How do I get the event to use event.stopPropagation ()?

I am using the Markercluster plugin for Google Maps API V3. I want to access the click event when the user clicks on the cluster icon. The closest I can come to is

JS code

google.maps.event.addListener(mc, "clusterclick", function (cluster) {
    event.stopPropagation();
});

      

Problem: event.stopPropagation()

Only works in Chrome, not Firefox or IE. It can only work if passed as a parameter to a function such as event

an object:

$("#div").click(function(event) { 
    event.stopPropagation();
}

      

However, I don't know the DOM element of the cluster icon generated by MarkerClusterer, so I can't select it !! What should I do?

+3


source to share


2 answers


See here: https://developers.google.com/maps/documentation/javascript/events#EventArguments

google.maps.event.addListener (map, 'click', function (event) {placeMarker (event.latLng);});

The first parameter for the calback event is the event object. In your case, it would be:

google.maps.event.addListener(mc, "clusterclick", function (cluster) {     
    cluster.stopPropagation();     
});

      

Strike>

Since this is a custom event and the programmers did not pass the event object as a parameter, your solution had to implement it yourself:

Lines 150 and 151 from http://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/markerclustererplus/src/markerclusterer.js?r=362 :



from

google.maps.event.trigger(mc, "click", cClusterIcon.cluster_);
google.maps.event.trigger(mc, "clusterclick", cClusterIcon.cluster_); // deprecated name 

      

in

google.maps.event.trigger(mc, "click", e, cClusterIcon.cluster_);
google.maps.event.trigger(mc, "clusterclick", e, cClusterIcon.cluster_); // deprecated name 

      

Notice e

how the third parameter is. This is the event object from the original event that raises these 2 lines on line 139 :

google.maps.event.addDomListener(this.div_, "click", function (e) {

      

+3


source


You can try using return false;

. Although it does stop event bubbles as well as the default behavior. So I don't know if you can use it in your specific case.

UPDATE



clusterclick

the event is out of date
. You must use an event click

.

Have you already tried doing .stopPropagtion

and .cancelBubble = true

?

+1


source







All Articles