Stop propagation of 'click' event in Leaflet
This one worked for me...
var div = L.DomUtil.get('div_id');
if (!L.Browser.touch) {
L.DomEvent.disableClickPropagation(div);
L.DomEvent.on(div, 'mousewheel', L.DomEvent.stopPropagation);
} else {
L.DomEvent.on(div, 'click', L.DomEvent.stopPropagation);
}
Thanks to https://gis.stackexchange.com/questions/104507/disable-panning-dragging-on-leaflet-map-for-div-within-map
I know that this answer is quite late, but if someone is interested in a solution, here is how i have solved it.
This snippet here below is an example of binding a function to the click
event.
map.on('click', doSomething);
Actually, after checking leaflet's API and some geekish debugging, it seems that the event returns an object, not the event itself. The event itself is wrapped into a field within the returned object.
var doSomething = function(map) {
// stop propagation
map.originalEvent.preventDefault();
};
When using the above snippet, the event bubbling has stopped, something which i wanted, and probably what you wanted.
I know that this answer is event more quite late, but as in jquery you can use .off
map.on('click', doSomething);
map.off('click');
It works fine for any leaflet events.
I use it for 'zoomend'
event to be triggered one time only.
map.on('moveend', function(e){
console.log("any code");
map.off('moveend');
});