I like to keep track of any and all infowindows that are open on my Google Maps interface (I store their names in an array), but I can't figure out how to remove them from my array when they are closed via the "x" in the upper right hand corner of each one.
Is there some sort of callback I can listen for? Or maybe I can do something like addListener("close", infowindow1, etc
?
An InfoWindow displays content (usually text or images) in a popup window above the map, at a given location. The info window has a content area and a tapered stem. The tip of the stem is attached to a specified location on the map. Info windows appear as a Dialog to screen readers.
To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.
there's an event for infowindows call closeclick
that can help you
var currentMark; var infoWindow = new google.maps.InfoWindow({ content: 'im an info windows' }); google.maps.event.addListener(marker, 'click', function () { infoWindow.open(map, this); currentMark = this; }); google.maps.event.addListener(infoWindow,'closeclick',function(){ currentMark.setMap(null); //removes the marker // then, remove the infowindows name from the array });
The only consistent solution I've found here is to retain a pointer to the infoWindow
and check its .getMap()
method whenever you need to validate whether it has been closed.
The reason for this is that clicking another element can cause the infoWindow to be dismissed for other reasons... without the closeclick
event firing.
var infoWindow = new google.maps.InfoWindow({ content: 'Something to put here.' }); infoWindow.open(map, infoWindow); setInterval(function () { console.log("infoWindow is bound to map: "+(infoWindow.getMap() ? true : false)); }, 1000);
... If you literally only care if the infoWindow
was closed using the "X" button, then monitoring closeclick
is fine. However, there are other reasons it may be or have been closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With