From 1636a8e3aa8756a36d79700fbc71e8e30581fac7 Mon Sep 17 00:00:00 2001 From: Mike van Afferden Date: Sat, 11 Mar 2017 00:59:32 +0100 Subject: [PATCH] Add GeometryUtil functions to leaflet-draw (#14755) * Add GeometryUtil functions to leaflet-draw Add two functions in the GeometryUtil namespace of leaflet-draw * Remove illegal whitespaces * Add GeometryUtil function calls to tests Validate that the function declarations are valid by adding calls of geodesicArea() and readableArea() to the tests. Remove a whitespace that the linter complained about. --- leaflet-draw/index.d.ts | 13 +++++++++++++ leaflet-draw/leaflet-draw-tests.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/leaflet-draw/index.d.ts b/leaflet-draw/index.d.ts index 9668940c3a..3e2963f18b 100644 --- a/leaflet-draw/index.d.ts +++ b/leaflet-draw/index.d.ts @@ -349,4 +349,17 @@ declare namespace L { handler: string; } } + + namespace GeometryUtil { + + /** + * Returns the area of a polygon drawn with leaflet.draw + */ + export function geodesicArea(coordinates: L.LatLngLiteral[]): number; + + /** + * Returns a readable area string in yards or metric + */ + export function readableArea(area: number, isMetric: boolean): string; + } } diff --git a/leaflet-draw/leaflet-draw-tests.ts b/leaflet-draw/leaflet-draw-tests.ts index 6373687a03..8ad6e2a804 100644 --- a/leaflet-draw/leaflet-draw-tests.ts +++ b/leaflet-draw/leaflet-draw-tests.ts @@ -42,3 +42,7 @@ map.on('draw:created', (e: any) => { drawnItems.addLayer(layer); }); + +let examplePolygon: L.LatLngLiteral[] = [{lng: 0, lat: 0}, {lng: 10, lat: 0}, {lng: 10, lat: 10}, {lng: 0, lat: 10}, {lng: 0, lat: 0}]; +let examplePolygonArea: number = L.GeometryUtil.geodesicArea(examplePolygon); +L.GeometryUtil.readableArea(examplePolygonArea, true);