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 openedThe 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); });更多推荐
发布评论