This is my map ,my removeLayer in leaflet map remove once (Removed picture )and as you see in picture it remove marker perfectly but when I try to remove it again it don't! checked is not true but it didnt remove for 2nd time here is the function that called from checkbox :
function myFunction(id) {
var marker = [];
var checkBox = document.getElementById(id)
var lat = checkBox.name;
var lon = checkBox.value;
var RN = checkBox.className;
console.log(RN)
var pop_cont = `<img id="icon" src="sample.jpg" alt="shipPIC"/><br><b>${RN}</b><br> latitude :${lat}<br>longitude: ${lon}`
if (checkBox.checked == true) {
marker = L.marker([lat, lon]).addTo(map);
marker.setIcon(dish_icon);
marker.bindPopup(pop_cont).openPopup();
console.log("checked")
} else {
marker = L.marker([lat, lon])
var x_id = L.stamp(markers);
map.removeLayer(markers[id]);
console.log("NOOOOT Check");
}
}
why removeLayer() work for first time remove but when i add that layer again and want to remove it , removeLayer don't work?!
thank you verymuch!