问题描述
在地图上使用自定义标点(dom方式)后,缩放地图会造成标点位置偏移。
![]()
问题代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| const map = new AMap.Map('container')
const getMarkerContent = function (content) { return ` <div class="custom-content-marker"> <img src="//webapi.amap.com/theme/v1.3/markers/b/mark_bs.png"> <div class="device-num">${content}</div> </div> ` }
const marker = new AMap.Marker({ position: new AMap.LngLat(120.148838, 30.245366), content: getMarkerContent('西湖'), offset: new AMap.Pixel(-13, -17), ...option })
map.add(marker)
|
解决方式
增加锚点定位和偏移量。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| const map = new AMap.Map('container')
const getMarkerContent = function (content) { return ` <div class="custom-content-marker"> <img src="//webapi.amap.com/theme/v1.3/markers/b/mark_bs.png"> <div class="device-num">${content}</div> </div> ` }
const marker = new AMap.Marker({ position: new AMap.LngLat(120.148838, 30.245366), content: getMarkerContent('西湖'), offset: new AMap.Pixel(0, -17), anchor: 'center', ...option })
map.add(marker)
|