diff --git a/types/leaflet/index.d.ts b/types/leaflet/index.d.ts index b4c71d06f7..b1e7ead796 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: PathOptions): 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. */ @@ -886,12 +886,7 @@ 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; + options: GeoJSONOptions

; } /** @@ -901,7 +896,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'; @@ -1457,8 +1452,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 +1465,7 @@ export class Marker extends Layer { // Properties options: MarkerOptions; dragging?: Handler; + feature?: geojson.Feature; } export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; diff --git a/types/leaflet/leaflet-tests.ts b/types/leaflet/leaflet-tests.ts index b85c8bf4d7..e1cdcd2b90 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";