高德地图可通过maker来添加点位标注
let maker = new AMap.Marker({
position: new AMap.LngLat(el.longitude,el.latitude),
content: Dom,
offset: new AMap.Pixel(0, 0)
});
this.map.add(maker)
可实现如图所示效果
但是地图缩放等级改变后,发现点位所指示的定位不准,通过查找文档发现问题出在offset参数上,该参数表示maker 左上角距离所给position的位移,即当offset为 0,0时,所给图片左上角为该定位点,而图示maker我们要左下角的小圆点定位在所给position。经过查看图片高度为92,所以我们只需要将maker向上位移92即对应左下角,对应参数为-92。
let maker = new AMap.Marker({
position: new AMap.LngLat(el.longitude,el.latitude),
content: Dom,
offset: new AMap.Pixel(0, -92)
});
this.map.add(maker)
这样缩放的时候maker和所对应的position就不会不一致了