6

I am using leaflet maps to compare heat layer and marker layer. I've an option to add multiple marker and heat layers dynamically. For me Heat layers are enabled by default as on when user adds new layer. I face issue when user adds marker layer the layer is created and it is not enabled by default. User needs to go and check the check box then it's getting enabled.

My question is, How to enable marker layers by default as on when users adds a new layer. Attached screen shots for better understanding of my question.

Shows heat layers are enabled by default.

When checked manually it appears.

5

For the sake of completion, as per https://github.com/Leaflet/Leaflet/issues/3199#event-230611315:

Simply add the layer directly to the map.

map.addLayer(layer)

The control layer function will pick this up and set the control buttons accordingly, regardless if the layer is included into the control. For example:

map.addLayer(layer1)
map.addLayer(layer2)

var baseLayers = {

};

var overlays = {
    "layer1": layer1,
    "layer2": layer2,
    "layer3": layer3,
    "layer4": layer4
};
L.control.layers(baseLayers, overlays).addTo(map);

Hopefully this makes life easier for some future seeker.

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.