2

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.

mneumann
  • 713
  • 2
  • 9
  • 42
  • `setRotationAngle()` is not a static class to access it like `Marker.setRotationAngle()`. Create instance of marker and then use it. – Maihan Nijat Jun 18 '19 at 16:01
  • I know, that was just an example. I have an instance and I'm trying to call the function, like in the example on the github page. – mneumann Jun 18 '19 at 16:02

1 Answers1

8

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

Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110