Google Maps : open InfoWindow on mouseover, close & reopen on click

不想你离开。 提交于 2019-11-30 09:37:27
Dr.Molle

Try this:

google.maps.event.addListener(CalMarker, 'mouseover', function() {
    //open the infowindow when it's not open yet
    if(contentStringCal!=infowindow.getContent())
    {
      infowindow.setContent(contentStringCal);
      infowindow.open(map,CalMarker);
    }
});

google.maps.event.addListener(CalMarker, 'click', function() {
    //when the infowindow is open, close it an clear the contents
    if(contentStringCal==infowindow.getContent())
    {
      infowindow.close(map,CalMarker);
      infowindow.setContent('');
    }
    //otherwise trigger mouseover to open the infowindow
    else
    {
      google.maps.event.trigger(CalMarker, 'mouseover');
    }
});

//clear the contents of the infwindow on closeclick
google.maps.event.addListener(infowindow, 'closeclick', function() {
      infowindow.setContent('');
});

Demo: http://jsfiddle.net/doktormolle/JXqLa/

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