检查infowindow是否已打开Goog​​le Maps v3 [英] Check if infowindow is opened Google Maps v3

查看:321
本文介绍了检查infowindow是否已打开Goog​​le Maps v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想检查我的infowindow是否已打开。



请注意,例如:

  if(infowindow.isOpened)
{
doSomething()
}

  if(infowindow.close)
{
doAnotherthing();
}

我没有任何想法,如何做到这一点

解决方案

这是一个未记录的功能,因此如有更改,恕不另行通知,但 infoWindow.close()方法将对象上的映射设置为 null (这就是为什么 infoWindow.open(map,[anchor])要求你传入一个 Map ),所以你可以检查这个属性来判断它是否正在显示:

 函数isInfoWindowOpen(infoWindow){
var map = infoWindow.getMap();
return(map!== null&& typeof map!==undefined);
}

if(isInfoWindowOpen(infoWindow)){
//做某些事情,如果它是开放的
}其他{
//做一些事情已关闭
}

更新:
另可能有用的方法是将 isOpen()方法添加到 InfoWindow 原型中

  google.maps.InfoWindow.prototype.isOpen = function(){
var map = this.getMap();
return(map!== null&& typeof map!==undefined);
}


Please, I need a help.

I want to check if my infowindow is opened.

For example:

if (infowindow.isOpened)
{
   doSomething()
}

or

if (infowindow.close)
{
   doAnotherthing();
}

I dont have any idea, how to do this

解决方案

This is an undocumented feature, and is therefore subject to change without notice, however the infoWindow.close() method sets the map on the object to null (this is why infoWindow.open(map, [anchor]) requires that you pass in a Map), so you can check this property to tell if it is currently being displayed:

function isInfoWindowOpen(infoWindow){
    var map = infoWindow.getMap();
    return (map !== null && typeof map !== "undefined");
}

if (isInfoWindowOpen(infoWindow)){
    // do something if it is open
} else {
    // do something if it is closed
}

Update: Another potentially useful way to write this is to add an isOpen() method to the InfoWindow prototype.

google.maps.InfoWindow.prototype.isOpen = function(){
    var map = this.getMap();
    return (map !== null && typeof map !== "undefined");
}

这篇关于检查infowindow是否已打开Goog​​le Maps v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆