问题
While looking for a way to rotate markers in leaflet.js, I found the module leaflet-rotatedmarker. I installed it via npm, but now I don't know how to actually use it.
As per the readme, it only extends the existing Marker
class. To my understanding, I should be able to just call Marker.setRotationAngle()
now, but that function does not exist. Importing Marker
from leaflet-rotatedmarker
does not work either.
How do I properly import the extended class or how do I extend the existing leaflet class with the functions/attributes in the module? Thanks.
I am talking about the import { XYZ } from 'leaflet-rotatedmarker'
statement.
Edit:
It also does not work if I try to set the rotationAngle
in the constructor:
const marker = L.marker([tmpAgv.Pos.X, tmpAgv.Pos.Y], { alt: tmpAgv.Id }, {rotationAngle: 180}).addTo(this.mapObject);
The marker is still not rotated.
回答1:
I installed the same package you have:
npm install leaflet-rotatedmarker
And import it:
import 'leaflet-rotatedmarker';
And this is how I used:
let m = L.marker([lat,lng]).addTo(this.map);
m.setRotationAngle(180);
And before and after results:
After:
来源:https://stackoverflow.com/questions/56652984/importing-module-that-extends-a-class