Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if infowindow is opened Google Maps v3

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

like image 398
Fred Vicentin Avatar asked Sep 13 '12 15:09

Fred Vicentin


People also ask

How do I know if InfoWindow is open?

Calling InfoWindow. getOpenedState() returns a boolean which reflects the state (opened/closed) of the infowindow.

How do I get rid of InfoWindow in Google Maps?

After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.

How do you use InfoWindow in maps?

When you create an info window, it is not displayed automatically on the map. To make the info window visible, you must call the open() method on the InfoWindow , passing an InfoWindowOpenOptions object literal specifying the following options: map specifies the map or Street View panorama on which to open.

How do I edit InfoWindow on Google Maps?

You can modify the whole InfoWindow using jquery alone... var popup = new google. maps. InfoWindow({ content:'<p id="hook">Hello World!


2 Answers

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"); } 
like image 138
doublesharp Avatar answered Sep 28 '22 15:09

doublesharp


Until google doesn't give us any better way of doing this, you can add a property to the infoWindow objects. Something like:

google.maps.InfoWindow.prototype.opened = false; infoWindow = new google.maps.InfoWindow({content: '<h1> Olá mundo </h1>'});  if(infoWindow.opened){    // do something    infoWindow.opened = false; } else{    // do something else    infoWindow.opened = true; } 
like image 22
pedro Avatar answered Sep 28 '22 14:09

pedro