Search code examples
djangoleafletdjango-leaflet

django-leaflet: How can you add layer controls to the controlLayer for the Tiles created in settings.py?


I have map tile layers configured in my settings.py and they properly appear and work.

When my site is loaded, I am also getting data to add two layers to the map and I also add them to a controlLayer.

controlLayers.addOverlay(restaurantMarkers, 'Restaurants');
controlLayers.addOverlay(parksMarkers, 'Parks');

and then I add the control layer to the map

var controlLayers = L.control.layers().addTo(map);

This all works, but they are in their own control layer separate from the tiles control layer so now I have two control layers.

How do I add additional controls to the controlLayer created for the Tiles?

Thanks so much!


Solution

  • With the help of the dev team (on github)...

    map.layerscontrol is the attribute that the Tiles from the settings.py are added to.

    So if in your own page you use var controlLayers = map.layerscontrol; and then add layers to it controlLayers.addOverlay(layerData, "Layer Name") you will have a single control layer.

    More info in Github https://github.com/makinacorpus/django-leaflet/issues/219