2012-10-26 59 views
6

我有一个页面,上面有InfoWindows标记,我点击打开。我决定宁愿打开正在工作的MouseOver上的InfoWindows。谷歌地图:在鼠标悬停时打开InfoWindow,关闭并重新打开点击

但我发现不得不将鼠标移动到InfoWindow的十字架上以关闭它,这对这些懒惰的互联网访问者来说有点苛刻。所以我在点击标记上添加了一个关闭事件,它也在工作。

我想不出的工作是能够重新打开标记上的InfoWindow单击而不必鼠标移动以便能够在标记上重新进行鼠标悬停。

我的代码:

google.maps.event.addListener(CalMarker, 'mouseover', function() { 
    infowindow.setContent(contentStringCal); 
    infowindow.open(map,CalMarker); 
}); 
google.maps.event.addListener(CalMarker, 'click', function() { 
    infowindow.close(map,CalMarker); 
}); 

谁能帮助我通过点击标记重新打开窗口?

在此先感谢

PS:无法管理想说声“嗨”的帖子的beggining,这是不可思议。

回答

8

试试这个:

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(''); 
}); 

演示:http://jsfiddle.net/doktormolle/JXqLa/

+0

工作,非常感谢;-) – Tsokoa

相关问题