- Leaflet version I'm using: 1.9.4
- Leaflet.MarkerCluster version I'm using: latest from master
- Browser (with version) I'm using: Firefox 121 (although it's not a browser related issue)
- OS/Platform (with version) I'm using: Windows 10
How to reproduce
- Create a map and add markerClusterGroup
- Create LayerControl with
L.Control.Layers and add to map
- Add layerGroup to MCG and LayerControl
- Create new marker, add to layerGroup
- Hide the layer using the LayerControl
- Change the latlng of the marker to
map.getCenter() for example
- The marker will re-appear despite the layer being hidden!
What behaviour I'm expecting and which behaviour I'm seeing
I've reproduced the same using the LayerControl demo, the marker did not re-appear using the same approach from above.
I found this to be the cause of the bug: https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerClusterGroup.js#L716
This causes the layer to be re-added, without checking if it's added or not.
How to reproduce
L.Control.Layersand add to mapmap.getCenter()for exampleWhat behaviour I'm expecting and which behaviour I'm seeing
I've reproduced the same using the LayerControl demo, the marker did not re-appear using the same approach from above.
I found this to be the cause of the bug: https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerClusterGroup.js#L716
This causes the layer to be re-added, without checking if it's added or not.