Google地图:在鼠标悬停时关闭InfoWindow,关闭&重新打开点击 [英] Google Maps : open InfoWindow on mouseover, close & reopen on click
问题描述
我有一个带有InfoWindows标记的页面,我在Click上打开。我决定打开正在工作的MouseOver上的InfoWindows。
但是我发现必须将鼠标移动到InfoWindow的十字交叉处才能关闭它为这些懒惰的互联网访客。所以我在点击标记上添加了一个关闭事件,它也在工作。
我无法想象的工作是能够
我的代码:
在标记点击InfoWindow,然后点击鼠标,而不必鼠标悬停在标记上。$ p $
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:在帖子开始时无法说出Hi,这很奇怪。
试试这个:
google。如果(contentStringCal!= infowindow.getContent())
{
infowindow.setContent(contentStringCal);
infowindow.open(map,CalMarker);
}
});
google.maps.event.addListener(CalMarker,'click',function(){
//当infowindow打开时,关闭它清除内容
if( contentStringCal == infowindow.getContent())
{
infowindow.close(map,CalMarker);
infowindow.setContent('');
}
//否则触发mouseover打开infowindow
else
{
google.maps.event.trigger(CalMarker,'mouseover');
}
});
//在closeclick上清除infwindow的内容
google.maps.event.addListener(infowindow,'closeclick',function(){
infowindow.setContent('' );
});
演示: http://jsfiddle.net/doktormolle/JXqLa/
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 move the mouse to the cross of the InfoWindow to close it is a bit demanding for these lazy visitors of the internet. So I added a Close event on Click of the Marker which is also working.
What I can't figure out to work is to be able to re-open the InfoWindow on Marker Click instead of having to mouseout in order to be able to re-mouseover on the marker.
My code :
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);
});
Can anyone help me to reopen window by clicking on the marker ?
Thanks in advance
PS : can't manage to say "Hi" at the beggining of the post, that's weird.
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/
这篇关于Google地图:在鼠标悬停时关闭InfoWindow,关闭&重新打开点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!