In leaflet 0.3.1, when the same marker is added to more than one layer, all of which are added to L.Control.Layers as overlays, and one of the overlays is disabled, the marker is disabled.
e.g.
var groupA = new L.LayerGroup(),
groupB = new L.LayerGroup();
map.addLayer(groupA).addLayer(groupB);
var overlays = {
"A features": groupA,
"B features": groupB,
};
map.addControl(new L.Control.Layers(null, overlays));
var marker = new L.Marker(new L.LatLng(1.0, 1.0));
groupA.addLayer(marker);
groupB.addLayer(marker);
Now, whenever the "A features" overlay is disabled, the marker is removed, even if the "B features" overlay is still enabled. Disabling and re-enabling "B features" does re-add the marker.
You need a newline before the ```javascript :)
Thanks, fixed it.
I can see where such behavior could be useful (different sets of markers, some overlapping), but it's quite hard to fix as layers in Leaflet are currently completely independent from each other... I'll think about this, thanks for the report.
I wrote a workaround that does the trick for me. Perhaps this new behaviour should be hidden behind some forceReadd option or something, otherwise I might think its performance impact is not welcome.
I don't see an easy way to implement this, so if there's a workaround for people that need it, I think I can close this for now.
I wrote a workaround that does the trick for me. Perhaps this new behaviour should be hidden behind some forceReadd option or something, otherwise I might think its performance impact is not welcome.
@rgeissert can you share your workaround, please?
@MaxiPigna I think the workaround is in the cross-referenced commit here: https://github.com/rgeissert/Leaflet/commit/e273f1bb0aeef485d07c2814429a28ea9ea07474
Most helpful comment
I wrote a workaround that does the trick for me. Perhaps this new behaviour should be hidden behind some forceReadd option or something, otherwise I might think its performance impact is not welcome.