[Google Maps] How to close an Infowindow using "mouseout" trigger event?

[Google Maps] How to close an Infowindow using "mouseout" trigger event?

  
Forge Component
(20)
Published on 9 Mar by Steve Collins
20 votes
Published on 9 Mar by Steve Collins

Hi all,

I would like to know if is possible to close an infowindow on a  marker using "mouseout" trigger event with "AddMarkerEvent" method?

I was able to implement the "mouseover" trigger event to show an infowindow on markers but I don't know how can i close the infowindow on a "mouseout" event.

Anyone already implemented something similar?


Thanks in advance for your help.


Cheers



Hi all,


anyone have any idea how to achieve this?

I'm pretty sure is my JS knowledge failing here but I already tested a lot of things and I can't get this logic working....


Thanks for your help.


Cheers

Solution

Hey Gonçalo,

You need to add a second marker event for the "mouseout" trigger.

In order for you to work with the same infowindow, I would suggest that you declare it as a window variable. Something like the following:

    var contentString = <YOUR HTML GOES HERE>;

    window.infowindow = new google.maps.InfoWindow({
          content: contentString
      });

    window.infowindow.open(this.getMap(), this);

And for the 'mouseout' handler you can have something like

window.infowindow.close();


Hope it helps,

Cheers

Solution

Hi Henrique,

Declaring infowindow as a window variable did the trick!

It's working like a charm now with your tips! ;)


Thank you very much for your help!


Cheers