简体   繁体   中英

Leaflet map: Rotated Marker for ionic2 (Typescript)

I'm a typescript "newbie", currently working on an ionic2 project (Typescript) that use leaflet v1.1.0 as a map. I need to rotate a marker. In previous projects (JavaScript) I was using Leaflet.RotatedMarker . But this plugin isn't typed and It can't be used in my current project.

I need help either finding a way to use leaflet rotated marker plugin or to create the marker rotation behavior directly in my code.

Since a few months TypeScript type definitions for Leaflet.RotatedMarker are provided here: https://github.com/DefinitelyTyped/DefinitelyTyped/commits/master/types/leaflet-rotatedmarker

You need to install them @types/leaflet-rotatedmarker in addition to leaflet-rotatedmarker

If you're using npm you just need to install both packages:

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

Then you can set the rotationAngle on your marker.

import * as L from 'leaflet';
import 'leaflet-rotatedmarker';
...
 let marker = L.marker([47,18], {         
          rotationAngle: 180
          icon: ...,
        });

As a temporary solution I've used L.divIcon and it work perfectly

L.divIcon({
  html: '<img class="leaflet-marker-icon leaflet-zoom-animated" src="[icon image URL]" style="width: [icon width]px; height: [icon height]px;transform: rotate([angle]deg);  -webkit-transform: rotate([angle]deg); -moz-transform:rotate([angle]deg);" />'
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM