有没有办法和第一,如果信息窗口设置如果不设置使用如何检查infoWindow是否已设置并在地图上?
marker.infowindow.close();
之前在地图上,而不是在地图上查,该脚本不工作?我正在考虑在结束之前检查if语句?
有没有办法和第一,如果信息窗口设置如果不设置使用如何检查infoWindow是否已设置并在地图上?
marker.infowindow.close();
之前在地图上,而不是在地图上查,该脚本不工作?我正在考虑在结束之前检查if语句?
您可以在Javascript中使用typeof
函数。
if (typeof(marker.infowindow) === "undefined"){
//object doesn't exist
}
else{
//the object does exist
marker.infowindow.close();
}
您可以为您用作InfoWindow内容的div指定ID。 document.getElementById('content-div-id')
将在InfoWindow在地图上打开时返回div,否则返回null
。
您可以使用一个变量来检查,如果一个信息窗口存在:
var currentInfoWindow = null;
if(currentInfoWindow !== null){
currentInfoWindow.close();
}
然后,调用infoWindow.open()
后currentInfoWindow分配给新的信息窗口:
currentInfoWindow = infoWindow;
这是特别有用确保在地图上只打开一个infoWindow。
我试过,但它似乎总是未定义。 – Federico 2012-01-12 21:36:08