|
Leafletjs的标准图层的marker是可以通过组件 leaflet-rotatedmarker进行图标旋转的,在marker上添加两个属性:
rotationAngle:旋转角度,以度为单位,顺时针旋转。
rotationOrigin:旋转中心,默认值为 'bottom center',对应于标记图标的“尖端”。
但是leaflet-canvasmarker组件的图层使用leaflet-rotatedmarker的旋转方式失效,而在leaflet-canvasmarker官网提供了一个旋转的方法: Leaflet.Icon扩展参数 rotate
参考网址:https://zhuanlan.zhihu.com/p/593744067
关键代码:rotate: Math.PI / 180 * v.direction,
// 图标
const icon = L.icon({
iconUrl,
iconSize: [24, 24],
iconAnchor: [12, 12],
rotate: Math.PI / 180 * v.direction,
});
// 加到marker上
const m = L.marker([v.lat, v.lng],{ icon, data: v});
来源:https://www.cnblogs.com/zibocoder/p/18848768 |