Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
911 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...