最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - RichMarker for Google Maps v3 - Click falls through marker - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

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');
});
google.maps.event.addListener(richMarker, 'click', function(event) 
{
    // your stuff here

    event.preventDefault();
    event.stopPropagation();
    event.preventDefault();
});
发布评论

评论列表(0)

  1. 暂无评论