I am using leaflet to display maps on my site. I want user to show and save his address on the map (by placing a marker) so in my code, if user double clicks, a marker will be placed on the map. The problem is I don't want to disable double click zoom. So when user double clicks again, the previous marker should be deleted and a new marker should be added. I searched Stack Overflow and reached to this code
map.on('dblclick', addMarker);
var Marker;
function addMarker(e) {
//remove previous markers
map.removeLayer(Marker);
// Add marker to map at click location; add popup window
Marker = new L.marker(e.latlng,{draggable:true}).addTo(map);
}
But after adding "map.removeLayer (Marker);" not only double click zoom stopped working, but also no marker is added to map anymore Summary: I always want to keep the last marker added to map