Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sgrillon14 opened this issue Jan 4, 2018 · 2 comments
Open

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

sgrillon14 opened this issue Jan 4, 2018 · 2 comments

Comments

@sgrillon14
Copy link

No description provided.

@haoliangyu
Copy link
Collaborator

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
Copy link

jbaranski commented Nov 26, 2019

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;
  }
}
  1. npm install leaflet-geometryutil
  2. import 'leaflet-geometryutil' in some file (component, service, whatever...)
  3. Make calls like const latlng: LatLng = GeometryUtil.closest(this.map, this.polyline, map.getBounds().getCenter())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants