From 16e5b26b3da67b6f1f693af4666db65c10596dbe Mon Sep 17 00:00:00 2001 From: Arne Schubert Date: Fri, 27 Jan 2017 17:22:50 +0100 Subject: [PATCH] Refactor td for leaflet and geojson --- geojson/geojson-tests.ts | 127 +- geojson/index.d.ts | 90 +- geojson/tslint.json | 1 + leaflet/index.d.ts | 2701 +++++++++++++++++++------------------- leaflet/leaflet-tests.ts | 30 + leaflet/tslint.json | 1 + 6 files changed, 1547 insertions(+), 1403 deletions(-) create mode 100644 geojson/tslint.json create mode 100644 leaflet/tslint.json diff --git a/geojson/geojson-tests.ts b/geojson/geojson-tests.ts index dc3432f48c..50b5f7b396 100644 --- a/geojson/geojson-tests.ts +++ b/geojson/geojson-tests.ts @@ -1,26 +1,27 @@ -var featureCollection: GeoJSON.FeatureCollection = { +import GeometryObject = GeoJSON.GeometryObject; +let featureCollection: GeoJSON.FeatureCollection = { type: "FeatureCollection", - features: [ - { + features: [ + { type: "Feature", geometry: { - type: "Point", + type: "Point", coordinates: [102.0, 0.5] }, properties: { prop0: "value0" } }, - { + { type: "Feature", geometry: { type: "LineString", coordinates: [ - [102.0, 0.0], - [103.0, 1.0], - [104.0, 0.0], + [102.0, 0.0], + [103.0, 1.0], + [104.0, 0.0], [105.0, 1.0] ] }, @@ -29,7 +30,7 @@ var featureCollection: GeoJSON.FeatureCollection = { prop1: 0.0 } }, - { + { type: "Feature", geometry: { type: "Polygon", @@ -52,9 +53,9 @@ var featureCollection: GeoJSON.FeatureCollection = { type: "proj4" } } -} +}; -var feature: GeoJSON.Feature = { +let featureWithPolygon: GeoJSON.Feature = { type: "Feature", bbox: [-180.0, -90.0, 180.0, 90.0], geometry: { @@ -67,29 +68,29 @@ var feature: GeoJSON.Feature = { }; -var point: GeoJSON.Point = { +let point: GeoJSON.Point = { type: "Point", coordinates: [100.0, 0.0] }; // This type is commonly used in the turf package -var pointCoordinates: number[] = point.coordinates +let pointCoordinates: number[] = point.coordinates; -var lineString: GeoJSON.LineString = { +let lineString: GeoJSON.LineString = { type: "LineString", coordinates: [ [100.0, 0.0], [101.0, 1.0] ] }; -var polygon: GeoJSON.Polygon = { +let polygon: GeoJSON.Polygon = { type: "Polygon", coordinates: [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] }; -var polygonWithHole: GeoJSON.Polygon = { +let polygonWithHole: GeoJSON.Polygon = { type: "Polygon", coordinates: [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], @@ -97,12 +98,12 @@ var polygonWithHole: GeoJSON.Polygon = { ] }; -var multiPoint: GeoJSON.MultiPoint = { +let multiPoint: GeoJSON.MultiPoint = { type: "MultiPoint", coordinates: [ [100.0, 0.0], [101.0, 1.0] ] }; -var multiLineString: GeoJSON.MultiLineString = { +let multiLineString: GeoJSON.MultiLineString = { type: "MultiLineString", coordinates: [ [ [100.0, 0.0], [101.0, 1.0] ], @@ -110,25 +111,103 @@ var multiLineString: GeoJSON.MultiLineString = { ] }; -var multiPolygon: GeoJSON.MultiPolygon = { +let multiPolygon: GeoJSON.MultiPolygon = { type: "MultiPolygon", coordinates: [ [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] ] -} +}; -var geometryCollection: GeoJSON.GeometryCollection = { +let geometryCollection: GeoJSON.GeometryCollection = { type: "GeometryCollection", "geometries": [ - { + { type: "Point", coordinates: [100.0, 0.0] }, - { + { type: "LineString", coordinates: [ [101.0, 0.0], [102.0, 1.0] ] } ] -} \ No newline at end of file +}; + +let feature: GeoJSON.Feature = { + type: "Feature", + geometry: lineString, + properties: null +}; +feature = { + type: "Feature", + geometry: polygon, + properties: null +}; +feature = { + type: "Feature", + geometry: polygonWithHole, + properties: null +}; +feature = { + type: "Feature", + geometry: multiPoint, + properties: null +}; +feature = { + type: "Feature", + geometry: multiLineString, + properties: null +}; +feature = { + type: "Feature", + geometry: multiPolygon, + properties: null +}; +feature = { + type: "Feature", + geometry: geometryCollection, + properties: null +}; + +featureCollection = { + type: "FeatureCollection", + features: [ + { + type: "Feature", + geometry: lineString, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: polygon, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: polygonWithHole, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: multiPoint, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: multiLineString, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: multiPolygon, + properties: {test: 'OK'} + }, { + type: "Feature", + geometry: geometryCollection, + properties: {test: 'OK'} + } + ], + crs: { + type: "link", + properties: { + href: "http://example.com/crs/42", + type: "proj4" + } + } +}; diff --git a/geojson/index.d.ts b/geojson/index.d.ts index f6261d81fe..b38106aae7 100644 --- a/geojson/index.d.ts +++ b/geojson/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for GeoJSON Format Specification +// Type definitions for GeoJSON Format Specification Revision 1.0 // Project: http://geojson.org/ // Definitions by: Jacob Bruun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -8,8 +8,7 @@ declare namespace GeoJSON { /*** * http://geojson.org/geojson-spec.html#geojson-objects */ - export interface GeoJsonObject - { + export interface GeoJsonObject { type: string; bbox?: number[]; crs?: CoordinateReferenceSystem; @@ -18,116 +17,107 @@ declare namespace GeoJSON { /*** * http://geojson.org/geojson-spec.html#positions */ - export type Position = number[] + export type Position = number[]; /*** * http://geojson.org/geojson-spec.html#geometry-objects */ - export interface GeometryObject extends GeoJsonObject - { - coordinates: any + export interface DirectGeometryObject extends GeoJsonObject { + coordinates: Position[][][] | Position[][] | Position[] | Position; } + /** + * GeometryObject supports geometry collection as well + */ + export type GeometryObject = DirectGeometryObject | GeometryCollection; /*** * http://geojson.org/geojson-spec.html#point */ - export interface Point extends GeometryObject - { - type: 'Point' - coordinates: Position + export interface Point extends DirectGeometryObject { + type: 'Point'; + coordinates: Position; } /*** * http://geojson.org/geojson-spec.html#multipoint */ - export interface MultiPoint extends GeometryObject - { - type: 'MultiPoint' - coordinates: Position[] + export interface MultiPoint extends DirectGeometryObject { + type: 'MultiPoint'; + coordinates: Position[]; } /*** * http://geojson.org/geojson-spec.html#linestring */ - export interface LineString extends GeometryObject - { - type: 'LineString' - coordinates: Position[] + export interface LineString extends DirectGeometryObject { + type: 'LineString'; + coordinates: Position[]; } /*** * http://geojson.org/geojson-spec.html#multilinestring */ - export interface MultiLineString extends GeometryObject - { - type: 'MultiLineString' - coordinates: Position[][] + export interface MultiLineString extends DirectGeometryObject { + type: 'MultiLineString'; + coordinates: Position[][]; } /*** * http://geojson.org/geojson-spec.html#polygon */ - export interface Polygon extends GeometryObject - { - type: 'Polygon' - coordinates: Position[][] + export interface Polygon extends DirectGeometryObject { + type: 'Polygon'; + coordinates: Position[][]; } /*** * http://geojson.org/geojson-spec.html#multipolygon */ - export interface MultiPolygon extends GeometryObject - { - type: 'MultiPolygon' - coordinates: Position[][][] + export interface MultiPolygon extends DirectGeometryObject { + type: 'MultiPolygon'; + coordinates: Position[][][]; } /*** * http://geojson.org/geojson-spec.html#geometry-collection */ - export interface GeometryCollection extends GeoJsonObject - { - type: 'GeometryCollection' + export interface GeometryCollection extends GeoJsonObject { + type: 'GeometryCollection'; geometries: GeometryObject[]; } /*** * http://geojson.org/geojson-spec.html#feature-objects */ - export interface Feature extends GeoJsonObject - { - type: 'Feature' + export interface Feature extends GeoJsonObject { + type: 'Feature'; geometry: T; - properties: any; + properties: {} | null; id?: string; } /*** * http://geojson.org/geojson-spec.html#feature-collection-objects */ - export interface FeatureCollection extends GeoJsonObject - { - type: 'FeatureCollection' - features: Feature[]; + export interface FeatureCollection extends GeoJsonObject { + type: 'FeatureCollection'; + features: Array>; } /*** * http://geojson.org/geojson-spec.html#coordinate-reference-system-objects */ - export interface CoordinateReferenceSystem - { + export interface CoordinateReferenceSystem { type: string; properties: any; } - export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem - { - properties: { name: string } + export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem { + properties: { name: string }; } - export interface LinkedCoordinateReferenceSystem extends CoordinateReferenceSystem - { - properties: { href: string; type: string } + export interface LinkedCoordinateReferenceSystem extends CoordinateReferenceSystem { + properties: { href: string; type: string }; } } diff --git a/geojson/tslint.json b/geojson/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/geojson/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index 4112082f54..b62695dd10 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -1,1459 +1,1502 @@ -// Type definitions for Leaflet.js 1.0.2 +// Type definitions for Leaflet.js 1.0 // Project: https://github.com/Leaflet/Leaflet // Definitions by: Alejandro Sánchez // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// - type NativeMouseEvent = MouseEvent; type NativeKeyboardEvent = KeyboardEvent; -declare namespace L { - export class Class { - static extend(props: any): any/* how to return constructor of self extended type ? */; - static include(props: any): any /* how to return self extended type ? */; - static mergeOptions(props: any): any /* how to return self extended type ? */; - static addInitHook(initHookFn: () => void): any/* how to return self extended type ? */; - } +import * as GeoJSONDefinition from 'geojson'; - export class Transformation { - constructor(a: number, b: number, c: number, d: number); +export class Class { + static extend(props: any): any/* how to return constructor of self extended type ? */; + static include(props: any): any /* how to return self extended type ? */; + static mergeOptions(props: any): any /* how to return self extended type ? */; + static addInitHook(initHookFn: () => void): any/* how to return self extended type ? */; +} - transform(point: Point, scale?: number): Point; +export class Transformation { + constructor(a: number, b: number, c: number, d: number); - untransform(point: Point, scale?: number): Point; - } + transform(point: Point, scale?: number): Point; - export namespace LineUtil { - export function simplify(points: Array, tolerance: number): Array; + untransform(point: Point, scale?: number): Point; +} - export function simplify(points: Array, tolerance: number): Array; +export namespace LineUtil { + export function simplify(points: PointExpression[], tolerance: number): Point[]; - export function pointToSegmentDistance(p: Point, p1: Point, p2: Point): number; + export function pointToSegmentDistance(p: PointExpression, p1: PointExpression, p2: PointExpression): number; - export function pointToSegmentDistance(p: PointTuple, p1: PointTuple, p2: PointTuple): number; + export function closestPointOnSegment(p: PointExpression, p1: PointExpression, p2: PointExpression): Point; +} - export function closestPointOnSegment(p: Point, p1: Point, p2: Point): Point; +export namespace PolyUtil { + export function clipPolygon(points: PointExpression[], bounds: BoundsExpression, round?: boolean): Point[]; +} - export function closestPointOnSegment(p: PointTuple, p1: PointTuple, p2: PointTuple): Point; - } +export class DomUtil { + /** + * Get Element by its ID or with the given HTML-Element + */ + static get(element: string | HTMLElement): HTMLElement; + static getStyle(el: HTMLElement, styleAttrib: string): string; + static create(tagName: string, className?: string, container?: HTMLElement): HTMLElement; + static remove(el: HTMLElement): void; + static empty(el: HTMLElement): void; + static toFront(el: HTMLElement): void; + static toBack(el: HTMLElement): void; + static hasClass(el: HTMLElement, name: string): boolean; + static addClass(el: HTMLElement, name: string): void; + static removeClass(el: HTMLElement, name: string): void; + static setClass(el: HTMLElement, name: string): void; + static getClass(el: HTMLElement): string; + static setOpacity(el: HTMLElement, opacity: number): void; + static testProp(props: string[]): string | boolean/*=false*/; + static setTransform(el: HTMLElement, offset: Point, scale?: number): void; + static setPosition(el: HTMLElement, position: Point): void; + static getPosition(el: HTMLElement): Point; + static disableTextSelection(): void; + static enableTextSelection(): void; + static disableImageDrag(): void; + static enableImageDrag(): void; + static preventOutline(el: HTMLElement): void; + static restoreOutline(): void; +} - export namespace PolyUtil { - export function clipPolygon(points: Array, bounds: Bounds, round?: boolean): Array; +export abstract class CRS { + latLngToPoint(latlng: LatLngExpression, zoom: number): Point; + pointToLatLng(point: PointExpression, zoom: number): LatLng; + project(latlng: LatLngExpression): Point; + unproject(point: PointExpression): LatLng; + scale(zoom: number): number; + zoom(scale: number): number; + getProjectedBounds(zoom: number): Bounds; + distance(latlng1: LatLngExpression, latlng2: LatLngExpression): number; + wrapLatLng(latlng: LatLngExpression): LatLng; - export function clipPolygon(points: Array, bounds: BoundsLiteral, round?: boolean): Array; - } + code: string; + wrapLng: [number, number]; + wrapLat: [number, number]; + infinite: boolean; +} - export class DomUtil { - static get(id: string): HTMLElement; - static get(id: HTMLElement): HTMLElement; - static getStyle(el: HTMLElement, styleAttrib: string): string; - static create(tagName: String, className?: String, container?: HTMLElement): HTMLElement; - static remove(el: HTMLElement):void; - static empty(el: HTMLElement):void; - static toFront(el: HTMLElement):void; - static toBack(el: HTMLElement):void; - static hasClass(el: HTMLElement, name: String): Boolean; - static addClass(el: HTMLElement, name: String):void; - static removeClass(el: HTMLElement, name: String):void; - static setClass(el: HTMLElement, name: String):void; - static getClass(el: HTMLElement): String; - static setOpacity(el: HTMLElement, opacity: Number):void; - static testProp(props: String[]): String|boolean/*=false*/; - static setTransform(el: HTMLElement, offset: Point, scale?: Number):void; - static setPosition(el: HTMLElement, position: Point):void; - static getPosition(el: HTMLElement): Point; - static disableTextSelection(): void; - static enableTextSelection(): void; - static disableImageDrag(): void; - static enableImageDrag(): void; - static preventOutline(el: HTMLElement): void; - static restoreOutline(): void; - } +export namespace CRS { + export const EPSG3395: CRS; + export const EPSG3857: CRS; + export const EPSG4326: CRS; + export const Earth: CRS; + export const Simple: CRS; +} - export interface CRS { - latLngToPoint(latlng: LatLngExpression, zoom: number): Point; - pointToLatLng(point: PointExpression, zoom: number): LatLng; - project(latlng: LatLngExpression): Point; - unproject(point: PointExpression): LatLng; - scale(zoom: number): number; - zoom(scale: number): number; - getProjectedBounds(zoom: number): Bounds; - distance(latlng1: LatLngExpression, latlng2: LatLngExpression): number; - wrapLatLng(latlng: LatLngExpression): LatLng; +export interface Projection { + project(latlng: LatLngExpression): Point; + unproject(point: PointExpression): LatLng; - code: string; - wrapLng: [number, number]; - wrapLat: [number, number]; - infinite: boolean; - } + bounds: LatLngBounds; +} - export namespace CRS { - export const EPSG3395: CRS; - export const EPSG3857: CRS; - export const EPSG4326: CRS; - export const Earth: CRS; - export const Simple: CRS; - } +export namespace Projection { + export const LonLat: Projection; + export const Mercator: Projection; + export const SphericalMercator: Projection; +} - export interface Projection { - project(latlng: LatLngExpression): Point; - unproject(point: PointExpression): LatLng; +export class LatLng { + constructor(latitude: number, longitude: number, altitude?: number); + constructor(coords: LatLngTuple | [number, number, number] | LatLngLiteral | {lat: number, lng: number, alt?: number}); + equals(otherLatLng: LatLngExpression, maxMargin?: number): boolean; + toString(): string; + distanceTo(otherLatLng: LatLngExpression): number; + wrap(): LatLng; + toBounds(sizeInMeters: number): LatLngBounds; - bounds: LatLngBounds; - } + lat: number; + lng: number; + alt: number; +} - export namespace Projection { - export const LonLat: Projection; - export const Mercator: Projection; - export const SphericalMercator: Projection; - } +export interface LatLngLiteral { + lat: number; + lng: number; +} - export interface LatLng { - equals(otherLatLng: LatLngExpression, maxMargin?: number): boolean; - toString(): string; - distanceTo(otherLatLng: LatLngExpression): number; - wrap(): LatLng; - toBounds(sizeInMeters: number): LatLngBounds; +export type LatLngTuple = [number, number]; - lat: number; - lng: number; - alt: number; - } +type LatLngExpression = LatLng | LatLngLiteral | LatLngTuple; - export interface LatLngLiteral { - lat: number; - lng: number; - } +export function latLng(latitude: number, longitude: number, altitude?: number): LatLng; - export type LatLngTuple = [number, number]; +export function latLng(coords: LatLngTuple | [number, number, number] | LatLngLiteral | {lat: number, lng: number, alt?: number}): LatLng; - type LatLngExpression = LatLng | LatLngLiteral | LatLngTuple; +export class LatLngBounds { + constructor(southWest: LatLngExpression, northEast: LatLngExpression); + constructor(latlngs: LatLngBoundsLiteral); + extend(latlngOrBounds: LatLngExpression | LatLngBoundsExpression): this; + pad(bufferRatio: number): LatLngBounds; // does this modify the current instance or does it return a new one? + getCenter(): LatLng; + getSouthWest(): LatLng; + getNorthEast(): LatLng; + getNorthWest(): LatLng; + getSouthEast(): LatLng; + getWest(): number; + getSouth(): number; + getEast(): number; + getNorth(): number; + contains(otherBoundsOrLatLng: LatLngBoundsExpression | LatLngExpression): boolean; + intersects(otherBounds: LatLngBoundsExpression): boolean; + overlaps(otherBounds: BoundsExpression): boolean; // investigate if this is really bounds and not latlngbounds + toBBoxString(): string; + equals(otherBounds: LatLngBoundsExpression): boolean; + isValid(): boolean; +} - export function latLng(latitude: number, longitude: number, altitude?: number): LatLng; +export type LatLngBoundsLiteral = LatLngTuple[]; - export function latLng(coords: LatLngTuple): LatLng; +type LatLngBoundsExpression = LatLngBounds | LatLngBoundsLiteral; - export function latLng(coords: [number, number, number]): LatLng; +export function latLngBounds(southWest: LatLngExpression, northEast: LatLngExpression): LatLngBounds; - export function latLng(coords: LatLngLiteral): LatLng; +export function latLngBounds(latlngs: LatLngBoundsLiteral): LatLngBounds; - export function latLng(coords: {lat: number, lng: number, alt: number}): LatLng; +export type PointTuple = [number, number]; - export interface LatLngBounds { - extend(latlng: LatLngExpression): this; - extend(otherBounds: LatLngBoundsExpression): this; - pad(bufferRatio: number): LatLngBounds; // does this modify the current instance or does it return a new one? - getCenter(): LatLng; - getSouthWest(): LatLng; - getNorthEast(): LatLng; - getNorthWest(): LatLng; - getSouthEast(): LatLng; - getWest(): number; - getSouth(): number; - getEast(): number; - getNorth(): number; - contains(otherBounds: LatLngBoundsExpression): boolean; - contains(latlng: LatLngExpression): boolean; - intersects(otherBounds: LatLngBoundsExpression): boolean; - overlaps(otherBounds: BoundsExpression): boolean; // investigate if this is really bounds and not latlngbounds - toBBoxString(): string; - equals(otherBounds: LatLngBoundsExpression): boolean; - isValid(): boolean; - } +export class Point { + constructor(x: number, y: number, round?: boolean); + constructor(coords: PointTuple | {x: number, y: number}); + clone(): Point; + add(otherPoint: PointExpression): Point; // investigate if this mutates or returns a new instance + subtract(otherPoint: PointExpression): Point; + divideBy(num: number): Point; + multiplyBy(num: number): Point; + scaleBy(scale: PointExpression): Point; + unscaleBy(scale: PointExpression): Point; + round(): Point; + floor(): Point; + ceil(): Point; + distanceTo(otherPoint: PointExpression): number; + equals(otherPoint: PointExpression): boolean; + contains(otherPoint: PointExpression): boolean; + toString(): string; + x: number; + y: number; +} - export type LatLngBoundsLiteral = Array; +type PointExpression = Point | PointTuple; - type LatLngBoundsExpression = LatLngBounds | LatLngBoundsLiteral; +export function point(x: number, y: number, round?: boolean): Point; - export function latLngBounds(southWest: LatLngExpression, northEast: LatLngExpression): LatLngBounds; +export function point(coords: PointTuple | {x: number, y: number}): Point; - export function latLngBounds(latlngs: LatLngBoundsLiteral): LatLngBounds; +export type BoundsLiteral = PointTuple[]; - export type PointTuple = [number, number]; +export class Bounds { + constructor(topLeft: PointExpression, bottomRight: PointExpression); + constructor(points: Point[] | BoundsLiteral); + extend(point: PointExpression): this; + getCenter(round?: boolean): Point; + getBottomLeft(): Point; + getTopRight(): Point; + getSize(): Point; + contains(pointOrBounds: BoundsExpression | PointExpression): boolean; + intersects(otherBounds: BoundsExpression): boolean; + overlaps(otherBounds: BoundsExpression): boolean; - export interface Point { - clone(): Point; - add(otherPoint: PointExpression): Point; // investigate if this mutates or returns a new instance - subtract(otherPoint: PointExpression): Point; - divideBy(num: number): Point; - multiplyBy(num: number): Point; - scaleBy(scale: PointExpression): Point; - unscaleBy(scale: PointExpression): Point; - round(): Point; - floor(): Point; - ceil(): Point; - distanceTo(otherPoint: PointExpression): number; - equals(otherPoint: PointExpression): boolean; - contains(otherPoint: PointExpression): boolean; - toString(): string; - x: number; - y: number; - } + min: Point; + max: Point; +} - type PointExpression = Point | PointTuple; +type BoundsExpression = Bounds | BoundsLiteral; - export function point(x: number, y: number, round?: boolean): Point; +export function bounds(topLeft: PointExpression, bottomRight: PointExpression): Bounds; - export function point(coords: PointTuple): Point; +export function bounds(points: Point[] | BoundsLiteral): Bounds; - export function point(coords: {x: number, y: number}): Point; +export type EventHandlerFn = (event: Event) => void; - export type BoundsLiteral = Array; +export interface EventHandlerFnMap { + [type: string]: EventHandlerFn; +} - export interface Bounds { - extend(point: PointExpression): this; - getCenter(round?: boolean): Point; - getBottomLeft(): Point; - getTopRight(): Point; - getSize(): Point; - contains(otherBounds: BoundsExpression): boolean; - contains(point: PointExpression): boolean; - intersects(otherBounds: BoundsExpression): boolean; - overlaps(otherBounds: BoundsExpression): boolean; - - min: Point; - max: Point; - } - - type BoundsExpression = Bounds | BoundsLiteral; - - export function bounds(topLeft: PointExpression, bottomRight: PointExpression): Bounds; - - export function bounds(points: Array): Bounds; - - export function bounds(points: BoundsLiteral): Bounds; - - export type EventHandlerFn = (event: Event) => void; - - export type EventHandlerFnMap = {[type: string]: EventHandlerFn}; +/** + * A set of methods shared between event-powered classes (like Map and Marker). + * Generally, events allow you to execute some function when something happens + * with an object (e.g. the user clicks on the map, causing the map to fire + * 'click' event). + */ +export abstract class Evented extends Class { + /** + * Adds a listener function (fn) to a particular event type of the object. + * You can optionally specify the context of the listener (object the this + * keyword will point to). You can also pass several space-separated types + * (e.g. 'click dblclick'). + */ + on(type: string, fn: EventHandlerFn, context?: any): this; /** - * A set of methods shared between event-powered classes (like Map and Marker). - * Generally, events allow you to execute some function when something happens - * with an object (e.g. the user clicks on the map, causing the map to fire - * 'click' event). + * Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} */ - export abstract class Evented extends Class { - /** - * Adds a listener function (fn) to a particular event type of the object. - * You can optionally specify the context of the listener (object the this - * keyword will point to). You can also pass several space-separated types - * (e.g. 'click dblclick'). - */ - on(type: string, fn: EventHandlerFn, context?: any): this; - - /** - * Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} - */ - on(eventMap: EventHandlerFnMap): this; - - /** - * Removes a previously added listener function. If no function is specified, - * it will remove all the listeners of that particular event from the object. - * Note that if you passed a custom context to on, you must pass the same context - * to off in order to remove the listener. - */ - off(type: string, fn?: EventHandlerFn, context?: any): this; - - /** - * Removes a set of type/listener pairs. - */ - off(eventMap: EventHandlerFnMap): this; - - /** - * Removes all listeners to all events on the object. - */ - off(): this; - - /** - * Fires an event of the specified type. You can optionally provide a data - * object — the first argument of the listener function will contain its properties. - * The event might can optionally be propagated to event parents. - */ - fire(type: string, data?: any, propagate?: boolean): this; - - /** - * Returns true if a particular event type has any listeners attached to it. - */ - listens(type: string): boolean; - - /** - * Behaves as on(...), except the listener will only get fired once and then removed. - */ - once(type: string, fn: EventHandlerFn, context?: any): this; - - /** - * Behaves as on(...), except the listener will only get fired once and then removed. - */ - once(eventMap: EventHandlerFnMap): this; - - /** - * Adds an event parent - an Evented that will receive propagated events - */ - addEventParent(obj: Evented): this; - - /** - * Removes an event parent, so it will stop receiving propagated events - */ - removeEventParent(obj: Evented): this; - - /** - * Alias for on(...) - * - * Adds a listener function (fn) to a particular event type of the object. - * You can optionally specify the context of the listener (object the this - * keyword will point to). You can also pass several space-separated types - * (e.g. 'click dblclick'). - */ - addEventListener(type: string, fn: EventHandlerFn, context?: any): this; - - /** - * Alias for on(...) - * - * Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} - */ - addEventListener(eventMap: EventHandlerFnMap): this; - - /** - * Alias for off(...) - * - * Removes a previously added listener function. If no function is specified, - * it will remove all the listeners of that particular event from the object. - * Note that if you passed a custom context to on, you must pass the same context - * to off in order to remove the listener. - */ - removeEventListener(type: string, fn: EventHandlerFn, context?: any): this; - - /** - * Alias for off(...) - * - * Removes a set of type/listener pairs. - */ - removeEventListener(eventMap: EventHandlerFnMap): this; - - /** - * Alias for off() - * - * Removes all listeners to all events on the object. - */ - clearAllEventListeners(): this; - - /** - * Alias for once(...) - * - * Behaves as on(...), except the listener will only get fired once and then removed. - */ - addOneTimeEventListener(type: string, fn: EventHandlerFn, context?: any): this; - - /** - * Alias for once(...) - * - * Behaves as on(...), except the listener will only get fired once and then removed. - */ - addOneTimeEventListener(eventMap: EventHandlerFnMap): this; - - /** - * Alias for fire(...) - * - * Fires an event of the specified type. You can optionally provide a data - * object — the first argument of the listener function will contain its properties. - * The event might can optionally be propagated to event parents. - */ - fireEvent(type: string, data?: any, propagate?: boolean): this; - - /** - * Alias for listens(...) - * - * Returns true if a particular event type has any listeners attached to it. - */ - hasEventListeners(type: string): boolean; - } + on(eventMap: EventHandlerFnMap): this; /** - * A class for making DOM elements draggable (including touch support). - * Used internally for map and marker dragging. Only works for elements - * that were positioned with [`L.DomUtil.setPosition`](#domutil-setposition). + * Removes a previously added listener function. If no function is specified, + * it will remove all the listeners of that particular event from the object. + * Note that if you passed a custom context to on, you must pass the same context + * to off in order to remove the listener. */ - export class Draggable extends Evented { - constructor(element: HTMLElement, dragStartTarget?: HTMLElement, preventOutline?: boolean); - - enable(): void; - - disable(): void; - - finishDrag(): void; - } - - interface LayerOptions { - pane?: string; - } - - interface InteractiveLayerOptions extends LayerOptions { - interactive?: boolean; - } - - export class Layer extends Evented { - constructor(options?: LayerOptions); - addTo(map: Map): this; - remove(): this; - removeFrom(map: Map): this; - getPane(name?: string): HTMLElement; - - // Popup methods - bindPopup(content: string, options?: PopupOptions): this; - bindPopup(content: HTMLElement, options?: PopupOptions): this; - bindPopup(content: (layer: Layer) => Content, options?: PopupOptions): this; - bindPopup(content: Popup): this; - unbindPopup(): this; - openPopup(): this; - openPopup(latlng: LatLngExpression): this; - closePopup(): this; - togglePopup(): this; - isPopupOpen(): boolean; - setPopupContent(content: string): this; - setPopupContent(content: HTMLElement): this; - setPopupContent(content: Popup): this; - getPopup(): Popup; - - // Tooltip methods - bindTooltip(content: string, options?: TooltipOptions): this; - bindTooltip(content: HTMLElement, options?: TooltipOptions): this; - bindTooltip(content: (layer: Layer) => Content, options?: TooltipOptions): this; - bindTooltip(content: Tooltip, options?: TooltipOptions): this; - unbindTooltip(): this; - openTooltip(): this; - openTooltip(latlng: LatLngExpression): this; - closeTooltip(): this; - toggleTooltip(): this; - isTooltipOpen(): boolean; - setTooltipContent(content: string): this; - setTooltipContent(content: HTMLElement): this; - setTooltipContent(content: Tooltip): this; - getTooltip(): Tooltip; - - // Extension methods - onAdd(map: Map): this; - onRemove(map: Map): this; - getEvents(): {[name: string]: (event: Event) => void}; - getAttribution(): string; - beforeAdd(map: Map): this; - } - - export interface GridLayerOptions { - tileSize?: number | Point; - opacity?: number; - updateWhenIdle?: boolean; - updateWhenZooming?: boolean; - updateInterval?: number; - attribution?: string; - zIndex?: number; - bounds?: LatLngBoundsExpression; - minZoom?: number; - maxZoom?: number; - noWrap?: boolean; - pane?: string; - className?: string; - keepBuffer?: number; - } - - export interface GridLayer extends Layer { - bringToFront(): this; - bringToBack(): this; - getAttribution(): string; - getContainer(): HTMLElement; - setOpacity(opacity: number): this; - setZIndex(zIndex: number): this; - isLoading(): boolean; - redraw(): this; - getTileSize(): Point; - } - - export function gridLayer(options?: GridLayerOptions): GridLayer; - - export interface TileLayerOptions extends GridLayerOptions { - minZoom?: number; - maxZoom?: number; - maxNativeZoom?: number; - subdomains?: string | Array; - errorTileUrl?: string; - zoomOffset?: number; - tms?: boolean; - zoomReverse?: boolean; - detectRetina?: boolean; - crossOrigin?: boolean; - [name: string]: any; - } - - export interface TileLayer extends GridLayer { - setUrl(url: string, noRedraw?: boolean): this; - } - - export function tileLayer(urlTemplate: string, options?: TileLayerOptions): TileLayer; - - export interface WMSOptions extends TileLayerOptions { - layers: string; - styles?: string; - format?: string; - transparent?: boolean; - version?: string; - crs?: CRS; - uppercase?: boolean; - } - - export interface WMS extends TileLayer { - setParams(params: any, noRedraw?: boolean): this; - } - - export namespace tileLayer { - export function wms(baseUrl: string, options?: WMSOptions): WMS; - } - - export interface ImageOverlayOptions extends LayerOptions { - opacity?: number; - alt?: string; - interactive?: boolean; - attribution?: string; - crossOrigin?: boolean; - } - - export interface ImageOverlay extends Layer { - setOpacity(opacity: number): this; - bringToFront(): this; - bringToBack(): this; - setUrl(url: string): this; - - /** Update the bounds that this ImageOverlay covers */ - setBounds(bounds: LatLngBounds): this; - - /** Get the bounds that this ImageOverlay covers */ - getBounds(): LatLngBounds; - - /** Get the img element that represents the ImageOverlay on the map */ - getElement(): HTMLImageElement; - } - - export function imageOverlay(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions): ImageOverlay; - - export type LineCapShape = 'butt' | 'round' | 'square' | 'inherit'; - - export type LineJoinShape = 'miter' | 'round' | 'bevel' | 'inherit'; - - export type FillRule = 'nonzero' | 'evenodd' | 'inherit'; - - export interface PathOptions extends InteractiveLayerOptions { - stroke?: boolean; - color?: string; - weight?: number; - opacity?: number; - lineCap?: LineCapShape; - lineJoin?: LineJoinShape; - dashArray?: string; - dashOffset?: string; - fill?: boolean; - fillColor?: string; - fillOpacity?: number; - fillRule?: FillRule; - renderer?: Renderer; - className?: string; - } - - export interface Path extends Layer { - redraw(): this; - setStyle(style: PathOptions): this; - bringToFront(): this; - bringToBack(): this; - } - - export interface PolylineOptions extends PathOptions { - smoothFactor?: number; - noClip?: boolean; - } - - interface InternalPolyline extends Path { - getLatLngs(): Array; - setLatLngs(latlngs: Array): this; - isEmpty(): boolean; - getCenter(): LatLng; - getBounds(): LatLngBounds; - addLatLng(latlng: LatLngExpression): this; - addLatLng(latlng: Array): this; // these three overloads aren't explicitly noted in the docs - } - - export interface Polyline extends InternalPolyline { - toGeoJSON(): GeoJSON.LineString | GeoJSON.MultiLineString; - } - - export function polyline(latlngs: Array, options?: PolylineOptions): Polyline; - export function polyline(latlngs: Array>, options?: PolylineOptions): Polyline; - - export interface Polygon extends InternalPolyline { - toGeoJSON(): GeoJSON.Polygon | GeoJSON.MultiPolygon; - } - - export function polygon(latlngs: Array, options?: PolylineOptions): Polygon; - - export function polygon(latlngs: Array>, options?: PolylineOptions): Polygon; - - export interface Rectangle extends Polygon { - setBounds(latLngBounds: LatLngBoundsExpression): this; - } - - export function rectangle(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions): Rectangle; - - export interface CircleMarkerOptions extends PathOptions { - radius?: number; - } - - export interface CircleMarker extends Path { - toGeoJSON(): GeoJSON.Point; - setLatLng(latLng: LatLngExpression): this; - getLatLng(): LatLng; - setRadius(radius: number): this; - getRadius(): number; - } - - export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker; - - export interface CircleOptions extends PathOptions { - radius?: number; - } - - export interface Circle extends CircleMarker { - setRadius(radius: number): this; - getRadius(): number; - getBounds(): LatLngBounds; - } - - export function circle(latlng: LatLngExpression, options?: CircleOptions): Circle; - export function circle(latlng: LatLngExpression, radius: number, options?: CircleOptions): Circle; - - export interface RendererOptions extends LayerOptions { - padding?: number; - } - - export interface Renderer extends Layer {} - - export interface SVG extends Renderer {} - - export namespace SVG { - export function create(name: string): SVGElement; - - export function pointsToPath(rings: Array, close: boolean): string; - - export function pointsToPath(rings: Array, close: boolean): string; - } - - export function svg(options?: RendererOptions): SVG; - - export interface Canvas extends Renderer {} - - export function canvas(options?: RendererOptions): Canvas; + off(type: string, fn?: EventHandlerFn, context?: any): this; /** - * Used to group several layers and handle them as one. - * 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. + * Removes a set of type/listener pairs. */ - export interface LayerGroup extends Layer { - /** - * Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection). - */ - toGeoJSON(): GeoJSON.GeometryCollection; + off(eventMap: EventHandlerFnMap): this; - /** - * Adds the given layer to the group. - */ - addLayer(layer: Layer): this; + /** + * Removes all listeners to all events on the object. + */ + off(): this; - /** - * Removes the given layer from the group. - */ - removeLayer(layer: Layer): this; + /** + * Fires an event of the specified type. You can optionally provide a data + * object — the first argument of the listener function will contain its properties. + * The event might can optionally be propagated to event parents. + */ + fire(type: string, data?: any, propagate?: boolean): this; - /** - * Removes the layer with the given internal ID from the group. - */ - removeLayer(id: number): this; + /** + * Returns true if a particular event type has any listeners attached to it. + */ + listens(type: string): boolean; - /** - * Returns true if the given layer is currently added to the group. - */ - hasLayer(layer: Layer): boolean; + /** + * Behaves as on(...), except the listener will only get fired once and then removed. + */ + once(type: string, fn: EventHandlerFn, context?: any): this; - /** - * Removes all the layers from the group. - */ - clearLayers(): this; + /** + * Behaves as on(...), except the listener will only get fired once and then removed. + */ + once(eventMap: EventHandlerFnMap): this; - /** - * Calls methodName on every layer contained in this group, passing any additional parameters. - * Has no effect if the layers contained do not implement methodName. - */ - invoke(methodName: string, ...params: Array): this; + /** + * Adds an event parent - an Evented that will receive propagated events + */ + addEventParent(obj: Evented): this; - /** - * Iterates over the layers of the group, - * optionally specifying context of the iterator function. - */ - eachLayer(fn: (layer: Layer) => void, context?: any): this; + /** + * Removes an event parent, so it will stop receiving propagated events + */ + removeEventParent(obj: Evented): this; - /** - * Returns the layer with the given internal ID. - */ - getLayer(id: number): Layer; + /** + * Alias for on(...) + * + * Adds a listener function (fn) to a particular event type of the object. + * You can optionally specify the context of the listener (object the this + * keyword will point to). You can also pass several space-separated types + * (e.g. 'click dblclick'). + */ + addEventListener(type: string, fn: EventHandlerFn, context?: any): this; - /** - * Returns an array of all the layers added to the group. - */ - getLayers(): Array; + /** + * Alias for on(...) + * + * Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} + */ + addEventListener(eventMap: EventHandlerFnMap): this; - /** - * Calls setZIndex on every layer contained in this group, passing the z-index. - */ - setZIndex(zIndex: number): this; + /** + * Alias for off(...) + * + * Removes a previously added listener function. If no function is specified, + * it will remove all the listeners of that particular event from the object. + * Note that if you passed a custom context to on, you must pass the same context + * to off in order to remove the listener. + */ + removeEventListener(type: string, fn: EventHandlerFn, context?: any): this; - /** - * Returns the internal ID for a layer - */ - getLayerId(layer: Layer): number; + /** + * Alias for off(...) + * + * Removes a set of type/listener pairs. + */ + removeEventListener(eventMap: EventHandlerFnMap): this; + + /** + * Alias for off() + * + * Removes all listeners to all events on the object. + */ + clearAllEventListeners(): this; + + /** + * Alias for once(...) + * + * Behaves as on(...), except the listener will only get fired once and then removed. + */ + addOneTimeEventListener(type: string, fn: EventHandlerFn, context?: any): this; + + /** + * Alias for once(...) + * + * Behaves as on(...), except the listener will only get fired once and then removed. + */ + addOneTimeEventListener(eventMap: EventHandlerFnMap): this; + + /** + * Alias for fire(...) + * + * Fires an event of the specified type. You can optionally provide a data + * object — the first argument of the listener function will contain its properties. + * The event might can optionally be propagated to event parents. + */ + fireEvent(type: string, data?: any, propagate?: boolean): this; + + /** + * Alias for listens(...) + * + * Returns true if a particular event type has any listeners attached to it. + */ + hasEventListeners(type: string): boolean; +} + +/** + * A class for making DOM elements draggable (including touch support). + * Used internally for map and marker dragging. Only works for elements + * that were positioned with [`L.DomUtil.setPosition`](#domutil-setposition). + */ +export class Draggable extends Evented { + constructor(element: HTMLElement, dragStartTarget?: HTMLElement, preventOutline?: boolean); + + enable(): void; + + disable(): void; + + finishDrag(): void; +} + +interface LayerOptions { + pane?: string; +} + +interface InteractiveLayerOptions extends LayerOptions { + interactive?: boolean; +} + +export class Layer extends Evented { + constructor(options?: LayerOptions); + addTo(map: Map): this; + remove(): this; + removeFrom(map: Map): this; + getPane(name?: string): HTMLElement; + + // Popup methods + bindPopup(content: (layer: Layer) => Content | Content | Popup, options?: PopupOptions): this; + unbindPopup(): this; + openPopup(latlng?: LatLngExpression): this; + closePopup(): this; + togglePopup(): this; + isPopupOpen(): boolean; + setPopupContent(content: Content | Popup): this; + getPopup(): Popup; + + // Tooltip methods + bindTooltip(content: (layer: Layer) => Content | Tooltip | Content, options?: TooltipOptions): this; + unbindTooltip(): this; + openTooltip(latlng?: LatLngExpression): this; + closeTooltip(): this; + toggleTooltip(): this; + isTooltipOpen(): boolean; + setTooltipContent(content: Content | Tooltip): this; + getTooltip(): Tooltip; + + // Extension methods + onAdd(map: Map): this; + onRemove(map: Map): this; + getEvents(): {[name: string]: (event: Event) => void}; + getAttribution(): string; + beforeAdd(map: Map): this; +} + +export interface GridLayerOptions { + tileSize?: number | Point; + opacity?: number; + updateWhenIdle?: boolean; + updateWhenZooming?: boolean; + updateInterval?: number; + attribution?: string; + zIndex?: number; + bounds?: LatLngBoundsExpression; + minZoom?: number; + maxZoom?: number; + noWrap?: boolean; + pane?: string; + className?: string; + keepBuffer?: number; +} + +export class GridLayer extends Layer { + constructor(options?: GridLayerOptions); + bringToFront(): this; + bringToBack(): this; + getAttribution(): string; + getContainer(): HTMLElement; + setOpacity(opacity: number): this; + setZIndex(zIndex: number): this; + isLoading(): boolean; + redraw(): this; + getTileSize(): Point; +} + +export function gridLayer(options?: GridLayerOptions): GridLayer; + +export interface TileLayerOptions extends GridLayerOptions { + minZoom?: number; + maxZoom?: number; + maxNativeZoom?: number; + subdomains?: string | string[]; + errorTileUrl?: string; + zoomOffset?: number; + tms?: boolean; + zoomReverse?: boolean; + detectRetina?: boolean; + crossOrigin?: boolean; + [name: string]: any; +} + +export class TileLayer extends GridLayer { + constructor(urlTemplate: string, options?: TileLayerOptions); + setUrl(url: string, noRedraw?: boolean): this; + + options: TileLayerOptions; +} + +export function tileLayer(urlTemplate: string, options?: TileLayerOptions): TileLayer; + + +export namespace TileLayer { + export class WMS extends TileLayer { + constructor(baseUrl: string, options: WMSOptions); + setParams(params: WMSParams, noRedraw?: boolean): this; + + wmsParams: WMSParams; + options: WMSOptions; } +} + +export interface WMSOptions extends TileLayerOptions { + layers: string; + styles?: string; + format?: string; + transparent?: boolean; + version?: string; + crs?: CRS; + uppercase?: boolean; +} + +export interface WMSParams { + format?: string; + layers: string; + request?: string; + service?: string; + styles?: string; + version?: string; + transparent?: boolean; + width?: number; + height?: number; +} + +export namespace tileLayer { + export function wms(baseUrl: string, options?: WMSOptions): TileLayer.WMS; +} + +export interface ImageOverlayOptions extends LayerOptions { + opacity?: number; + alt?: string; + interactive?: boolean; + attribution?: string; + crossOrigin?: boolean; +} + +export class ImageOverlay extends Layer { + constructor(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions); + setOpacity(opacity: number): this; + bringToFront(): this; + bringToBack(): this; + setUrl(url: string): this; + + /** Update the bounds that this ImageOverlay covers */ + setBounds(bounds: LatLngBounds): this; + + /** Get the bounds that this ImageOverlay covers */ + getBounds(): LatLngBounds; + + /** Get the img element that represents the ImageOverlay on the map */ + getElement(): HTMLImageElement; + + options: ImageOverlayOptions; +} + +export function imageOverlay(imageUrl: string, bounds: LatLngBoundsExpression, options?: ImageOverlayOptions): ImageOverlay; + +export type LineCapShape = 'butt' | 'round' | 'square' | 'inherit'; + +export type LineJoinShape = 'miter' | 'round' | 'bevel' | 'inherit'; + +export type FillRule = 'nonzero' | 'evenodd' | 'inherit'; + +export interface PathOptions extends InteractiveLayerOptions { + stroke?: boolean; + color?: string; + weight?: number; + opacity?: number; + lineCap?: LineCapShape; + lineJoin?: LineJoinShape; + dashArray?: string; + dashOffset?: string; + fill?: boolean; + fillColor?: string; + fillOpacity?: number; + fillRule?: FillRule; + renderer?: Renderer; + className?: string; +} + +export abstract class Path extends Layer { + redraw(): this; + setStyle(style: PathOptions): this; + bringToFront(): this; + bringToBack(): this; + + options: PathOptions; +} + +export interface PolylineOptions extends PathOptions { + smoothFactor?: number; + noClip?: boolean; +} + +declare class InternalPolyline extends Path { + getLatLngs(): LatLng[]; + setLatLngs(latlngs: LatLngExpression[]): this; + isEmpty(): boolean; + getCenter(): LatLng; + getBounds(): LatLngBounds; + addLatLng(latlng: LatLngExpression | LatLngExpression[]): this; + + options: PolylineOptions; +} + +export class Polyline extends InternalPolyline { + constructor(latlngs: LatLngExpression[], options?: PolylineOptions); + toGeoJSON(): GeoJSONDefinition.Feature; + + feature: GeoJSONDefinition.Feature; +} + +export function polyline(latlngs: LatLngExpression[], options?: PolylineOptions): Polyline; + +export class Polygon extends InternalPolyline { + constructor(latlngs: LatLngExpression[], options?: PolylineOptions); + toGeoJSON(): GeoJSONDefinition.Feature; + + feature: GeoJSONDefinition.Feature; +} + +export function polygon(latlngs: LatLngExpression[], options?: PolylineOptions): Polygon; + +export class Rectangle extends Polygon { + constructor(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions); + setBounds(latLngBounds: LatLngBoundsExpression): this; +} + +export function rectangle(latLngBounds: LatLngBoundsExpression, options?: PolylineOptions): Rectangle; + +export interface CircleMarkerOptions extends PathOptions { + radius?: number; +} + +export class CircleMarker extends Path { + constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); + toGeoJSON(): GeoJSONDefinition.Feature; + setLatLng(latLng: LatLngExpression): this; + getLatLng(): LatLng; + setRadius(radius: number): this; + getRadius(): number; + + options: CircleMarkerOptions; + feature: GeoJSONDefinition.Feature; +} + +export function circleMarker(latlng: LatLngExpression, options?: CircleMarkerOptions): CircleMarker; + + +export class Circle extends CircleMarker { + constructor(latlng: LatLngExpression, options?: CircleMarkerOptions); + constructor(latlng: LatLngExpression, radius: number, options?: CircleMarkerOptions); // deprecated! + getBounds(): LatLngBounds; +} + +export function circle(latlng: LatLngExpression, options?: CircleMarkerOptions): Circle; +export function circle(latlng: LatLngExpression, radius: number, options?: CircleMarkerOptions): Circle; // deprecated! + +export interface RendererOptions extends LayerOptions { + padding?: number; +} + +export class Renderer extends Layer { + constructor(options?: RendererOptions); + + options: RendererOptions; +} + +export class SVG extends Renderer {} + +export namespace SVG { + export function create(name: string): SVGElement; + + export function pointsToPath(rings: PointExpression[], close: boolean): string; +} + +export function svg(options?: RendererOptions): SVG; + +export class Canvas extends Renderer {} + +export function canvas(options?: RendererOptions): Canvas; + +/** + * Used to group several layers and handle them as one. + * 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 { + constructor(layers: Layer[]); + /** + * Returns a GeoJSON representation of the layer group (as a GeoJSON GeometryCollection, GeoJSONDefinition.FeatureCollection or Multipoint). + */ + toGeoJSON(): GeoJSONDefinition.FeatureCollection | GeoJSONDefinition.Feature; /** - * Create a layer group, optionally given an initial set of layers. + * Adds the given layer to the group. */ - export function layerGroup(layers: Array): LayerGroup; + addLayer(layer: Layer): this; /** - * Extended LayerGroup that also has mouse events (propagated from - * members of the group) and a shared bindPopup method. + * Removes the layer with the given internal ID or the given layer from the group. */ - export interface FeatureGroup extends LayerGroup { - /** - * Sets the given path options to each layer of the group that has a setStyle method. - */ - setStyle(style: PathOptions): this; - - /** - * Brings the layer group to the top of all other layers - */ - bringToFront(): this; - - /** - * Brings the layer group to the top [sic] of all other layers - */ - bringToBack(): this; - - /** - * Returns the LatLngBounds of the Feature Group (created from - * bounds and coordinates of its children). - */ - getBounds(): LatLngBounds; - } + removeLayer(layer: number | Layer): this; /** - * Create a feature group, optionally given an initial set of layers. + * Returns true if the given layer is currently added to the group. */ - export function featureGroup(layers?: Array): FeatureGroup; + hasLayer(layer: Layer): boolean; - type StyleFunction = (feature: GeoJSON.Feature) => PathOptions; + /** + * Removes all the layers from the group. + */ + clearLayers(): this; - 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 - * feature and its LatLng. - * - * The default is to spawn a default Marker: - * - * ``` - * function(geoJsonPoint, latlng) { + /** + * Calls methodName on every layer contained in this group, passing any additional parameters. + * Has no effect if the layers contained do not implement methodName. + */ + invoke(methodName: string, ...params: any[]): this; + + /** + * Iterates over the layers of the group, + * optionally specifying context of the iterator function. + */ + eachLayer(fn: (layer: Layer) => void, context?: any): this; + + /** + * Returns the layer with the given internal ID. + */ + getLayer(id: number): Layer; + + /** + * Returns an array of all the layers added to the group. + */ + getLayers(): Layer[]; + + /** + * Calls setZIndex on every layer contained in this group, passing the z-index. + */ + setZIndex(zIndex: number): this; + + /** + * Returns the internal ID for a layer + */ + getLayerId(layer: Layer): number; + + feature: GeoJSONDefinition.FeatureCollection | GeoJSONDefinition.Feature; +} + +/** + * Create a layer group, optionally given an initial set of layers. + */ +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 { + /** + * Sets the given path options to each layer of the group that has a setStyle method. + */ + setStyle(style: PathOptions): this; + + /** + * Brings the layer group to the top of all other layers + */ + bringToFront(): this; + + /** + * Brings the layer group to the top [sic] of all other layers + */ + bringToBack(): this; + + /** + * Returns the LatLngBounds of the Feature Group (created from + * bounds and coordinates of its children). + */ + getBounds(): LatLngBounds; +} + +/** + * Create a feature group, optionally given an initial set of layers. + */ +export function featureGroup(layers?: Layer[]): FeatureGroup; + +type StyleFunction = (feature: GeoJSONDefinition.Feature) => PathOptions; + +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 + * feature and its LatLng. + * + * The default is to spawn a default Marker: + * + * ``` + * function(geoJsonPoint, latlng) { * return L.marker(latlng); * } - * ``` - */ - pointToLayer?: (geoJsonPoint: GeoJSON.Feature, latlng: LatLng) => Layer; // should import GeoJSON typings + * ``` + */ + pointToLayer?: (geoJsonPoint: GeoJSONDefinition.Feature, latlng: LatLng) => Layer; // should import GeoJSON typings - /** - * A Function defining the Path options for styling GeoJSON lines and polygons, - * called internally when data is added. - * - * The default value is to not override any defaults: - * - * ``` - * function (geoJsonFeature) { + /** + * A Function defining the Path options for styling GeoJSON lines and polygons, + * called internally when data is added. + * + * The default value is to not override any defaults: + * + * ``` + * function (geoJsonFeature) { * return {} * } - * ``` - */ - style?: StyleFunction; + * ``` + */ + style?: StyleFunction; - /** - * A Function that will be called once for each created Feature, after it - * has been created and styled. Useful for attaching events and popups to features. - * - * The default is to do nothing with the newly created layers: - * - * ``` - * function (feature, layer) {} - * ``` - */ - onEachFeature?: (feature: GeoJSON.Feature, layer: Layer) => void; + /** + * A Function that will be called once for each created Feature, after it + * has been created and styled. Useful for attaching events and popups to features. + * + * The default is to do nothing with the newly created layers: + * + * ``` + * function (feature, layer) {} + * ``` + */ + onEachFeature?: (feature: GeoJSONDefinition.Feature, layer: Layer) => void; - /** - * A Function that will be used to decide whether to show a feature or not. - * - * The default is to show all features: - * - * ``` - * function (geoJsonFeature) { + /** + * A Function that will be used to decide whether to show a feature or not. + * + * The default is to show all features: + * + * ``` + * function (geoJsonFeature) { * return true; * } - * ``` - */ - filter?: (geoJsonFeature: GeoJSON.Feature) => boolean; - - /** - * A Function that will be used for converting GeoJSON coordinates to LatLngs. - * The default is the coordsToLatLng static method. - */ - 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, number, number]; // A three tuple can be assigned to a two or three tuple - - - /** - * 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; - - } + * ``` + */ + filter?: (geoJsonFeature: GeoJSONDefinition.Feature) => boolean; /** - * Represents a GeoJSON object or an array of GeoJSON objects. - * Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup. + * A Function that will be used for converting GeoJSON coordinates to LatLngs. + * The default is the coordsToLatLng static method. */ - export interface GeoJSON extends FeatureGroup { - /** - * Adds a GeoJSON object to the layer. - */ - addData(data: GeoJSON.GeoJsonObject): Layer; + coordsToLatLng?: (coords: [number, number] | [number, number, number]) => LatLng; // check if LatLng has an altitude property +} - /** - * Resets the given vector layer's style to the original GeoJSON style, - * useful for resetting style after hover events. - */ - resetStyle(layer: Layer): Layer; - - /** - * Changes styles of GeoJSON vector layers with the given style function. - */ - setStyle(style: StyleFunction): this; - - } +/** + * 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 { + /** + * Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer + * and/or coordsToLatLng functions if provided as options. + */ + static geometryToLayer(featureData: GeoJSONDefinition.Feature, options?: GeoJSONOptions): Layer; /** - * Creates a GeoJSON layer. - * - * Optionally accepts an object in GeoJSON format to display on the - * map (you can alternatively add it later with addData method) and - * an options object. + * Creates a LatLng object from an array of 2 numbers (longitude, latitude) or + * 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. */ - export function geoJSON(geojson?: GeoJSON.GeoJsonObject, options?: GeoJSONOptions): GeoJSON; + static coordsToLatLng(coords: [number, number] | [number, number, number]): LatLng; - type Zoom = boolean | 'center'; + /** + * 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 - export interface MapOptions { - preferCanvas?: boolean; + /** + * Reverse of coordsToLatLng + */ + static latLngToCoords(latlng: LatLng): [number, number, number]; // A three tuple can be assigned to a two or three tuple - // Control options - attributionControl?: boolean; - zoomControl?: boolean; - // Interaction options - closePopupOnClick?: boolean; - zoomSnap?: number; - zoomDelta?: number; - trackResize?: boolean; - boxZoom?: boolean; - doubleClickZoom?: Zoom; - dragging?: boolean; + /** + * 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 - // Map state options - crs?: CRS; - center?: LatLngExpression; - zoom?: number; - minZoom?: number; - maxZoom?: number; - layers?: Array; - maxBounds?: LatLngBoundsExpression; - renderer?: Renderer; + /** + * Normalize GeoJSON geometries/features into GeoJSON features. + */ + static asFeature(geojson: GeoJSONDefinition.Feature | GeoJSONDefinition.GeometryObject): GeoJSONDefinition.Feature; - // Animation options - fadeAnimation?: boolean; - markerZoomAnimation?: boolean; - transform3DLimit?: number; - zoomAnimation?: boolean; - zoomAnimationThreshold?: number; + constructor(geojson?: GeoJSONDefinition.GeoJsonObject, options?: GeoJSONOptions) + /** + * Adds a GeoJSON object to the layer. + */ + addData(data: GeoJSONDefinition.GeoJsonObject): Layer; - // Panning inertia options - inertia?: boolean; - inertiaDeceleration?: number; - inertiaMaxSpeed?: number; - easeLinearity?: number; - worldCopyJump?: boolean; - maxBoundsViscosity?: number; + /** + * Resets the given vector layer's style to the original GeoJSON style, + * useful for resetting style after hover events. + */ + resetStyle(layer: Layer): Layer; - // Keyboard navigation options - keyboard?: boolean; - keyboardPanDelta?: number; + /** + * Changes styles of GeoJSON vector layers with the given style function. + */ + setStyle(style: StyleFunction): this; - // Mousewheel options - scrollWheelZoom?: Zoom; - wheelDebounceTime?: number; - wheelPxPerZoomLevel?: number; + options: GeoJSONOptions; - // Touch interaction options - tap?: boolean; - tapTolerance?: number; - touchZoom?: Zoom; - bounceAtZoomLimits?: boolean; +} + +/** + * Creates a GeoJSON layer. + * + * Optionally accepts an object in GeoJSON format to display on the + * map (you can alternatively add it later with addData method) and + * an options object. + */ +export function geoJSON(geojson?: GeoJSONDefinition.GeoJsonObject, options?: GeoJSONOptions): GeoJSON; + +type Zoom = boolean | 'center'; + +export interface MapOptions { + preferCanvas?: boolean; + + // Control options + attributionControl?: boolean; + zoomControl?: boolean; + + // Interaction options + closePopupOnClick?: boolean; + zoomSnap?: number; + zoomDelta?: number; + trackResize?: boolean; + boxZoom?: boolean; + doubleClickZoom?: Zoom; + dragging?: boolean; + + // Map state options + crs?: CRS; + center?: LatLngExpression; + zoom?: number; + minZoom?: number; + maxZoom?: number; + layers?: Layer[]; + maxBounds?: LatLngBoundsExpression; + renderer?: Renderer; + + // Animation options + fadeAnimation?: boolean; + markerZoomAnimation?: boolean; + transform3DLimit?: number; + zoomAnimation?: boolean; + zoomAnimationThreshold?: number; + + // Panning inertia options + inertia?: boolean; + inertiaDeceleration?: number; + inertiaMaxSpeed?: number; + easeLinearity?: number; + worldCopyJump?: boolean; + maxBoundsViscosity?: number; + + // Keyboard navigation options + keyboard?: boolean; + keyboardPanDelta?: number; + + // Mousewheel options + scrollWheelZoom?: Zoom; + wheelDebounceTime?: number; + wheelPxPerZoomLevel?: number; + + // Touch interaction options + tap?: boolean; + tapTolerance?: number; + touchZoom?: Zoom; + bounceAtZoomLimits?: boolean; +} + +export type ControlPosition = 'topleft' | 'topright' | 'bottomleft' | 'bottomright'; + +export interface ControlOptions { + position?: ControlPosition; +} + +export class Control extends Class { + constructor(options?: ControlOptions); + getPosition(): ControlPosition; + setPosition(position: ControlPosition): this; + getContainer(): HTMLElement; + addTo(map: Map): this; + remove(): this; + + // Extension methods + onAdd(map: Map): HTMLElement; + onRemove(map: Map): void; + + options: ControlOptions; +} + +export namespace Control { + export interface ZoomOptions extends ControlOptions { + zoomInText?: string; + zoomInTitle?: string; + zoomOutText?: string; + zoomOutTitle?: string; } - export type ControlPosition = 'topleft' | 'topright' | 'bottomleft' | 'bottomright'; - - export interface ControlOptions { - position?: ControlPosition; + export class Zoom extends Control { + constructor(options?: ZoomOptions); + options: ZoomOptions; } - export class Control extends Class { - constructor (options?: ControlOptions); - getPosition(): ControlPosition; - setPosition(position: ControlPosition): this; - getContainer(): HTMLElement; - addTo(map: Map): this; - remove(): this; - - // Extension methods - onAdd(map: Map): HTMLElement; - onRemove(map: Map): void; + export interface AttributionOptions extends ControlOptions { + prefix?: string | boolean; } - export namespace Control { - export interface ZoomOptions extends ControlOptions { - zoomInText?: string; - zoomInTitle?: string; - zoomOutText?: string; - zoomOutTitle?: string; - } - - export interface Zoom extends Control {} - - export interface AttributionOptions extends ControlOptions { - prefix?: string | boolean; - } - - export interface Attribution extends Control { - setPrefix(prefix: string): this; - addAttribution(text: string): this; - removeAttribution(text: string): this; - } - - export interface LayersOptions extends ControlOptions { - collapsed?: boolean; - autoZIndex?: boolean; - hideSingleBase?: boolean; - } - - export interface Layers extends Control { - addBaseLayer(layer: Layer, name: string): this; - addOverlay(layer: Layer, name: string): this; - removeLayer(layer: Layer): this; - expand(): this; - collapse(): this; - } - - export interface ScaleOptions extends ControlOptions { - maxWidth?: number; - metric?: boolean; - imperial?: boolean; - updateWhenIdle?: boolean; - } - - export interface Scale extends Control {} + export class Attribution extends Control { + constructor(options?: AttributionOptions); + setPrefix(prefix: string): this; + addAttribution(text: string): this; + removeAttribution(text: string): this; + options: AttributionOptions; } - export namespace control { - export function zoom(options: Control.ZoomOptions): Control.Zoom; - - export function attribution(options: Control.AttributionOptions): Control.Attribution; - - type LayersObject = {[name: string]: Layer}; - - export function layers(baseLayers?: LayersObject, overlays?: LayersObject, options?: Control.LayersOptions): Control.Layers; - - export function scale(options?: Control.ScaleOptions): Control.Scale; + export interface LayersOptions extends ControlOptions { + collapsed?: boolean; + autoZIndex?: boolean; + hideSingleBase?: boolean; } - interface DivOverlayOptions { - offset?: PointExpression; - zoomAnimation?: boolean; - className?: string; - pane?: string; + interface LayersObject { + [name: string]: Layer; } - export interface PopupOptions extends DivOverlayOptions { - maxWidth?: number; - minWidth?: number; - maxHeight?: number; - autoPan?: boolean; - autoPanPaddingTopLeft?: PointExpression; - autoPanPaddingBottomRight?: PointExpression; - autoPanPadding?: PointExpression; - keepInView?: boolean; - closeButton?: boolean; - autoClose?: boolean; - closeOnClick?: boolean; - } - - type Content = string | HTMLElement; - - export interface Popup extends Layer { - getLatLng(): LatLng; - setLatLng(latlng: LatLngExpression): this; - getContent(): Content; - setContent(htmlContent: string): this; - setContent(htmlContent: HTMLElement): this; - setContent(htmlContent: (source: Layer) => Content): this; - getElement(): Content; - update(): void; - isOpen(): boolean; - bringToFront(): this; - bringToBack(): this; - openOn(map: Map): this; - } - - export function popup(options?: PopupOptions, source?: Layer): Popup; - - export type Direction = 'right' | 'left' | 'top' | 'bottom' | 'center' | 'auto'; - - export interface TooltipOptions extends DivOverlayOptions { - pane?: string; - offset?: PointExpression; - direction?: Direction; - permanent?: boolean; - sticky?: boolean; - interactive?: boolean; - opacity?: number; - } - - export interface Tooltip extends Layer {} - - export function tooltip(options?: TooltipOptions, source?: Layer): Tooltip; - - export interface ZoomOptions { - animate?: boolean; - } - - export interface PanOptions { - animate?: boolean; - duration?: number; - easeLinearity?: number; - noMoveStart?: boolean; - } - - export interface ZoomPanOptions extends ZoomOptions, PanOptions {} - - export interface FitBoundsOptions extends ZoomOptions, PanOptions { - paddingTopLeft?: PointExpression; - paddingBottomRight?: PointExpression; - padding?: PointExpression; - maxZoom?: number; - } - - export interface LocateOptions { - watch?: boolean; - setView?: boolean; - maxZoom?: number; - timeout?: number; - maximumAge?: number; - enableHighAccuracy?: boolean; - } - - export interface Handler { - enable(): this; - disable(): this; - enabled(): boolean; - - // Extension methods - addHooks(): void; - removeHooks(): void; - } - - export interface Event { - type: string; - target: any; - } - - export interface MouseEvent extends Event { - latlng: LatLng; - layerPoint: Point; - containerPoint: Point; - originalEvent: NativeMouseEvent; - } - - export interface KeyboardEvent extends Event { - originalEvent: NativeKeyboardEvent; - } - - export interface LocationEvent extends Event { - latlng: LatLng; - bounds: LatLngBounds; - accuracy: number; - altitude: number; - altitudeAccuracy: number; - heading: number; - speed: number; - timestamp: number; - } - - export interface ErrorEvent extends Event { - message: string; - code: number; - } - - export interface LayerEvent extends Event { - layer: Layer; - } - - export interface LayersControlEvent extends LayerEvent { - name: string; - } - - export interface TileEvent extends Event { - tile: HTMLImageElement; - coords: Point; // apparently not a normal point, since docs say it has z (zoom) - } - - export interface TileErrorEvent extends TileEvent { - error: Error; - } - - export interface ResizeEvent extends Event { - oldSize: Point; - newSize: Point; - } - - export interface GeoJSONEvent extends Event { - layer: Layer; - properties: any; - geometryType: string; - id: string; - } - - export interface PopupEvent extends Event { - popup: Popup; - } - - export interface TooltipEvent extends Event { - tooltip: Tooltip; - } - - export interface DragEndEvent extends Event { - distance: number; - } - - export interface ZoomAnimEvent extends Event { - center: LatLng; - zoom: number; - noUpdate: boolean; - } - - export namespace DomEvent { - export function on(el: HTMLElement, types: string, fn: (ev: Event) => any, context?: any): typeof DomEvent; - - export function on(el: HTMLElement, eventMap: {[eventName: string]: Function}, context?: any): typeof DomEvent; - - export function off(el: HTMLElement, types: string, fn: (ev: Event) => any, context?: any): typeof DomEvent; - - export function off(el: HTMLElement, eventMap: {[eventName: string]: Function}, context?: any): typeof DomEvent; - - export function stopPropagation(ev: Event): typeof DomEvent; - - export function disableScrollPropagation(el: HTMLElement): typeof DomEvent; - - export function disableClickPropagation(el: HTMLElement): typeof DomEvent; - - export function preventDefault(ev: Event): typeof DomEvent; - - export function stop(ev: Event): typeof DomEvent; - - export function getMousePosition(ev: Event, container?: HTMLElement): Point; - - export function getWheelDelta(ev: Event): number; - - export function addListener(el: HTMLElement, types: string, fn: (ev: Event) => any, context?: any): typeof DomEvent; - - export function addListener(el: HTMLElement, eventMap: {[eventName: string]: Function}, context?: any): typeof DomEvent; - - export function removeListener(el: HTMLElement, types: string, fn: (ev: Event) => any, context?: any): typeof DomEvent; - - export function removeListener(el: HTMLElement, eventMap: {[eventName: string]: Function}, context?: any): typeof DomEvent; - } - - interface DefaultMapPanes { - mapPane: HTMLElement; - tilePane: HTMLElement; - overlayPane: HTMLElement; - shadowPane: HTMLElement; - markerPane: HTMLElement; - tooltipPane: HTMLElement; - popupPane: HTMLElement; - } - - export interface Map extends Evented { - getRenderer(layer: Path): Renderer; - - // Methods for layers and controls - addControl(control: Control): this; - removeControl(control: Control): this; - addLayer(layer: Layer): this; + export class Layers extends Control { + constructor(baseLayers?: LayersObject, overlays?: LayersObject, options?: Control.LayersOptions); + addBaseLayer(layer: Layer, name: string): this; + addOverlay(layer: Layer, name: string): this; removeLayer(layer: Layer): this; - hasLayer(layer: Layer): boolean; - eachLayer(fn: (layer: Layer) => void, context?: any): this; - openPopup(popup: Popup): this; - openPopup(content: string, latlng: LatLngExpression, options?: PopupOptions): this; - openPopup(content: HTMLElement, latlng: LatLngExpression, options?: PopupOptions): this; - closePopup(popup?: Popup): this; - openTooltip(tooltip: Tooltip): this; - openTooltip(content: string, latlng: LatLngExpression, options?: TooltipOptions): this; - openTooltip(content: HTMLElement, latlng: LatLngExpression, options?: TooltipOptions): this; - closeTooltip(tooltip?: Tooltip): this; - - // Methods for modifying map state - setView(center: LatLngExpression, zoom: number, options?: ZoomPanOptions): this; - setZoom(zoom: number, options?: ZoomPanOptions): this; - zoomIn(delta?: number, options?: ZoomOptions): this; - zoomOut(delta?: number, options?: ZoomOptions): this; - setZoomAround(latlng: LatLngExpression, zoom: number, options?: ZoomOptions): this; - setZoomAround(offset: Point, zoom: number, options?: ZoomOptions): this; - fitBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions): this; - fitWorld(options?: FitBoundsOptions): this; - panTo(latlng: LatLngExpression, options?: PanOptions): this; - panBy(offset: PointExpression): this; - setMaxBounds(bounds: LatLngBoundsExpression): this; - setMinZoom(zoom: number): this; - setMaxZoom(zoom: number): this; - panInsideBounds(bounds: LatLngBoundsExpression, options?: PanOptions): this; - invalidateSize(options: ZoomPanOptions): this; - invalidateSize(animate: boolean): this; - stop(): this; - flyTo(latlng: LatLngExpression, zoom?: number, options?: ZoomPanOptions): this; - flyToBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions): this; - - // Other methods - addHandler(name: string, HandlerClass: () => Handler): this; // HandlerClass is actually a constructor function, is this the right way? - remove(): this; - createPane(name: string, container?: HTMLElement): HTMLElement; - getPane(pane: string): HTMLElement; - getPane(pane: HTMLElement): HTMLElement; - getPanes(): {[name: string]: HTMLElement} & DefaultMapPanes; - getContainer(): HTMLElement; - whenReady(fn: () => void, context?: any): this; - - // Methods for getting map state - getCenter(): LatLng; - getZoom(): number; - getBounds(): LatLngBounds; - getMinZoom(): number; - getMaxZoom(): number; - getBoundsZoom(bounds: LatLngBoundsExpression, inside?: boolean): number; - getSize(): Point; - getPixelBounds(): Bounds; - getPixelOrigin(): Point; - getPixelWorldBounds(zoom?: number): Bounds; - - // Conversion methods - getZoomScale(toZoom: number, fromZoom: number): number; - getScaleZoom(scale: number, fromZoom: number): number; - project(latlng: LatLngExpression, zoom: number): Point; - unproject(point: PointExpression, zoom: number): LatLng; - layerPointToLatLng(point: PointExpression): LatLng; - latLngToLayerPoint(latlng: LatLngExpression): Point; - wrapLatLng(latlng: LatLngExpression): LatLng; - distance(latlng1: LatLngExpression, latlng2: LatLngExpression): number; - containerPointToLayerPoint(point: PointExpression): Point; - layerPointToContainerPoint(point: PointExpression): Point; - layerPointToContainerPoint(point: PointTuple): Point; - latLngToContainerPoint(latlng: LatLngExpression): Point; - mouseEventToContainerPoint(ev: MouseEvent): Point; - mouseEventToLayerPoint(ev: MouseEvent): Point; - mouseEventToLatLng(ev: MouseEvent): LatLng; - - // Geolocation methods - locate(options?: LocateOptions): this; - stopLocate(): this; - - // Properties - boxZoom: Handler; - doubleClickZoom: Handler; - dragging: Handler; - keyboard: Handler; - scrollWheelZoom: Handler; - tap: Handler; - touchZoom: Handler; + expand(): this; + collapse(): this; + options: LayersOptions; } - export function map(id: string, options?: MapOptions): Map; - - export function map(el: HTMLElement, options?: MapOptions): Map; - - export interface IconOptions extends LayerOptions { - iconUrl: string; - iconRetinaUrl?: string; - iconSize?: PointExpression; - iconAnchor?: PointExpression; - popupAnchor?: PointExpression; - shadowUrl?: string; - shadowRetinaUrl?: string; - shadowSize?: PointExpression; - shadowAnchor?: PointExpression; - className?: string; + export interface ScaleOptions extends ControlOptions { + maxWidth?: number; + metric?: boolean; + imperial?: boolean; + updateWhenIdle?: boolean; } - export interface Icon extends Layer { - createIcon(oldIcon?: HTMLElement): HTMLElement; - createShadow(oldIcon?: HTMLElement): HTMLElement; + export class Scale extends Control { + constructor(options?: Control.ScaleOptions); + options: ScaleOptions; } +} - export interface IconDefault extends Icon { +export namespace control { + export function zoom(options?: Control.ZoomOptions): Control.Zoom; + + export function attribution(options?: Control.AttributionOptions): Control.Attribution; + + export function layers(baseLayers?: Control.LayersObject, overlays?: Control.LayersObject, options?: Control.LayersOptions): Control.Layers; + + export function scale(options?: Control.ScaleOptions): Control.Scale; +} + +interface DivOverlayOptions { + offset?: PointExpression; + zoomAnimation?: boolean; + className?: string; + pane?: string; +} + +export interface PopupOptions extends DivOverlayOptions { + maxWidth?: number; + minWidth?: number; + maxHeight?: number; + autoPan?: boolean; + autoPanPaddingTopLeft?: PointExpression; + autoPanPaddingBottomRight?: PointExpression; + autoPanPadding?: PointExpression; + keepInView?: boolean; + closeButton?: boolean; + autoClose?: boolean; + closeOnClick?: boolean; +} + +type Content = string | HTMLElement; + +export class Popup extends Layer { + constructor(options?: PopupOptions, source?: Layer); + getLatLng(): LatLng; + setLatLng(latlng: LatLngExpression): this; + getContent(): Content; + setContent(htmlContent: (source: Layer) => Content | Content): this; + getElement(): HTMLElement; + update(): void; + isOpen(): boolean; + bringToFront(): this; + bringToBack(): this; + openOn(map: Map): this; + + options: PopupOptions; +} + +export function popup(options?: PopupOptions, source?: Layer): Popup; + +export type Direction = 'right' | 'left' | 'top' | 'bottom' | 'center' | 'auto'; + +export interface TooltipOptions extends DivOverlayOptions { + pane?: string; + offset?: PointExpression; + direction?: Direction; + permanent?: boolean; + sticky?: boolean; + interactive?: boolean; + opacity?: number; +} + +export class Tooltip extends Layer { + constructor(options?: TooltipOptions, source?: Layer); + setOpacity(val: number): void; + getLatLng(): LatLng; + setLatLng(latlng: LatLngExpression): this; + getContent(): Content; + setContent(htmlContent: (source: Layer) => Content | Content): this; + getElement(): HTMLElement; + update(): void; + isOpen(): boolean; + bringToFront(): this; + bringToBack(): this; + + options: TooltipOptions; +} + +export function tooltip(options?: TooltipOptions, source?: Layer): Tooltip; + +export interface ZoomOptions { + animate?: boolean; +} + +export interface PanOptions { + animate?: boolean; + duration?: number; + easeLinearity?: number; + noMoveStart?: boolean; +} + +export interface ZoomPanOptions extends ZoomOptions, PanOptions {} + +export interface FitBoundsOptions extends ZoomOptions, PanOptions { + paddingTopLeft?: PointExpression; + paddingBottomRight?: PointExpression; + padding?: PointExpression; + maxZoom?: number; +} + +export interface LocateOptions { + watch?: boolean; + setView?: boolean; + maxZoom?: number; + timeout?: number; + maximumAge?: number; + enableHighAccuracy?: boolean; +} + +export class Handler extends Class { + constructor(map: Map); + enable(): this; + disable(): this; + enabled(): boolean; + + // Extension methods + addHooks(): void; + removeHooks(): void; +} + +export interface Event { + type: string; + target: any; +} + +export interface MouseEvent extends Event { + latlng: LatLng; + layerPoint: Point; + containerPoint: Point; + originalEvent: NativeMouseEvent; +} + +export interface KeyboardEvent extends Event { + originalEvent: NativeKeyboardEvent; +} + +export interface LocationEvent extends Event { + latlng: LatLng; + bounds: LatLngBounds; + accuracy: number; + altitude: number; + altitudeAccuracy: number; + heading: number; + speed: number; + timestamp: number; +} + +export interface ErrorEvent extends Event { + message: string; + code: number; +} + +export interface LayerEvent extends Event { + layer: Layer; +} + +export interface LayersControlEvent extends LayerEvent { + name: string; +} + +export interface TileEvent extends Event { + tile: HTMLImageElement; + coords: Point; // apparently not a normal point, since docs say it has z (zoom) +} + +export interface TileErrorEvent extends TileEvent { + error: Error; +} + +export interface ResizeEvent extends Event { + oldSize: Point; + newSize: Point; +} + +export interface GeoJSONEvent extends Event { + layer: Layer; + properties: any; + geometryType: string; + id: string; +} + +export interface PopupEvent extends Event { + popup: Popup; +} + +export interface TooltipEvent extends Event { + tooltip: Tooltip; +} + +export interface DragEndEvent extends Event { + distance: number; +} + +export interface ZoomAnimEvent extends Event { + center: LatLng; + zoom: number; + noUpdate: boolean; +} + +export namespace DomEvent { + export function on(el: HTMLElement, types: string, fn: EventHandlerFn, context?: any): typeof DomEvent; + + export function on(el: HTMLElement, eventMap: {[eventName: string]: EventHandlerFn}, context?: any): typeof DomEvent; + + export function off(el: HTMLElement, types: string, fn: EventHandlerFn, context?: any): typeof DomEvent; + + export function off(el: HTMLElement, eventMap: {[eventName: string]: EventHandlerFn}, context?: any): typeof DomEvent; + + export function stopPropagation(ev: Event): typeof DomEvent; + + export function disableScrollPropagation(el: HTMLElement): typeof DomEvent; + + export function disableClickPropagation(el: HTMLElement): typeof DomEvent; + + export function preventDefault(ev: Event): typeof DomEvent; + + export function stop(ev: Event): typeof DomEvent; + + export function getMousePosition(ev: Event, container?: HTMLElement): Point; + + export function getWheelDelta(ev: Event): number; + + export function addListener(el: HTMLElement, types: string, fn: EventHandlerFn, context?: any): typeof DomEvent; + + export function addListener(el: HTMLElement, eventMap: {[eventName: string]: EventHandlerFn}, context?: any): typeof DomEvent; + + export function removeListener(el: HTMLElement, types: string, fn: EventHandlerFn, context?: any): typeof DomEvent; + + export function removeListener(el: HTMLElement, eventMap: {[eventName: string]: EventHandlerFn}, context?: any): typeof DomEvent; +} + +interface DefaultMapPanes { + mapPane: HTMLElement; + tilePane: HTMLElement; + overlayPane: HTMLElement; + shadowPane: HTMLElement; + markerPane: HTMLElement; + tooltipPane: HTMLElement; + popupPane: HTMLElement; +} + +export class Map extends Evented { + constructor(element: string | HTMLElement, options?: MapOptions); + getRenderer(layer: Path): Renderer; + + // Methods for layers and controls + addControl(control: Control): this; + removeControl(control: Control): this; + addLayer(layer: Layer): this; + removeLayer(layer: Layer): this; + hasLayer(layer: Layer): boolean; + eachLayer(fn: (layer: Layer) => void, context?: any): this; + openPopup(popup: Popup): this; + openPopup(content: Content, latlng: LatLngExpression, options?: PopupOptions): this; + closePopup(popup?: Popup): this; + openTooltip(tooltip: Tooltip): this; + openTooltip(content: string | HTMLElement, latlng: LatLngExpression, options?: TooltipOptions): this; + closeTooltip(tooltip?: Tooltip): this; + + // Methods for modifying map state + setView(center: LatLngExpression, zoom: number, options?: ZoomPanOptions): this; + setZoom(zoom: number, options?: ZoomPanOptions): this; + zoomIn(delta?: number, options?: ZoomOptions): this; + zoomOut(delta?: number, options?: ZoomOptions): this; + setZoomAround(position: Point | LatLngExpression, zoom: number, options?: ZoomOptions): this; + fitBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions): this; + fitWorld(options?: FitBoundsOptions): this; + panTo(latlng: LatLngExpression, options?: PanOptions): this; + panBy(offset: PointExpression): this; + setMaxBounds(bounds: LatLngBoundsExpression): this; + setMinZoom(zoom: number): this; + setMaxZoom(zoom: number): this; + panInsideBounds(bounds: LatLngBoundsExpression, options?: PanOptions): this; + /** + * Boolean for animate or advanced ZoomPanOptions + */ + invalidateSize(options?: boolean | ZoomPanOptions): this; + stop(): this; + flyTo(latlng: LatLngExpression, zoom?: number, options?: ZoomPanOptions): this; + flyToBounds(bounds: LatLngBoundsExpression, options?: FitBoundsOptions): this; + + // Other methods + addHandler(name: string, HandlerClass: () => Handler): this; // HandlerClass is actually a constructor function, is this the right way? + remove(): this; + createPane(name: string, container?: HTMLElement): HTMLElement; + /** + * Name of the pane or the pane as HTML-Element + */ + getPane(pane: string | HTMLElement): HTMLElement; + getPanes(): {[name: string]: HTMLElement} & DefaultMapPanes; + getContainer(): HTMLElement; + whenReady(fn: () => void, context?: any): this; + + // Methods for getting map state + getCenter(): LatLng; + getZoom(): number; + getBounds(): LatLngBounds; + getMinZoom(): number; + getMaxZoom(): number; + getBoundsZoom(bounds: LatLngBoundsExpression, inside?: boolean): number; + getSize(): Point; + getPixelBounds(): Bounds; + getPixelOrigin(): Point; + getPixelWorldBounds(zoom?: number): Bounds; + + // Conversion methods + getZoomScale(toZoom: number, fromZoom: number): number; + getScaleZoom(scale: number, fromZoom: number): number; + project(latlng: LatLngExpression, zoom: number): Point; + unproject(point: PointExpression, zoom: number): LatLng; + layerPointToLatLng(point: PointExpression): LatLng; + latLngToLayerPoint(latlng: LatLngExpression): Point; + wrapLatLng(latlng: LatLngExpression): LatLng; + distance(latlng1: LatLngExpression, latlng2: LatLngExpression): number; + containerPointToLayerPoint(point: PointExpression): Point; + layerPointToContainerPoint(point: PointExpression): Point; + latLngToContainerPoint(latlng: LatLngExpression): Point; + mouseEventToContainerPoint(ev: MouseEvent): Point; + mouseEventToLayerPoint(ev: MouseEvent): Point; + mouseEventToLatLng(ev: MouseEvent): LatLng; + + // Geolocation methods + locate(options?: LocateOptions): this; + stopLocate(): this; + + // Properties + boxZoom: Handler; + doubleClickZoom: Handler; + dragging: Handler; + keyboard: Handler; + scrollWheelZoom: Handler; + tap: Handler; + touchZoom: Handler; + + options: MapOptions; +} + +/** + * ID of a HTML-Element as string or the HTML-ELement itself + */ +export function map(element: string | HTMLElement, options?: MapOptions): Map; + +export interface IconOptions extends LayerOptions { + iconUrl: string; + iconRetinaUrl?: string; + iconSize?: PointExpression; + iconAnchor?: PointExpression; + popupAnchor?: PointExpression; + shadowUrl?: string; + shadowRetinaUrl?: string; + shadowSize?: PointExpression; + shadowAnchor?: PointExpression; + className?: string; +} + +declare class InternalIcon extends Layer { + constructor(options: IconOptions); + createIcon(oldIcon?: HTMLElement): HTMLElement; +} + +export class Icon extends InternalIcon { + createShadow(oldIcon?: HTMLElement): HTMLElement; + options: IconOptions; +} + +export interface IconDefault extends InternalIcon { + imagePath: string; +} + +export namespace Icon { + export class Default extends InternalIcon { imagePath: string; } - - export class Icon { - constructor(options: IconOptions); - } - - export namespace Icon { - export class Default extends Icon { - constructor(options?: IconOptions); - imagePath: string; - } - } - - export function icon(options: IconOptions): Icon; - - export interface DivIconOptions extends LayerOptions { - html?: string; - bgPos?: PointExpression; - iconSize?: PointExpression; - iconAnchor?: PointExpression; - popupAnchor?: PointExpression; - className?: string; - } - - export class DivIcon extends Icon { - constructor(options?: DivIconOptions); - } - - export function divIcon(options?: DivIconOptions): DivIcon; - - export interface MarkerOptions extends InteractiveLayerOptions { - icon?: Icon; - clickable?: boolean; - draggable?: boolean; - keyboard?: boolean; - title?: string; - alt?: string; - zIndexOffset?: number; - opacity?: number; - riseOnHover?: boolean; - riseOffset?: number; - } - - export class Marker extends Layer { - constructor(latlng: LatLngExpression, options?: MarkerOptions); - getLatLng(): LatLng; - setLatLng(latlng: LatLngExpression): this; - setZIndexOffset(offset: number): this; - setIcon(icon: Icon): this; - setOpacity(opacity: number): this; - getElement(): Element; - - // Properties - dragging: Handler; - } - - export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; - - export namespace Browser { - export const ie: boolean; - export const ielt9: boolean; - export const edge: boolean; - export const webkit: boolean; - export const gecko: boolean; - export const android: boolean; - export const android23: boolean; - export const chrome: boolean; - export const safari: boolean; - export const win: boolean; - export const ie3d: boolean; - export const webkit3d: boolean; - export const gecko3d: boolean; - export const opera12: boolean; - export const any3d: boolean; - export const mobile: boolean; - export const mobileWebkit: boolean; - export const mobiWebkit3d: boolean; - export const mobileOpera: boolean; - export const mobileGecko: boolean; - export const touch: boolean; - export const msPointer: boolean; - export const pointer: boolean; - export const retina: boolean; - export const canvas: boolean; - export const vml: boolean; - export const svg: boolean; - } } -declare module 'leaflet' { - export = L; +export function icon(options: IconOptions): Icon; + +export interface DivIconOptions extends LayerOptions { + html?: string; + bgPos?: PointExpression; + iconSize?: PointExpression; + iconAnchor?: PointExpression; + popupAnchor?: PointExpression; + className?: string; +} + +export class DivIcon extends InternalIcon { + constructor(options?: DivIconOptions); + options: DivIconOptions; +} + +export function divIcon(options?: DivIconOptions): DivIcon; + +export interface MarkerOptions extends InteractiveLayerOptions { + icon?: Icon; + clickable?: boolean; + draggable?: boolean; + keyboard?: boolean; + title?: string; + alt?: string; + zIndexOffset?: number; + opacity?: number; + riseOnHover?: boolean; + riseOffset?: number; + + options: DivIconOptions; +} + +export class Marker extends Layer { + constructor(latlng: LatLngExpression, options?: MarkerOptions); + getLatLng(): LatLng; + setLatLng(latlng: LatLngExpression): this; + setZIndexOffset(offset: number): this; + setIcon(icon: Icon): this; + setOpacity(opacity: number): this; + getElement(): HTMLElement; + + // Properties + options: MarkerOptions; + dragging: Handler; +} + +export function marker(latlng: LatLngExpression, options?: MarkerOptions): Marker; + +export namespace Browser { + export const ie: boolean; + export const ielt9: boolean; + export const edge: boolean; + export const webkit: boolean; + export const gecko: boolean; + export const android: boolean; + export const android23: boolean; + export const chrome: boolean; + export const safari: boolean; + export const win: boolean; + export const ie3d: boolean; + export const webkit3d: boolean; + export const gecko3d: boolean; + export const opera12: boolean; + export const any3d: boolean; + export const mobile: boolean; + export const mobileWebkit: boolean; + export const mobiWebkit3d: boolean; + export const mobileOpera: boolean; + export const mobileGecko: boolean; + export const touch: boolean; + export const msPointer: boolean; + export const pointer: boolean; + export const retina: boolean; + export const canvas: boolean; + export const vml: boolean; + export const svg: boolean; } diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index c6dca97f5d..6f9fa242d8 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -11,6 +11,14 @@ latLng = L.latLng({lat: 12, lng: 13, alt: 0}); latLng = L.latLng(latLngTuple); latLng = L.latLng([12, 13, 0]); +latLng = new L.LatLng(12, 13); +latLng = new L.LatLng(12, 13, 0); +latLng = new L.LatLng(latLngLiteral); +latLng = new L.LatLng({lat: 12, lng: 13, alt: 0}); +latLng = new L.LatLng(latLngTuple); +latLng = new L.LatLng([12, 13, 0]); + + const latLngBoundsLiteral: L.LatLngBoundsLiteral = [[12, 13], latLngTuple]; let latLngBounds: L.LatLngBounds; @@ -18,6 +26,10 @@ latLngBounds = L.latLngBounds(latLng, latLng); latLngBounds = L.latLngBounds(latLngLiteral, latLngLiteral); latLngBounds = L.latLngBounds(latLngTuple, latLngTuple); +latLngBounds = new L.LatLngBounds(latLng, latLng); +latLngBounds = new L.LatLngBounds(latLngLiteral, latLngLiteral); +latLngBounds = new L.LatLngBounds(latLngTuple, latLngTuple); + const pointTuple: L.PointTuple = [0, 0]; let point: L.Point; @@ -26,6 +38,11 @@ point = L.point(12, 13, true); point = L.point(pointTuple); point = L.point({x: 12, y: 13}); +point = new L.Point(12, 13); +point = new L.Point(12, 13, true); +point = new L.Point(pointTuple); +point = new L.Point({x: 12, y: 13}); + let distance: number; point.distanceTo(point); point.distanceTo(pointTuple); @@ -44,6 +61,11 @@ bounds = L.bounds(pointTuple, pointTuple); bounds = L.bounds([point, point]); bounds = L.bounds(boundsLiteral); +bounds = new L.Bounds(point, point); +bounds = new L.Bounds(pointTuple, pointTuple); +bounds = new L.Bounds([point, point]); +bounds = new L.Bounds(boundsLiteral); + let points: Array; points = L.LineUtil.simplify([point, point], 1); points = L.LineUtil.simplify([pointTuple, pointTuple], 2); @@ -143,6 +165,10 @@ map = L.map('foo', mapOptions); map = L.map(htmlElement); map = L.map(htmlElement, mapOptions); +map = new L.Map('foo', mapOptions); +map = new L.Map(htmlElement); +map = new L.Map(htmlElement, mapOptions); + let doesItHaveLayer: boolean; doesItHaveLayer = map.hasLayer(L.tileLayer('')); @@ -230,6 +256,10 @@ tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'); tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', tileLayerOptions); tileLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png?{foo}&{bar}&{abc}', {foo: 'bar', bar: (data: any) => 'foo', abc: () => ''}); +tileLayer = new L.TileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'); +tileLayer = new L.TileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', tileLayerOptions); +tileLayer = new L.TileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png?{foo}&{bar}&{abc}', {foo: 'bar', bar: (data: any) => 'foo', abc: () => ''}); + let eventHandler = () => {}; let domEvent: Event = {} as Event; L.DomEvent diff --git a/leaflet/tslint.json b/leaflet/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/leaflet/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }