我有一个包含 100 多个标记的地图。我已经向服务器发出了 Ajax 请求,并获得了一个包含大量纬度、经度值的 xml 响应。循环这些值并在地图上添加带有标签的每个标记。ajax请求和响应很快发生,每个标记被快速添加到映射。然后整个页面冻结一段时间。然后标记显示为大然后恢复正常。为什么谷歌地图会这样?
我的ajax请求代码,响应并在地图上添加标记:
ajaxRequests[ax]=$.ajax({
type: "GET",
url: "myurl",
dataType: "xml",
async:true,
success: function(xml) {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
routepoints = new Array();
$(xml).find('value').each(function(){
var latt=$(this).find('lat').text();
var lonn=$(this).find('lon').text();
routepoints[i] = new Array(name,ct,latt,lonn,phone);
addMarker(i);
i=i+1;
});
mzoom=map.getZoom();
}
});
function addMarker(tt)
{
var icont;
if(tt==0)
icont='images/green.png';
else if(tt==(total_markers-1))
icont='images/red.png';
else
icont='images/purple.png';
var idm=(tt+1)+") "+routepoints[tt][1];
var clocation= new google.maps.LatLng(routepoints[tt][2],routepoints[tt][3]);
var marker = new MarkerWithLabel({
position: clocation,
map: map,
labelContent: idm,
labelAnchor: new google.maps.Point(15, 5),
labelClass: "labels",
icon: icont
});
if(tt==0 || (tt+1)==total_markers)
marker.setAnimation(google.maps.Animation.BOUNCE);
else
marker.setAnimation(google.maps.Animation.DROP);
markersArray.push(marker);
map.panTo(clocation);
}