You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've looked at the documentation to make sure the behavior isn't documented and expected.
I'm sure this is an issue with Leaflet, not with my app or other dependencies (Angular, Cordova, React, etc.).
I've searched through the current issues to make sure this hasn't been reported yet.
I agree to follow the Code of Conduct that this project adheres to.
Steps to reproduce
Code:
Create a LayerGroup and add to the map.
Create some layer, e.g. a Marker, and add to the LayerGroup.
Call layer.remove()
Remove the LayerGroup.
Add the LayerGroup back.
const map = L.map('map', {
layers: [L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png')],
center: [51, 0.02], zoom: 14
});
const layerGroup = L.layerGroup().addTo(map);
L.control.layers(null, { 'Notice that clicking off and on introduces a middle marker': layerGroup }, {collapsed: false}).addTo(map);
const marker1 = L.circleMarker([51, 0.01]).addTo(layerGroup);
const marker2 = L.circleMarker([51, 0.02]).addTo(layerGroup);
const marker3 = L.circleMarker([51, 0.03]).addTo(layerGroup);
// Layer.remove() is buggy. It removes from the Map but not the
// LayerGroup that it's in. If we remove the LayerGroup and add the
// LayerGroup back (for example using L.Control.Layers), then the marker
// reappears; whereas layerGroup.removeLayer() correctly removes from
// both LayerGroup and Map.
marker2.remove();
Expected behavior
I expected that layer.remove() removes from the map AND from the layerGroup that it's in, such that it remains removed if the layerGroup is removed and re-added.
Current behavior
As of Leaflet 1.9.4, Layer.remove() removes the layer from layer._map._layers, but does not remove from layerGroup._layers, for the layerGroup that it's in.
The layer gets removed from DOM and visually disappears.
However, if you remove the LayerGroup and add it back (for example via Layers Control), then the supposedly removed layer reappears (because it was never removed from layerGroup._layers).
Checklist
Steps to reproduce
Code:
layer.remove()
Expected behavior
I expected that
layer.remove()
removes from the map AND from the layerGroup that it's in, such that it remains removed if the layerGroup is removed and re-added.Current behavior
As of Leaflet 1.9.4,
Layer.remove()
removes the layer from layer._map._layers, but does not remove from layerGroup._layers, for the layerGroup that it's in.The layer gets removed from DOM and visually disappears.
However, if you remove the LayerGroup and add it back (for example via Layers Control), then the supposedly removed layer reappears (because it was never removed from layerGroup._layers).
Minimal example reproducing the issue
https://plnkr.co/edit/iYrvKIpBwRsUtYd2?preview
Environment
The text was updated successfully, but these errors were encountered: