Importing module that extends a class

北城余情 提交于 2019-12-10 12:11:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!