我目前有一堆标记,我将它们存储在一个数组中以跟踪它们。当我单击特定链接时,它会打开该标记的信息窗口。有没有办法在点击侦听器中进行检查,以查看我要打开的信息窗口是否是当前打开的信息窗口?如果是这样,不要关闭并重新打开信息窗口?
当前的javascript:
<script type="text/javascript">
var infowindow = null;
var stored_markers = new Array();
function initialize()
{
var latlng = new google.maps.LatLng(0,0);
var myOptions = {
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
setMarkers(map, items);
infowindow = new google.maps.InfoWindow({
content: "holding..."
});
}
var items = [
['title 1 to display on hover', latitude 1, longitude 1, z-index 1, 'infowindow 1 content'],
['title 2 to display on hover', latitude 2, longitude 2, z-index 2, 'infowindow 2 content'],
['title 3 to display on hover', latitude 3, longitude 3, z-index 3, 'infowindow 3 content']
];
function setMarkers(map, markers)
{
for (var i = 0; i < markers.length; i++)
{
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
html: sites[4]
});
stored_markers.push(marker);
//initial content string
var contentString = "Some content";
//attach infowindow on click
google.maps.event.addListener(marker, "click", function ()
{
infowindow.setContent(this.html);
infowindow.open(map, this);
});
}
}
</script>