? ? 最近在使用百度地圖加載多個(gè)標(biāo)記點(diǎn)和為其添加對(duì)應(yīng)的信息窗口的使用遇到信息窗口展示的內(nèi)容始終是最后一個(gè)的窗口信息;
之前使用的代碼如下:
//請(qǐng)求百度地圖的標(biāo)記點(diǎn)的坐標(biāo)
for(var i = 0 ; i < this.baiduMapMarker.length;i++){
var titleName = this.baiduMapMarker[i].GeoHazardPointCode
//坐標(biāo)轉(zhuǎn)換
//創(chuàng)建標(biāo)記點(diǎn)
var marker = new BMapGL.Marker(new BMapGL.Point(this.baiduMapMarker[i].GPS_Lon, this.baiduMapMarker[i].GPS_Lat));
map.addOverlay(marker);
//創(chuàng)建信息窗口
var opts ={
width:200,
height:50,
title:titleName
};
var infoWindow = new BMapGL.InfoWindow("地理位置:"+that.baiduMapMarker[i].NAME,opts);
//添加點(diǎn)的點(diǎn)擊事件
marker.addEventListener('click',function(e){
map.openInfoWindow(infoWindow,new BMapGL.Point(that.baiduMapMarker[i].GPS_Lon,that.baiduMapMarker[i].GPS_Lat));
})
}
//請(qǐng)求百度地圖的標(biāo)記點(diǎn)的坐標(biāo)
for(let? i = 0 ; i < this.baiduMapMarker.length;i++){
let titleName = this.baiduMapMarker[i].GeoHazardPointCode
//坐標(biāo)轉(zhuǎn)換
//創(chuàng)建標(biāo)記點(diǎn)
let marker = new BMapGL.Marker(new BMapGL.Point(this.baiduMapMarker[i].GPS_Lon, this.baiduMapMarker[i].GPS_Lat));
map.addOverlay(marker);
//創(chuàng)建信息窗口
let opts ={
width:200,
height:50,
title:titleName
};
let infoWindow = new BMapGL.InfoWindow("地理位置:"+that.baiduMapMarker[i].NAME,opts);
//添加點(diǎn)的點(diǎn)擊事件
marker.addEventListener('click',function(e){
map.openInfoWindow(infoWindow,new BMapGL.Point(that.baiduMapMarker[i].GPS_Lon,that.baiduMapMarker[i].GPS_Lat));
})
}
將var 改為let就可以了明吩。搀愧。赡矢。娶聘。個(gè)人感覺這個(gè)很坑
運(yùn)行結(jié)果: