From cdc9c593eb56a06867bf066430295987d4c41b64 Mon Sep 17 00:00:00 2001 From: Dmytro Gokun Date: Sat, 14 Mar 2020 03:32:08 +0200 Subject: [PATCH] [mapbox-gl] add LngLat.distanceTo (#43084) --- types/mapbox-gl/index.d.ts | 4 ++++ types/mapbox-gl/mapbox-gl-tests.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts index 65665c7f76..93cf6e6fdc 100644 --- a/types/mapbox-gl/index.d.ts +++ b/types/mapbox-gl/index.d.ts @@ -1056,6 +1056,10 @@ declare namespace mapboxgl { /** Return a LngLat as a string */ toString(): string; + /** Returns the approximate distance between a pair of coordinates in meters + * Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159) */ + distanceTo(lngLat: LngLat): number; + toBounds(radius: number): LngLatBounds; static convert(input: LngLatLike): mapboxgl.LngLat; diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts index 11cfe93b0c..2856ab20d0 100644 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ b/types/mapbox-gl/mapbox-gl-tests.ts @@ -687,6 +687,7 @@ expectType({ lon: 0, lat: 0 }); new mapboxgl.LngLat(0, 0); expectType(mapboxgl.LngLat.convert(lnglatlike)); +expectType(new mapboxgl.LngLat(0, 0).distanceTo(new mapboxgl.LngLat(0, 0))); /* * LngLatBoundsLike