Thursday, 22 August 2013

How do you add marker to map using leaflet map.on('click', function) event handler

How do you add marker to map using leaflet map.on('click', function) event
handler

I'm trying to use an event handler to add a marker to the map. I can
manage this with a callback function, but not when I separate the function
from the event handler.
Callback (http://fiddle.jshell.net/rhewitt/U6Gaa/7/):
map.on('click', function(e){
var marker = new L.marker(e.latlng).addTo(map);
});
Separate function (http://jsfiddle.net/rhewitt/U6Gaa/6/):
function newMarker(e){
var marker = new L.marker(e.latlng).addTo(map);
}

No comments:

Post a Comment