加载功能
function load() {
var cluster = [];
infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(10.6145, -24.3418),
zoom: 2,
mapTypeId: 'roadmap'
});
// Read the data from example.xml
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var link = markers[i].getAttribute("link");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + '<a href="' + link + '" >' + markers[i].getAttribute("name") + '</a>' + "</b> <br/>" + "</b> <br/>" + '<a href="' + link + '" >' + markers[i].getAttribute("address") + '</a>';
var icon = customIcons[type] || {};
// create the marker
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
addMarker(marker, html);
cluster.push(marker);
}
var mc = new MarkerClusterer(map,cluster);
//markerCluster = new MarkerClusterer(map, gmarkers);
});
}
添加标记
function addMarker(marker, content)
{
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(content);
infoWindow.open(map, marker);
infoWindow.close();
});
}
ajax的代码
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
答案 0 :(得分:1)
如果单击群集标记,则会触发“clusterclick”事件。
添加一个事件监听器然后关闭infowindow:
var mc = new MarkerClusterer(map, cluster);
google.maps.event.addListener(mc, 'clusterclick', function() {
infoWindow.close();
});