leaflet-panel-layers icon indicating copy to clipboard operation
leaflet-panel-layers copied to clipboard

How to remove layer from group dynamically?

Open scarybook opened this issue 1 year ago • 0 comments

I have noticed that both methods below only works when layer is added to a map directly and not to a group

panelLayers.removeLayer(toRemove) or toRemove.removeFrom(maps[mapId])

function addLayer(mapId, layer, layerId) {
    layer.id = layerId;
    layers[mapId].push(layer);
    layer.addTo(maps[mapId]);
}

function addLayerToGroup(groupId, layer, layerId) {
    layer.id = layerId;
    for (var i = 0; i < panelLayers._layers.length; i++) {
        if (panelLayers._layers[i].id == groupId) {
            layers[mapId].push(layer);
            panelLayers._layers[i].layer.addLayer(layer);
        }
    }
}

How to properly remove layer from the map when layer is in a group?

scarybook avatar Feb 16 '23 13:02 scarybook