Vue高德地图多个Marker添加点击事件(多个点位添加点击事件)
老样子废话不多说上代码(画地图如果画不出来请去看高德的开发文档这里咱就不说如何生产地图了)
·
老样子废话不多说上代码(画地图如果画不出来请去看高德的开发文档这里咱就不说如何生产地图了)
initAMap() {
map = new AMap.Map('container')
let infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
//遍历生成多个标记点
setTimeout(() => {
for (let i = 0; i < this.houseList.length; i++) {
let a= [this.houseList[i].longitude,this.houseList[i].latitude]
let marker = new AMap.Marker({
position: a,//不同标记点的经纬度
offset: new AMap.Pixel(-12, -32),
icon: '//vdata.amap.com/icons/b18/1/2.png'
});
marker.content = i+"";
marker.on('click', this.markerClick);
marker.emit('click', {target: marker});//默认初始化不出现信息窗体,打开初始化就出现信息窗体
map.add(marker)
}
//这里添加marker的点击事件的时候会给方法里面的都走一遍
//所以这里我们去给判断一下如果添加未完成的话不走我们的弹框
this.isOK = true;
}, 1000)
map.setFitView();
},
markerClick(e) {
this.index = e.target.content-0;
console.log(this.index)
if (this.isOK){
this.open1 = true;
}
//infoWindow.setContent(e.target.content);
//infoWindow.open(map, e.target.getPosition());
},
最后,我是放心不疼
祝你幸福
更多推荐
已为社区贡献2条内容
所有评论(0)