RichMarker for Google Maps v3 - Click falls through marker

拜拜、爱过 提交于 2019-11-28 09:06:28

问题


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


回答1:


You'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');
});



回答2:


google.maps.event.addListener(richMarker, 'click', function(event) 
{
    // your stuff here

    event.preventDefault();
    event.stopPropagation();
    event.preventDefault();
});


来源:https://stackoverflow.com/questions/29003120/richmarker-for-google-maps-v3-click-falls-through-marker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!