From c0d3c074f0a6adfe3c214abf9054cc637440f5eb Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 12:51:30 +0100 Subject: [PATCH 1/6] Adding generic GeoJSON properties to the type-definition of leaflet according to the enhancements in PR #20932 and the discussion in issue #20103. --- types/leaflet/index.d.ts | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index b4c71d06f7..01dca1a3f0 100644 --- a/types/leaflet/index.d.ts +++ b/types/leaflet/index.d.ts @@ -581,9 +581,9 @@ export interface PolylineOptions extends PathOptions { noClip?: boolean; } -export class Polyline extends Path { +export class Polyline extends Path { constructor(latlngs: LatLngExpression[], options?: PolylineOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; getLatLngs(): LatLng[]; setLatLngs(latlngs: LatLngExpression[]): this; isEmpty(): boolean; @@ -591,19 +591,19 @@ export class Polyline; + feature?: geojson.Feature; options: PolylineOptions; } export function polyline(latlngs: LatLngExpression[], options?: PolylineOptions): Polyline; -export class Polygon extends Polyline { +export class Polygon

extends Polyline { constructor(latlngs: LatLngExpression[] | LatLngExpression[][], options?: PolylineOptions); } export function polygon(latlngs: LatLngExpression[] | LatLngExpression[][], options?: PolylineOptions): Polygon; -export class Rectangle extends Polygon { +export class Rectangle

extends Polygon

{ constructor(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions); setBounds(latLngBounds: LatLngBoundsExpression): this; } @@ -614,21 +614,21 @@ export interface CircleMarkerOptions extends PathOptions { radius?: number; } -export class CircleMarker extends Path { +export class CircleMarker

extends Path { constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); - toGeoJSON(): geojson.Feature; + toGeoJSON(): geojson.Feature; setLatLng(latLng: LatLngExpression): this; getLatLng(): LatLng; setRadius(radius: number): this; getRadius(): number; options: CircleMarkerOptions; - feature?: geojson.Feature; + feature?: geojson.Feature; } export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker; -export class Circle extends CircleMarker { +export class Circle

extends CircleMarker

{ constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); constructor(latlng: LatLngExpression, radius: number, options?: CircleMarkerOptions); // deprecated! getBounds(): LatLngBounds; @@ -666,12 +666,12 @@ export function canvas(options?: RendererOptions): Canvas; * If you add it to the map, any layers added or removed from the group will be * added/removed on the map as well. Extends Layer. */ -export class LayerGroup extends Layer { +export class LayerGroup

extends Layer { constructor(layers?: Layer[]); /** * Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection, GeoJSONFeatureCollection or Multipoint). */ - toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + toGeoJSON(): geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; /** * Adds the given layer to the group. @@ -725,7 +725,7 @@ export class LayerGroup extends Layer { */ getLayerId(layer: Layer): number; - feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; + feature?: geojson.FeatureCollection | geojson.Feature | geojson.GeometryCollection; } /** @@ -737,11 +737,11 @@ export function layerGroup(layers: Layer[]): LayerGroup; * Extended LayerGroup that also has mouse events (propagated from * members of the group) and a shared bindPopup method. */ -export class FeatureGroup extends LayerGroup { +export class FeatureGroup

extends LayerGroup

{ /** * Sets the given path options to each layer of the group that has a setStyle method. */ - setStyle(style: StyleFunction): this; + setStyle(style: StyleFunction

): this; /** * Brings the layer group to the top of all other layers @@ -765,9 +765,9 @@ export class FeatureGroup extends LayerGroup { */ export function featureGroup(layers?: Layer[]): FeatureGroup; -export type StyleFunction = (feature?: geojson.Feature) => PathOptions; +export type StyleFunction

= (feature?: geojson.Feature) => PathOptions; -export interface GeoJSONOptions extends LayerOptions { +export interface GeoJSONOptions

extends LayerOptions { /** * A Function defining how GeoJSON points spawn Leaflet layers. * It is internally called when data is added, passing the GeoJSON point @@ -781,7 +781,7 @@ export interface GeoJSONOptions extends LayerOptions { * } * ``` */ - pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings + pointToLayer?(geoJsonPoint: geojson.Feature, latlng: LatLng): Layer; // should import GeoJSON typings /** * A Function defining the Path options for styling GeoJSON lines and polygons, @@ -795,7 +795,7 @@ export interface GeoJSONOptions extends LayerOptions { * } * ``` */ - style?: StyleFunction; + style?: StyleFunction

; /** * A Function that will be called once for each created Feature, after it @@ -807,7 +807,7 @@ export interface GeoJSONOptions extends LayerOptions { * function (feature, layer) {} * ``` */ - onEachFeature?(feature: geojson.Feature, layer: Layer): void; + onEachFeature?(feature: geojson.Feature, layer: Layer): void; /** * A Function that will be used to decide whether to show a feature or not. @@ -820,7 +820,7 @@ export interface GeoJSONOptions extends LayerOptions { * } * ``` */ - filter?(geoJsonFeature: geojson.Feature): boolean; + filter?(geoJsonFeature: geojson.Feature): boolean; /** * A Function that will be used for converting GeoJSON coordinates to LatLngs. @@ -833,12 +833,12 @@ export interface GeoJSONOptions extends LayerOptions { * Represents a GeoJSON object or an array of GeoJSON objects. * Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup. */ -export class GeoJSON extends FeatureGroup { +export class GeoJSON

extends FeatureGroup

{ /** * 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; + static geometryToLayer

(featureData: geojson.Feature, options?: GeoJSONOptions

): Layer; /** * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or @@ -872,9 +872,9 @@ export class GeoJSON extends FeatureGroup { /** * Normalize GeoJSON geometries/features into GeoJSON features. */ - static asFeature(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; + static asFeature

(geojson: geojson.Feature | geojson.GeometryObject): geojson.Feature; - constructor(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions) + constructor(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions

) /** * Adds a GeoJSON object to the layer. */ @@ -889,9 +889,9 @@ export class GeoJSON extends FeatureGroup { /** * Changes styles of GeoJSON vector layers with the given style function. */ - setStyle(style: StyleFunction): this; + setStyle(style: StyleFunction

): this; - options: GeoJSONOptions; + options: GeoJSONOptions

; } /** @@ -901,7 +901,7 @@ export class GeoJSON extends FeatureGroup { * map (you can alternatively add it later with addData method) and * an options object. */ -export function geoJSON(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions): GeoJSON; +export function geoJSON

(geojson?: geojson.GeoJsonObject, options?: GeoJSONOptions

): GeoJSON

; export type Zoom = boolean | 'center'; From b4d0aa4d5f0e3e49f95f2229b83cee30cbca5719 Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 13:33:51 +0100 Subject: [PATCH 2/6] Marker has also a toGeoJSON method and an optional feature property like the circleMarker has --- types/leaflet/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index 01dca1a3f0..a6c57b0557 100644 --- a/types/leaflet/index.d.ts +++ b/types/leaflet/index.d.ts @@ -1457,8 +1457,9 @@ export interface MarkerOptions extends InteractiveLayerOptions { riseOffset?: number; } -export class Marker extends Layer { +export class Marker

extends Layer { constructor(latlng: LatLngExpression, options?: MarkerOptions); + toGeoJSON(): geojson.Feature; getLatLng(): LatLng; setLatLng(latlng: LatLngExpression): this; setZIndexOffset(offset: number): this; @@ -1469,6 +1470,7 @@ export class Marker extends Layer { // Properties options: MarkerOptions; dragging?: Handler; + feature?: geojson.Feature; } export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; From a8df641bc3cae0415225be4b47029eb13f0ef04e Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 13:34:16 +0100 Subject: [PATCH 3/6] Write tests for the generic properties --- types/leaflet/leaflet-tests.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/types/leaflet/leaflet-tests.ts b/types/leaflet/leaflet-tests.ts index b85c8bf4d7..c647491b85 100644 --- a/types/leaflet/leaflet-tests.ts +++ b/types/leaflet/leaflet-tests.ts @@ -484,3 +484,15 @@ L.Util.requestAnimFrame(() => {}, {}); L.Util.requestAnimFrame(() => {}, {}, true); L.Util.cancelAnimFrame(1); L.Util.emptyImageUrl; + +interface MyProperties { + testProperty: string; +} + +(L.polygon(latLngs) as L.Polygon).feature.properties.testProperty = "test"; + +(L.marker([1, 2], { + icon: L.icon({ + iconUrl: 'my-icon.png' + }) +}) as L.Marker).feature.properties.testProperty = "test"; \ No newline at end of file From 7b7649682591e7ec0ff2d66fe3cc6fcbc381bae0 Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 13:35:55 +0100 Subject: [PATCH 4/6] Add missing EOF in new line --- types/leaflet/leaflet-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/leaflet/leaflet-tests.ts b/types/leaflet/leaflet-tests.ts index c647491b85..e1cdcd2b90 100644 --- a/types/leaflet/leaflet-tests.ts +++ b/types/leaflet/leaflet-tests.ts @@ -495,4 +495,4 @@ interface MyProperties { icon: L.icon({ iconUrl: 'my-icon.png' }) -}) as L.Marker).feature.properties.testProperty = "test"; \ No newline at end of file +}) as L.Marker).feature.properties.testProperty = "test"; From 0566a3bbb52f9a4e496d4ddbea253f3c2f076c1e Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 13:46:49 +0100 Subject: [PATCH 5/6] Force TypeScript version 2.3 for modules depending on the leaflet type definition --- types/leaflet-rotatedmarker/index.d.ts | 1 + types/proj4leaflet/index.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/types/leaflet-rotatedmarker/index.d.ts b/types/leaflet-rotatedmarker/index.d.ts index d11a82ae56..dfbf8966de 100644 --- a/types/leaflet-rotatedmarker/index.d.ts +++ b/types/leaflet-rotatedmarker/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/bbecquet/Leaflet.RotatedMarker // Definitions by: Robert Prib // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import * as L from 'leaflet'; diff --git a/types/proj4leaflet/index.d.ts b/types/proj4leaflet/index.d.ts index 1d88365237..81a16100e4 100644 --- a/types/proj4leaflet/index.d.ts +++ b/types/proj4leaflet/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/kartena/Proj4Leaflet#readme // Definitions by: BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import * as geojson from 'geojson'; import * as L from 'leaflet'; From d97cb4f781294056b9b8979e25cb94048fb82303 Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Thu, 2 Nov 2017 14:02:54 +0100 Subject: [PATCH 6/6] Solving #21069 in addition --- types/leaflet/index.d.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index a6c57b0557..b1e7ead796 100644 --- a/types/leaflet/index.d.ts +++ b/types/leaflet/index.d.ts @@ -741,7 +741,7 @@ export class FeatureGroup

extends LayerGroup

{ /** * Sets the given path options to each layer of the group that has a setStyle method. */ - setStyle(style: StyleFunction

): this; + setStyle(style: PathOptions): this; /** * Brings the layer group to the top of all other layers @@ -886,11 +886,6 @@ export class GeoJSON

extends FeatureGroup

{ */ resetStyle(layer: Layer): Layer; - /** - * Changes styles of GeoJSON vector layers with the given style function. - */ - setStyle(style: StyleFunction

): this; - options: GeoJSONOptions

; }