Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing module that extends a class

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.

like image 517
mneumann Avatar asked Jun 22 '26 07:06

mneumann


1 Answers

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:

Before Leaflet

After:

Leaflet After

like image 154
Maihan Nijat Avatar answered Jun 23 '26 22:06

Maihan Nijat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!