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");
}