vue使用高德地图自定义图片标记点

936 阅读1分钟

高德地图自定义图片标记点

效果图:

在这里插入图片描述

场景 例如标记范围内共享单车的位置

循环坐标数组然后绘制:

this.deviceMapData.output.value.curProData.forEach((item,index)=>{
      //循环单点绘制  不能自定义icon
      let marker = new AMap.Marker({
        icon: new AMap.Icon({            
          image: '/static/img/deviceMap/normal.svg',
          size: new AMap.Size(50, 50),  //图标大小
          imageSize: new AMap.Size(50,50),
        }),
        position: [item.lng,item.lat],
        offset: new AMap.Pixel(-24, -48)
      });
      //给marker添加属性
      marker.setExtData(item)
      marker.setMap(map);
      //给marker添加点击事件
      marker.on('click', (e)=>{
        console.log('点击',e.target.getExtData())
      })
    })