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

后端 未结 1 1471
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 20:57

I\'ve a page with markers with InfoWindows that I opened on Click. I decided to rather open the InfoWindows on MouseOver which is working.

But I find that having to

相关标签:
1条回答
  • 2020-12-31 21:09

    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/

    0 讨论(0)
提交回复
热议问题