在我的网站上,我正在使用Google v3在地图上放置房屋标记。
除非显式单击关闭图标,否则InfoWindows将保持打开状态。这意味着,如果您在地图标记上悬停,可以一次打开2+ InfoWindows。
问题:如何使其只打开当前活动的InfoWindow,关闭所有其他InfoWindows?意思是,一次只打开一个InfoWindow?
发布于 2010-02-08 18:54:34
有一个关闭()函数用于InfoWindows。只需跟踪上次打开的窗口,并在创建新窗口时调用关闭函数即可。
发布于 2012-02-28 11:55:41
使用多个infowindow的替代解决方案:保存prev在变量中打开infowindow,然后在新窗口打开时关闭它。
var prev_infowindow =false;
...
base.attachInfo = function(marker, i){
var infowindow = new google.maps.InfoWindow({
content: 'yourmarkerinfocontent'
});
google.maps.event.addListener(marker, 'click', function(){
if( prev_infowindow ) {
prev_infowindow.close();
}
prev_infowindow = infowindow;
infowindow.open(base.map, marker);
});
}
发布于 2010-09-18 23:56:25
//assuming you have a map called 'map'
var infowindow = new google.maps.InfoWindow();
var latlng1 = new google.maps.LatLng(0,0);
var marker1 = new google.maps.Marker({position:latlng1, map:map});
google.maps.event.addListener(marker1, 'click',
function(){
infowindow.close();//hide the infowindow
infowindow.setContent('Marker #1');//update the content for this marker
infowindow.open(map, marker1);//"move" the info window to the clicked marker and open it
}
);
var latlng2 = new google.maps.LatLng(10,10);
var marker2 = new google.maps.Marker({position:latlng2, map:map});
google.maps.event.addListener(marker2, 'click',
function(){
infowindow.close();//hide the infowindow
infowindow.setContent('Marker #2');//update the content for this marker
infowindow.open(map, marker2);//"move" the info window to the clicked marker and open it
}
);
这将“移动”信息窗口到每一个点击标记,实际上关闭自己,然后重新打开(和平移以适应视窗)在其新的位置。它在打开前改变其内容,以达到预期效果。适用于n个标记。
https://stackoverflow.com/questions/2223574
复制相似问题