How to rotate a marker in ngx-leaflet

260 Views Asked by At

I have read through the documentation but can't seem to find a way to rotate a marker using ngx-leaflet (I would like to dynamically change based on my compass heading).

1

There are 1 best solutions below

1
Shaun On

Here is the solution as there is a type definition for this:

npm i -S @types/leaflet-rotatedmarker leaflet-rotatedmarker

Then just import the module:

import 'leaflet-rotatedmarker';

Now your marker has extra functions to set rotation:

const currentMarker = marker([-28, 15], {
  icon: icon({
    iconSize: [25, 41],
    iconAnchor: [13, 41],
    iconUrl: 'assets/markers/marker-icon-green.png',
    iconRetinaUrl: 'assets/markers/marker-icon-2x-green.png',
    shadowUrl: 'assets/markers/marker-shadow.png'
  })
});
currentMarker.setRotationAngle(90);