5

In a Leaflet-based app I have create several overlays, grouped with leaflet.groupedlayercontrol.js, as shown in this image:

enter image description here

Everything works well, but I need to uncheck certain layers, allowing the user to check them if needed (the app should open with Heatmap and Geometries on, and the others off). I have references both to the layers and to the control object. How can I check/uncheck these overlays without removing them from the map object?

  • 1
    if app should open with Heatmap and Geometries on, and the others off - use option 'layers: [Geometries, Heatmap]' in L.map and delete '.addTo()map' options from this layers. – HasT Oct 16 '14 at 19:10
1

Generally with Leaflet, if you want to show something UNchecked in the overlay by default, you simply add the layer to the layers control, but do not add it to your map. So don't worry about "without removing them from the map" because you will not add them in the first place (until they are going to be displayed, via the layers control).

To wit:

var layerIsVisible = false;
if (layerIsVisible)
{
    map.addLayer(layer);
}
map.LayersControl.addOverlay(layer, "Layer Title");

I have not used the group layer control plugin you refer to, but I believe at its core it basically works the same way.

When a user ticks the overlay to display it, it will be automatically added to the map. Voila!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.