Adding event listener to infowindow Google Maps v3

可紊 提交于 2020-12-16 04:13:34

问题


I tried to add some listeners for Info Window like:

//works
google.maps.event.addListener(markerInfoWindow, "closeclick", function()
{
    console.log('trigger close');
});

//doesn't work
google.maps.event.addListener(markerInfoWindow, "click", function()
{
    console.log('trigger close');
});

Is there a list of events for infoWindow in documentation I missed or is there another way to make things done?

Actually the probles is that I want to create an event listener to close infoWindow on mouseout

google.maps.event.addListener(markerInfoWindow, 'mouseout', function(){
    console.log('trigger close');
    self._setInfoWndClosed();
});

the self._setInfoWndClosed() is working correctly in context of closeclick event. And I end up finding out that actually listener doesn't work itself.


回答1:


There is no documented "click" or "mouseover" event for an InfoWindow: The only documented events on an google.maps.InfoWindow (at present) are:

Events

closeclick Arguments: None

This event is fired when the close button was clicked.

content_changed Arguments: None

This event is fired when the content property changes.

domready Arguments: None

This event is fired when the containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically.

position_changed Arguments: None

This event is fired when the position property changes.

zindex_changed Arguments: None

This event is fired when the InfoWindow's zIndex changes.

You can add listeners for "click" and "mouseover" events on the content of the InfoWindow.




回答2:


As this link shows:

https://gist.github.com/thebouv/38f91f81675aad85f15d

you can add a 'domready' event listener to your info window. Once inside the callback you can attach event listeners to any of the info windows elements by id (using the standard "addEventListener"). The "onclick" method is much better but it didn't work well in my case because I was using react.



来源:https://stackoverflow.com/questions/40131421/adding-event-listener-to-infowindow-google-maps-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!