leaflet 中没有 setRotation 方法,因此可以使用 leaflet-rotatedmarker 插件来实现旋转功能。
步骤如下:
在项目中安装 leaflet-rotatedmarker 插件:npm install leaflet-rotatedmarker --save
导入插件:import 'leaflet-rotatedmarker';
在代码中使用 RotatedMarker 类替换原来的 L.marker,并使用 setRotation 方法设置旋转角度,例如:
javascriptCopy code
this.mapDataa.map(res=>{
let marker = L.marker([res.lat, res.lng], {rotationAngle:45// 设置旋转角度为45度
}).addTo(map);
marker.setIcon(
L.icon({
iconUrl:require("../../assets/images/zzzz.png"),
iconSize: [25,12]
})
);
});
这样就可以实现标记的旋转功能了。