I am using RichMarker for Google Maps v3 as found at .html
I have successfully been able to register clicking on the marker with this code:
google.maps.event.addListener(this.richMarker, 'click', function(event) {
console.log("click made on marker");
});
However the click also falls through the marker, so it registers a click on whatever falls behind it. ie the map, if it has a handler:
google.maps.event.addListener(map, 'click', function(event) {
console.log("click made on map");
});
Or a polygon if it is clickable.
How can I prevent this fall through click with RichMarker?
Thanks
I am using RichMarker for Google Maps v3 as found at https://googlemaps.github.io/js-rich-marker/reference.html
I have successfully been able to register clicking on the marker with this code:
google.maps.event.addListener(this.richMarker, 'click', function(event) {
console.log("click made on marker");
});
However the click also falls through the marker, so it registers a click on whatever falls behind it. ie the map, if it has a handler:
google.maps.event.addListener(map, 'click', function(event) {
console.log("click made on map");
});
Or a polygon if it is clickable.
How can I prevent this fall through click with RichMarker?
Thanks
Share Improve this question asked Mar 12, 2015 at 6:23 Nathan WilliamsNathan Williams 4196 silver badges14 bronze badges 1- Can you provide a JSFiddle or at least a mcve so that we can see how you did it? – MrUpsidown Commented Mar 12, 2015 at 6:55
2 Answers
Reset to default 5You'll need to modify the library.
Find this part:
google.maps.event.addDomListener(this.markerContent_, 'click', function(e) {
google.maps.event.trigger(that, 'click');
});
and change it to
google.maps.event.addDomListener(this.markerContent_, 'click', function(e) {
e.stopPropagation();
google.maps.event.trigger(that, 'click');
});
google.maps.event.addListener(richMarker, 'click', function(event)
{
// your stuff here
event.preventDefault();
event.stopPropagation();
event.preventDefault();
});