0
我想解決成功的問題。重新計算markercluster並downloadUrl
正如你可以看到當你取消選中VDSL或ADSL選項時,markercluster仍然具有相同的值。
downloadUrl("php_to_xml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var ThisMarkers = markers[i];
var lat = markers[i].getAttribute("lat");
var lng = markers[i].getAttribute("lng");
var typeofkafao = markers[i].getAttribute("typeofkafao");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var icon = coloredRideshareIcon(typeofkafao);
//below is the balloon of the marker.
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon
});
addMarker(typeofkafao, marker, map, infoWindow, ThisMarkers);
}
var mcOptions = {gridSize: 40, maxZoom: 15};
var markerCluster = new MarkerClusterer(map,gmarkers,mcOptions); // edo trexi
});
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);
}
我知道,問題是將downloadURL功能,因爲它的異步。 我不得不在downloadUrl之外調用markerCluster,但是我不能在downloadUrl函數外發送標記變量。
我認爲問題是解決類似的問題,但不完全如此。
var markers2;
downloadUrl("php_to_xml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
markers2 = markers;
});
for (var i = 0; i < markers2.length; i++) {
var ThisMarkers = markers2[i];
var lat = markers2[i].getAttribute("lat");
var lng = markers2[i].getAttribute("lng");
var typeofkafao = markers2[i].getAttribute("typeofkafao");
var type = markers2[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers2[i].getAttribute("lat")),
parseFloat(markers2[i].getAttribute("lng")));
var icon = coloredRideshareIcon(typeofkafao);
//below is the balloon of the marker.
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon
});
addMarker(typeofkafao, marker, map, infoWindow, ThisMarkers);
}
var mcOptions = {gridSize: 40, maxZoom: 15};
var markerCluster = new MarkerClusterer(map,gmarkers,mcOptions); // edo trexi
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);
}
任何想法傢伙?
非常感謝
我已經看到這裏的帖子http://stackoverflow.com/questions/28398881/recalculate-markercluster-onclick-of-filter 但它does not use downloadUrl – ElessarGR