In one of our projects we're using Leaflet
along with Leaflet.markercluster
plugin. Looking through the Leaflet
's sources I found that it appends _collapse()
function to the map's click
event, so whenever I click on the map it contracts previously expanded cluster.
Now, I want to disable this behavior. If the cluster is expanded, then I just want to deselect all of its markers on click
event (and don't contract the cluster itself). Here is the piece of my code:
map.on('click', function(e) {
scope.deselectAllMarkers();
});
I tried to add the following lines in the end of this one-line callback in order to stop propagation of click
event:
scope.L.DomEvent.stopPropagation(e);
scope.L.DomEvent.preventDefault(e);
scope.L.DomEvent.stop(e);
scope.L.DomEvent.stopPropagation(e.originalEvent);
scope.L.DomEvent.preventDefault(e.originalEvent);
scope.L.DomEvent.stop(e.originalEvent);
And none of them works. Default listener which is hidden inside of the Leaflet
sources keeps its invocation whenever I click on the map. Am I missing something?
In the end I've solved the issue by manual removal of default click
handler which was invoking the _collapse()
method, as far as I remember. Dirty, but it did the trick.