Google Maps API V3相同的事件列表器到多个标记阵列(Google Maps API V3 same event lister to multiple arrays of markers

编程入门 行业动态 更新时间:2024-10-28 14:22:32
Google Maps API V3相同的事件列表器到多个标记阵列(Google Maps API V3 same event lister to multiple arrays of markers)

所以基本上我有这样的东西

var arrayOfMarker1 = [...], arrayOfMarker2 = [...], ... arrayOfMarkerN = [...];

我想使用能够关闭当前打开的infoPanel的eventListener来显示最后点击的一个,即使它是另一个要点击的数组的标记。

例:

我打开arrayOfMarker1 infoPanel的标记(让我们称它为marker1) 我点击一个arrayOfMarker2标记(marker2) marker1的infoPanel已关闭, marker2已打开

我唯一发现的就是这个

marker.addListener('click', function () { infowindow.setContent(this.html); infowindow.open(map, this); });

但它只适用于同一阵列的标记。 有什么办法可以做到吗?

So basically I have something like this

var arrayOfMarker1 = [...], arrayOfMarker2 = [...], ... arrayOfMarkerN = [...];

and I want to use a eventListener able to close the current open infoPanel to show the last clicked one, even if it is a marker of another array to be clicked.

Example:

I open a marker of arrayOfMarker1 infoPanel (let's call it marker1) I click on a arrayOfMarker2 marker (marker2) marker1's infoPanel is closed and marker2's in opened

The only thing that I have found is this

marker.addListener('click', function () { infowindow.setContent(this.html); infowindow.open(map, this); });

But it just works for markers of the same array. Is there any way to do it?

最满意答案

您需要一个全局变量来跟踪上次打开的infoPanel。

var openedInfoWindow = null; marker.addListener('click', function () { if(openedInfoWindow != null) { openedInfoWindow.close(); } openedInfoWindow = infowindow; infowindow.setContent(this.html); infowindow.open(map, this); });

You would need a global variable to track the last opened infoPanel.

var openedInfoWindow = null; marker.addListener('click', function () { if(openedInfoWindow != null) { openedInfoWindow.close(); } openedInfoWindow = infowindow; infowindow.setContent(this.html); infowindow.open(map, this); });

更多推荐

本文发布于:2023-08-03 09:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386100.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   阵列   标记   事件   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!