Vue中在百度地图循环加标注并实现双击事件Demo

向地图中加marker
addMarkers(){
var markerArr = 后台获取到的list
var point = new Array() //保存相关的数据
var marker = new Array() //保存相关的数据
var info = new Array() //保存相关的数据
for(var i=0;i var json = markerArr[i];
var p0 = json.lon
var p1 = json.lat
point[i] = new window.BMap.Point(p0,p1)
var pointIcon = new BMap.Icon(
“map_green.png”,
new BMap.Size(
25, 25))
pointIcon
.setImageSize(new BMap.Size(
25, 25))
marker[i] = new window.BMap.Marker(point[i],{icon:pointIcon})
var label = new window.BMap.Label(json.name,{“offset”:new BMap.Size(13,-20)})
marker[i].setLabel(label)
map.addOverlay(marker[i])
label.setStyle({
borderColor:"#808080",
color:"#333",
cursor:“pointer”
})
info[i] = ‘


+ ‘

+’
  • ’+ markerArr[i].name
    +’:
    查看详情

  • + ‘

    this.addInfo(info[i],marker[i])
    }
    },
    addInfo(txt,marker){
    var infoWindow = new BMap.InfoWindow(txt)
    marker.addEventListener(“dblclick”, function(e){
    var p = e.target
    var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat)
    window.map.openInfoWindow(infoWindow,point)
    })
    },

    你可能感兴趣的:(vue)