I am trying to remove element from map: Work code:
var x = L.imageOverlay(fullURL, xbounds).addTo(Window.map);
Window.map.removeLayer(x);
Do not work:
var x = L.imageOverlay(fullURL, xbounds).addTo(Window.map);
Window.map.removeLayer(1);
By the docs it have method for removing elements by IDs
Actually, map.removeLayer() accepts only a layer (as in your first code).
It is layerGroup.removeLayer() that can also accept an ID.
This "ID" is automatically defined by Leaflet, and you can retrieve it using L.stamp(layer).
var layerGroup = L.layerGroup().addTo(map)
var x = L.marker(coordinates).addTo(layerGroup);
var x_id = L.stamp(x); // Retrieve the x layer ID
layerGroup.removeLayer(x_id);
Demo: https://jsfiddle.net/3v7hd2vx/65/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With