简体   繁体   English

谷歌地图点击标记

[英]google map click on markers

I have a map and multiple markers on that. 我有一张地图,上面有多个标记。 I have already attached a click event on the map container to disappearing whatever is shown over the map (I have legends, timeline, etc.) using animation. 我已经在地图容器上附加了click事件,以使用动画消失在地图上显示的所有内容(我有图例,时间轴等)。

My problem is when you click on a marker to see the infoWindow , it also triggers the click event on the map, which disappearing over layer objects on the map. 我的问题是,当您单击标记以查看infoWindow ,它还会触发地图上的click事件,该事件在地图上的图层对象上消失。 So, I want to prevent the map container already assigned event, when clicking on a marker, so only infoWindow would appears and nothing else. 因此,我想防止在单击标记时地图容器已经分配了事件,因此只会显示infoWindow,而不会显示其他任何内容。

Here is map click event: 这是地图点击事件:

$('#map_canvas').bind('mousedown', function() { ...

The only thing I can see on the markers, is that they all have the same class: gmnoprint 我只能在标记上看到的是它们都具有相同的类: gmnoprint

I've already tested this one: 我已经测试过这个:

$('#map_canvas').not('.gmnoprint').bind('mousedown', function() { ...

and: 和:

$('#map_canvas').bind('mousedown', function() {

    if ($(this).is('.gmnoprint'))
        return false;
....

But none of them worked. 但是他们都不起作用。 Anyone knows how to solve the problem? 有人知道如何解决问题吗?

Thanks in advance! 提前致谢!

I'd try to use the google maps API event listeners, as they will be the most reliable when interacting with elements of the map: 我会尝试使用Google Maps API事件监听器,因为它们在与地图元素进行交互时将是最可靠的:

https://developers.google.com/maps/documentation/javascript/events https://developers.google.com/maps/documentation/javascript/overlays#InfoWindows https://developers.google.com/maps/documentation/javascript/events https://developers.google.com/maps/documentation/javascript/overlays#InfoWindows

This is the basic syntax from the gmaps API for binding a click to open an info window associated with a marker: 这是gmaps API中用于绑定单击以打开与标记相关联的信息窗口的基本语法:

google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
});

Hopefully that will help! 希望这会有所帮助!

你必须抓住的event ,然后调用event.preventDefault ,你有.click该信息窗口功能。

You can do something like that 你可以做这样的事情

    <div id="map_canvas" class="foo"></div>


$("#map_canvas").hasClass("foo").click(function(){

 $(this).removeClass("foo")
})

Your problem is 你的问题是

$('#map_canvas').bind(...

those markers/info windows are in that map_canvas div, so your technically clicking on it 这些标记/信息窗口在该map_canvas div中,因此您可以从技术上单击它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM