Leaflet has a 'click' event:
map.on('click', function(e) {
alert(e.latlng);
});
This does not appear to work when map layers are displayed on the area clicked. Is there a way to use map.on('click')
so that it ignores any layers on the map?
Leaflet has a 'click' event:
map.on('click', function(e) {
alert(e.latlng);
});
This does not appear to work when map layers are displayed on the area clicked. Is there a way to use map.on('click')
so that it ignores any layers on the map?
When you have a layer that also listens for click then it will pick up the top most layer's event.
Check out this fiddle.
You can add the shape click handler and see that it picks that up instead of the map's.
layer.on("myEvent",function(e){...});
) and trigger them in the click
-event callback of the map (layer.fire("myEvent");
)
Commented
Jul 23, 2015 at 5:37
Evented
- so follow e.g. github.com/Leaflet/Leaflet/blob/master/src/core/Events.js
Commented
Jul 23, 2015 at 5:39
If you do (or want to) use the Leaflet 1.0 Beta version, Marker and Path have an interactive
option.
If false, the marker will not emit mouse events and will act as a part of the underlying map.
(from leaflet beta API)