使用BMap.InfoWindow,在for循环展示信息的时候,总是显示最后一条信息的数据。
其实,可以讲BMap.InfoWindow的创建写在一个单独的function中。这样,每一个BMap.InfoWindow,就是显示的当条的信息。
function callback(xyResults) {
var xyResult = null;
for(var i = 0;i<xyResults.length;i++){
xyResult = xyResults[i];
xySource = qntPoints.points[count*maxCon+i];
if (xyResult.error != 0) {
continue;
}
var point = new BMap.Point(xyResult.x, xyResult.y);
var myIcon1 = new BMap.Icon("<%=request.getContextPath()%>/js/map/car30.png", new BMap.Size(30,30));
var marker = new BMap.Marker(point,{icon:myIcon1});
map.addOverlay(marker);
txt = "<p style='font-size:14px;'>"+xySource.desc+"</p>" ;
addInfo(txt,marker);
if(xyResults.length-1==i){
map.centerAndZoom(point,6);
}
}
if(qntPoints.parArray.length>++count){
BMap.Convertor.transMore(qntPoints.parArray[count], 0, callback);
}else{
count = 0;
qntPoints.parArray = new Array();
}
}
function addInfo(txt,marker){
infoWindow = new BMap.InfoWindow(txt);
marker.addEventListener("click", function(){this.openInfoWindow(infoWindow);});
}