makinacorpus / Leaflet.GeometryUtil

Leaflet utility function on geometries
http://makinacorpus.github.io/Leaflet.GeometryUtil/
BSD 3-Clause "New" or "Revised" License
254 stars 94 forks source link

how to use GeometryUtil.destination in Angular2+ ? #73

Open sgrillon14 opened 6 years ago

haoliangyu commented 6 years ago

Angular 2+ uses TypeScript so you need the type definition to use this library. Unfortunately a dedicated type definition for this library doesn't exist yet. But you can still write a minimal .d.ts file just for the destination() function and import it into your TS project. As an example, you can take a look at this.

jbaranski commented 4 years ago

This worked for me (this makes a big assumption you're using ngx-leaflet and already have it working in your Angular2+ app):

  1. Add src/typings.d.ts, the content looks like below (just add more functions as needed):
    import * as L from 'leaflet';
    declare module 'leaflet' {
    export class GeometryUtil {
    static computeAngle(a: L.Point, b: L.Point): number;
    static closest(map: L.Map, layer: L.Layer, latlng: L.LatLng, vertices?: boolean): L.LatLng;
    }
    }
  2. npm install leaflet-geometryutil
  3. import 'leaflet-geometryutil' in some file (component, service, whatever...)
  4. Make calls like const latlng: LatLng = GeometryUtil.closest(this.map, this.polyline, map.getBounds().getCenter())