?
?
使用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>"?;??
- ????<span?style="color:#ff0000;"><strong>addInfo(txt,marker);</strong>??
- </span>????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();??
- ???}??
- ??}??
- ????
- ??<span?style="color:#ff0000;">function?addInfo(txt,marker){??
- ????infoWindow?=?new?BMap.InfoWindow(txt);??
- ????marker.addEventListener("click",?function(){this.openInfoWindow(infoWindow);});??
- ??}??
- </span>??
引自博客:
http://blog.csdn.net/mach365/article/details/8103648
?