From e7b6ff74cefeb6b7ed55982da13ec160341d67d7 Mon Sep 17 00:00:00 2001 From: reblace Date: Mon, 2 Jan 2017 13:05:33 -0500 Subject: [PATCH] Making the GeoJSON methods accessible as static methods --- leaflet/index.d.ts | 85 +++++++++++++++++++++------------------- leaflet/leaflet-tests.ts | 12 ++++++ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index 0d455717f2..1e8231f497 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -817,6 +817,51 @@ declare namespace L { coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng; // check if LatLng has an altitude property } + export class GeoJSON { + /** + * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer + * and/or coordsToLatLng functions if provided as options. + */ + static geometryToLayer(featureData: GeoJSON.Feature, options?: GeoJSONOptions): Layer; + + /** + * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or + * 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. + */ + static coordsToLatLng(coords: [number, number] | [number, number, number]): LatLng; + + /** + * Creates a multidimensional array of LatLngs from a GeoJSON coordinates array. + * levelsDeep specifies the nesting level (0 is for an array of points, 1 for an array of + * arrays of points, etc., 0 by default). + * Can use a custom coordsToLatLng function. + */ + static coordsToLatLngs( + coords: any[], + levelsDeep?: number, + coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng): any[]; // Using any[] to avoid artificially limiting valid calls + + /** + * Reverse of coordsToLatLng + */ + static latLngToCoords(latlng: LatLng): number[]; + + /** + * Reverse of coordsToLatLngs closed determines whether the first point should be + * appended to the end of the array to close the feature, only used when levelsDeep is 0. + * False by default. + */ + static latLngsToCoords(latlngs: any[], levelsDeep?: number, closed?: boolean): any[]; // Using any[] to avoid artificially limiting valid calls + + /** + * Normalize GeoJSON geometries/features into GeoJSON features. + */ + static asFeature(geojson: GeoJSON.GeometryObject): GeoJSON.Feature; + + static asFeature(geojson: GeoJSON.Feature): GeoJSON.Feature; + + } + /** * Represents a GeoJSON object or an array of GeoJSON objects. * Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup. @@ -838,46 +883,6 @@ declare namespace L { */ setStyle(style: StyleFunction): this; - /** - * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer - * and/or coordsToLatLng functions if provided as options. - */ - geometryToLayer(featureData: GeoJSON.Feature, options?: GeoJSONOptions): Layer; - - /** - * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or - * 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. - */ - coordsToLatLng(coords: [number, number]): LatLng; - - coordsToLatLng(coords: [number, number, number]): LatLng; - - /** - * Creates a multidimensional array of LatLngs from a GeoJSON coordinates array. - * levelsDeep specifies the nesting level (0 is for an array of points, 1 for an array of - * arrays of points, etc., 0 by default). - * Can use a custom coordsToLatLng function. - */ - coordsToLatLngs(coords: Array, levelsDeep?: number, coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng): LatLng[]; // Not entirely sure how to define arbitrarily nested arrays - - /** - * Reverse of coordsToLatLng - */ - latLngToCoords(latlng: LatLng): [number, number] | [number, number, number]; - - /** - * Reverse of coordsToLatLngs closed determines whether the first point should be - * appended to the end of the array to close the feature, only used when levelsDeep is 0. - * False by default. - */ - latLngsToCoords(latlngs: Array, levelsDeep?: number, closed?: boolean): [number, number] | [number, number, number]; - - /** - * Normalize GeoJSON geometries/features into GeoJSON features. - */ - asFeature(geojson: GeoJSON.GeometryObject): GeoJSON.Feature; - - asFeature(geojson: GeoJSON.Feature): GeoJSON.Feature; } /** diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index 8b988509c6..93d019b46b 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -358,6 +358,18 @@ draggable.enable(); draggable.disable(); draggable.on('drag', () => {}); +let twoCoords: [number, number] = [1, 2]; +latLng = L.GeoJSON.coordsToLatLng(twoCoords); +let coords: number[] = L.GeoJSON.latLngToCoords(latLng); + +let threeCoords: [number, number, number] = [1, 2, 3]; +latLng = L.GeoJSON.coordsToLatLng(threeCoords); +coords = L.GeoJSON.latLngToCoords(latLng); + +let nestedTwoCoords = [ [12, 13], [13, 14], [14, 15] ]; +let nestedLatLngs: L.LatLng[] = L.GeoJSON.coordsToLatLngs(nestedTwoCoords, 1); +nestedTwoCoords = L.GeoJSON.latLngsToCoords(nestedLatLngs, 1); + class MyMarker extends L.Marker { constructor() { super([12, 13]);