@types/leaflet
Version:
TypeScript definitions for leaflet
1,420 lines (1,308 loc) • 109 kB
TypeScript
export as namespace L;
import * as geojson from "geojson";
/** A constant that represents the Leaflet version in use. */
export const version: string;
export class Class {
static extend(props: any): { new(...args: any[]): any } & typeof Class;
static include(props: any): any & typeof Class;
static mergeOptions(props: any): any & typeof Class;
static addInitHook(initHookFn: () => void): any & typeof Class;
static addInitHook(methodName: string, ...args: any[]): any & typeof Class;
static callInitHooks(): void;
}
export class Transformation {
constructor(a: number, b: number, c: number, d: number);
transform(point: Point, scale?: number): Point;
untransform(point: Point, scale?: number): Point;
}
/** Instantiates a Transformation object with the given coefficients. */
export function transformation(a: number, b: number, c: number, d: number): Transformation;
/** Expects an coefficients array of the form `[a: Number, b: Number, c: Number, d: Number]`. */
export function transformation(coefficients: [number, number, number, number]): Transformation;
/**
* @see https://github.com/Leaflet/Leaflet/blob/bc918d4bdc2ba189807bc207c77080fb41ecc196/src/geometry/LineUtil.js#L118
*/
export namespace LineUtil {
function simplify(points: Point[], tolerance: number): Point[];
function pointToSegmentDistance(p: Point, p1: Point, p2: Point): number;
function closestPointOnSegment(p: Point, p1: Point, p2: Point): Point;
function isFlat(latlngs: LatLngExpression[]): boolean;
function clipSegment(
a: Point,
b: Point,
bounds: Bounds,
useLastCode?: boolean,
round?: boolean,
): [Point, Point] | false;
function polylineCenter(latlngs: LatLngExpression[], crs: CRS): LatLng;
}
export namespace PolyUtil {
function clipPolygon(points: Point[], bounds: BoundsExpression, round?: boolean): Point[];
function polygonCenter(latlngs: LatLngExpression[], crs: CRS): LatLng;
}
export namespace DomUtil {
/**
* Get Element by its ID or with the given HTML-Element
*/
function get(element: string | HTMLElement): HTMLElement | null;
function getStyle(el: HTMLElement, styleAttrib: string): string | null;
/**
* Creates an HTML element with `tagName`, sets its class to `className`, and optionally appends it to `container` element.
* @param tagName The name of the tag to create (for example: `div` or `canvas`).
* @param className The class to set on the created element.
* @param container The container to append the created element to.
*/
function create<T extends keyof HTMLElementTagNameMap>(
tagName: T,
className?: string,
container?: HTMLElement,
): HTMLElementTagNameMap[T];
function create(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
function remove(el: HTMLElement): void;
function empty(el: HTMLElement): void;
function toFront(el: HTMLElement): void;
function toBack(el: HTMLElement): void;
function hasClass(el: HTMLElement, name: string): boolean;
function addClass(el: HTMLElement, name: string): void;
function removeClass(el: HTMLElement, name: string): void;
function setClass(el: HTMLElement, name: string): void;
function getClass(el: HTMLElement): string;
function setOpacity(el: HTMLElement, opacity: number): void;
function testProp(props: string[]): string | false;
function setTransform(el: HTMLElement, offset: Point, scale?: number): void;
function setPosition(el: HTMLElement, position: Point): void;
function getPosition(el: HTMLElement): Point;
function getScale(el: HTMLElement): { x: number; y: number; boundingClientRect: DOMRect };
function getSizedParentNode(el: HTMLElement): HTMLElement;
function disableTextSelection(): void;
function enableTextSelection(): void;
function disableImageDrag(): void;
function enableImageDrag(): void;
function preventOutline(el: HTMLElement): void;
function restoreOutline(): void;
let TRANSFORM: string;
let TRANSITION: string;
let TRANSITION_END: string;
}
export class PosAnimation extends Evented {
run(el: HTMLElement, newPos: Point, duration?: number, easeLinearity?: number): void;
stop(): void;
}
export interface CRS {
latLngToPoint(latlng: LatLngExpression, zoom: number): Point;
pointToLatLng(point: PointExpression, zoom: number): LatLng;
project(latlng: LatLng | LatLngLiteral): 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: LatLng | LatLngLiteral): LatLng;
code?: string | undefined;
wrapLng?: [number, number] | undefined;
wrapLat?: [number, number] | undefined;
infinite: boolean;
}
export namespace CRS {
const EPSG3395: CRS;
const EPSG3857: CRS;
const EPSG4326: CRS;
const EPSG900913: CRS;
const Earth: CRS;
const Simple: CRS;
}
export interface Projection {
project(latlng: LatLng | LatLngLiteral): Point;
unproject(point: PointExpression): LatLng;
bounds: Bounds;
}
export namespace Projection {
const LonLat: Projection;
const Mercator: Projection;
const SphericalMercator: Projection;
}
export class LatLng {
constructor(latitude: number, longitude: number, altitude?: number);
equals(otherLatLng: LatLngExpression, maxMargin?: number): boolean;
toString(): string;
distanceTo(otherLatLng: LatLngExpression): number;
wrap(): LatLng;
toBounds(sizeInMeters: number): LatLngBounds;
clone(): LatLng;
lat: number;
lng: number;
alt?: number | undefined;
}
export interface LatLngLiteral {
lat: number;
lng: number;
alt?: number;
}
export type LatLngTuple = [number, number, number?];
export type LatLngExpression = LatLng | LatLngLiteral | LatLngTuple;
export function latLng(latitude: number, longitude: number, altitude?: number): LatLng;
export function latLng(
coords: LatLngTuple | [number, number, number] | LatLngLiteral | {
lat: number;
lng: number;
alt?: number | undefined;
},
): LatLng;
export class LatLngBounds {
constructor(southWest: LatLngExpression, northEast: LatLngExpression);
constructor(latlngs: LatLngExpression[]);
extend(latlngOrBounds: LatLngExpression | LatLngBoundsExpression): this;
pad(bufferRatio: number): LatLngBounds; // Returns a new LatLngBounds
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: LatLngBoundsExpression): boolean;
toBBoxString(): string;
equals(otherBounds: LatLngBoundsExpression, maxMargin?: number): boolean;
isValid(): boolean;
}
export type LatLngBoundsLiteral = LatLngTuple[]; // Must be [LatLngTuple, LatLngTuple], cant't change because Map.setMaxBounds
export type LatLngBoundsExpression = LatLngBounds | LatLngBoundsLiteral;
export function latLngBounds(southWest: LatLngExpression, northEast: LatLngExpression): LatLngBounds;
export function latLngBounds(latlngs: LatLngExpression[]): LatLngBounds;
export type PointTuple = [number, number];
export class Point {
constructor(x: number, y: number, round?: boolean);
clone(): Point;
add(otherPoint: PointExpression): Point; // non-destructive, returns a new point
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;
trunc(): Point;
distanceTo(otherPoint: PointExpression): number;
equals(otherPoint: PointExpression): boolean;
contains(otherPoint: PointExpression): boolean;
toString(): string;
x: number;
y: number;
}
export interface Coords extends Point {
z: number;
}
export type PointExpression = Point | PointTuple;
export function point(x: number, y: number, round?: boolean): Point;
export function point(coords: PointTuple | { x: number; y: number }): Point;
export type BoundsLiteral = [PointTuple, PointTuple];
export class Bounds {
constructor(topLeft: PointExpression, bottomRight: PointExpression);
constructor(points?: Point[] | BoundsLiteral);
// tslint:disable:unified-signatures
extend(point: PointExpression): this;
extend(otherBounds: BoundsExpression): this;
// tslint:enable:unified-signatures
getCenter(round?: boolean): Point;
getBottomLeft(): Point;
getBottomRight(): Point;
getTopLeft(): Point;
getTopRight(): Point;
getSize(): Point;
contains(pointOrBounds: BoundsExpression | PointExpression): boolean;
intersects(otherBounds: BoundsExpression): boolean;
overlaps(otherBounds: BoundsExpression): boolean;
isValid(): boolean;
pad(bufferRatio: number): Bounds; // Returns a new Bounds
equals(otherBounds: BoundsExpression): boolean;
min?: Point | undefined;
max?: Point | undefined;
}
export type BoundsExpression = Bounds | BoundsLiteral;
export function bounds(topLeft: PointExpression, bottomRight: PointExpression): Bounds;
export function bounds(points: Point[] | BoundsLiteral): Bounds;
// Event handler types
export type LeafletEventHandlerFn = (event: LeafletEvent) => void;
export type LayersControlEventHandlerFn = (event: LayersControlEvent) => void;
export type LayerEventHandlerFn = (event: LayerEvent) => void;
export type ResizeEventHandlerFn = (event: ResizeEvent) => void;
export type PopupEventHandlerFn = (event: PopupEvent) => void;
export type TooltipEventHandlerFn = (event: TooltipEvent) => void;
export type ErrorEventHandlerFn = (event: ErrorEvent) => void;
export type LocationEventHandlerFn = (event: LocationEvent) => void;
export type LeafletMouseEventHandlerFn = (event: LeafletMouseEvent) => void;
export type LeafletKeyboardEventHandlerFn = (event: LeafletKeyboardEvent) => void;
export type ZoomAnimEventHandlerFn = (event: ZoomAnimEvent) => void;
export type DragEndEventHandlerFn = (event: DragEndEvent) => void;
export type TileEventHandlerFn = (event: TileEvent) => void;
export type TileErrorEventHandlerFn = (event: TileErrorEvent) => void;
export interface LeafletEventHandlerFnMap {
baselayerchange?: LayersControlEventHandlerFn | undefined;
overlayadd?: LayersControlEventHandlerFn | undefined;
overlayremove?: LayersControlEventHandlerFn | undefined;
layeradd?: LayerEventHandlerFn | undefined;
layerremove?: LayerEventHandlerFn | undefined;
zoomlevelschange?: LeafletEventHandlerFn | undefined;
unload?: LeafletEventHandlerFn | undefined;
viewreset?: LeafletEventHandlerFn | undefined;
load?: LeafletEventHandlerFn | undefined;
zoomstart?: LeafletEventHandlerFn | undefined;
movestart?: LeafletEventHandlerFn | undefined;
zoom?: LeafletEventHandlerFn | undefined;
move?: LeafletEventHandlerFn | undefined;
zoomend?: LeafletEventHandlerFn | undefined;
moveend?: LeafletEventHandlerFn | undefined;
autopanstart?: LeafletEventHandlerFn | undefined;
dragstart?: LeafletEventHandlerFn | undefined;
drag?: LeafletEventHandlerFn | undefined;
add?: LeafletEventHandlerFn | undefined;
remove?: LeafletEventHandlerFn | undefined;
loading?: LeafletEventHandlerFn | undefined;
error?: LeafletEventHandlerFn | undefined;
update?: LeafletEventHandlerFn | undefined;
down?: LeafletEventHandlerFn | undefined;
predrag?: LeafletEventHandlerFn | undefined;
resize?: ResizeEventHandlerFn | undefined;
popupopen?: PopupEventHandlerFn | undefined;
popupclose?: PopupEventHandlerFn | undefined;
tooltipopen?: TooltipEventHandlerFn | undefined;
tooltipclose?: TooltipEventHandlerFn | undefined;
locationerror?: ErrorEventHandlerFn | undefined;
locationfound?: LocationEventHandlerFn | undefined;
click?: LeafletMouseEventHandlerFn | undefined;
dblclick?: LeafletMouseEventHandlerFn | undefined;
mousedown?: LeafletMouseEventHandlerFn | undefined;
mouseup?: LeafletMouseEventHandlerFn | undefined;
mouseover?: LeafletMouseEventHandlerFn | undefined;
mouseout?: LeafletMouseEventHandlerFn | undefined;
mousemove?: LeafletMouseEventHandlerFn | undefined;
contextmenu?: LeafletMouseEventHandlerFn | undefined;
preclick?: LeafletMouseEventHandlerFn | undefined;
keypress?: LeafletKeyboardEventHandlerFn | undefined;
keydown?: LeafletKeyboardEventHandlerFn | undefined;
keyup?: LeafletKeyboardEventHandlerFn | undefined;
zoomanim?: ZoomAnimEventHandlerFn | undefined;
dragend?: DragEndEventHandlerFn | undefined;
tileunload?: TileEventHandlerFn | undefined;
tileloadstart?: TileEventHandlerFn | undefined;
tileload?: TileEventHandlerFn | undefined;
tileabort?: TileEventHandlerFn | undefined;
tileerror?: TileErrorEventHandlerFn | undefined;
// [name: string]: any;
// You are able add additional properties, but it makes this interface uncheckable.
}
/**
* 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).
*/
// eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers
declare class Events {
/**
* 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').
*/
// tslint:disable:unified-signatures
on(type: "baselayerchange" | "overlayadd" | "overlayremove", fn: LayersControlEventHandlerFn, context?: any): this;
on(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
on(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
on(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
on(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
on(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
on(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
on(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
on(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
on(type: "keypress" | "keydown" | "keyup", fn: LeafletKeyboardEventHandlerFn, context?: any): this;
on(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
on(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
on(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn: TileEventHandlerFn, context?: any): this;
on(type: "tileerror", fn: TileErrorEventHandlerFn, context?: any): this;
on(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
*/
on(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
off(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn?: LayersControlEventHandlerFn,
context?: any,
): this;
off(type: "layeradd" | "layerremove", fn?: LayerEventHandlerFn, context?: any): this;
off(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn?: LeafletEventHandlerFn,
context?: any,
): this;
off(type: "resize", fn?: ResizeEventHandlerFn, context?: any): this;
off(type: "popupopen" | "popupclose", fn?: PopupEventHandlerFn, context?: any): this;
off(type: "tooltipopen" | "tooltipclose", fn?: TooltipEventHandlerFn, context?: any): this;
off(type: "locationerror", fn?: ErrorEventHandlerFn, context?: any): this;
off(type: "locationfound", fn?: LocationEventHandlerFn, context?: any): this;
off(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn?: LeafletMouseEventHandlerFn,
context?: any,
): this;
off(type: "keypress" | "keydown" | "keyup", fn?: LeafletKeyboardEventHandlerFn, context?: any): this;
off(type: "zoomanim", fn?: ZoomAnimEventHandlerFn, context?: any): this;
off(type: "dragend", fn?: DragEndEventHandlerFn, context?: any): this;
off(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn?: TileEventHandlerFn, context?: any): this;
off(type: "tileerror", fn?: TileErrorEventHandlerFn, context?: any): this;
off(type: string, fn?: LeafletEventHandlerFn, context?: any): this;
/**
* Removes a set of type/listener pairs.
*/
// With an eventMap there are no additional arguments allowed
off(eventMap: LeafletEventHandlerFnMap): this;
/**
* Removes all listeners to all events on the object.
*/
off(): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
listens(
type:
| "baselayerchange"
| "overlayadd"
| "overlayremove"
| "layeradd"
| "layerremove"
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag"
| "resize"
| "popupopen"
| "tooltipopen"
| "tooltipclose"
| "locationerror"
| "locationfound"
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick"
| "keypress"
| "keydown"
| "keyup"
| "zoomanim"
| "dragend"
| "tileunload"
| "tileloadstart"
| "tileload"
| "tileabort"
| "tileerror",
propagate?: boolean,
): boolean;
listens(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "resize", fn: ResizeEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type: "tooltipopen" | "tooltipclose",
fn: TooltipEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "locationerror", fn: ErrorEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "locationfound", fn: LocationEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(
type: "keypress" | "keydown" | "keyup",
fn: LeafletKeyboardEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "dragend", fn: DragEndEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type: "tileunload" | "tileloadstart" | "tileload" | "tileabort",
fn: TileEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "tileerror", fn: TileEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: string, fn: LeafletEventHandlerFn, context?: any, propagate?: boolean): boolean;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
// tslint:disable:unified-signatures
once(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
): this;
once(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
once(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
once(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
once(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
once(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
once(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
once(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
once(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
once(type: "keypress" | "keydown" | "keyup", fn: LeafletKeyboardEventHandlerFn, context?: any): this;
once(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
once(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
once(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn: TileEventHandlerFn, context?: any): this;
once(type: "tileerror", fn: TileEventHandlerFn, context?: any): this;
once(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
once(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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').
*/
// tslint:disable:unified-signatures
addEventListener(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
): this;
addEventListener(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
addEventListener(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
addEventListener(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
addEventListener(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
addEventListener(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
addEventListener(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
addEventListener(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
addEventListener(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
addEventListener(type: "keypress" | "keydown" | "keyup", fn: LeafletKeyboardEventHandlerFn, context?: any): this;
addEventListener(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
addEventListener(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
addEventListener(
type: "tileunload" | "tileloadstart" | "tileload" | "tileabort",
fn: TileEventHandlerFn,
context?: any,
): this;
addEventListener(type: "tileerror", fn: TileErrorEventHandlerFn, context?: any): this;
addEventListener(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Alias for on(...)
*
* Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
*/
addEventListener(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
removeEventListener(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn?: LayersControlEventHandlerFn,
context?: any,
): this;
removeEventListener(type: "layeradd" | "layerremove", fn?: LayerEventHandlerFn, context?: any): this;
removeEventListener(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn?: LeafletEventHandlerFn,
context?: any,
): this;
removeEventListener(type: "resize", fn?: ResizeEventHandlerFn, context?: any): this;
removeEventListener(type: "popupopen" | "popupclose", fn?: PopupEventHandlerFn, context?: any): this;
removeEventListener(type: "tooltipopen" | "tooltipclose", fn?: TooltipEventHandlerFn, context?: any): this;
removeEventListener(type: "locationerror", fn?: ErrorEventHandlerFn, context?: any): this;
removeEventListener(type: "locationfound", fn?: LocationEventHandlerFn, context?: any): this;
removeEventListener(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn?: LeafletMouseEventHandlerFn,
context?: any,
): this;
removeEventListener(
type: "keypress" | "keydown" | "keyup",
fn?: LeafletKeyboardEventHandlerFn,
context?: any,
): this;
removeEventListener(type: "zoomanim", fn?: ZoomAnimEventHandlerFn, context?: any): this;
removeEventListener(type: "dragend", fn?: DragEndEventHandlerFn, context?: any): this;
removeEventListener(
type: "tileunload" | "tileloadstart" | "tileload" | "tileabort",
fn?: TileEventHandlerFn,
context?: any,
): this;
removeEventListener(type: "tileerror", fn?: TileErrorEventHandlerFn, context?: any): this;
removeEventListener(type: string, fn?: LeafletEventHandlerFn, context?: any): this;
/**
* Alias for off(...)
*
* Removes a set of type/listener pairs.
*/
removeEventListener(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
addOneTimeEventListener(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
addOneTimeEventListener(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
addOneTimeEventListener(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(
type: "keypress" | "keydown" | "keyup",
fn: LeafletKeyboardEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
addOneTimeEventListener(
type: "tileunload" | "tileloadstart" | "tileload" | "tileabort",
fn: TileEventHandlerFn,
context?: any,
): this;
addOneTimeEventListener(type: "tileerror", fn: TileErrorEventHandlerFn, context?: any): this;
addOneTimeEventListener(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Alias for once(...)
*
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
addOneTimeEventListener(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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;
}
// eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers
declare class MixinType {
Events: Events;
}
export const Mixin: MixinType;
/**
* Base class of Leaflet classes supporting events
*/
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').
*/
// tslint:disable:unified-signatures
on(type: "baselayerchange" | "overlayadd" | "overlayremove", fn: LayersControlEventHandlerFn, context?: any): this;
on(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
on(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
on(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
on(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
on(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
on(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
on(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
on(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
on(type: "keypress" | "keydown" | "keyup", fn: LeafletKeyboardEventHandlerFn, context?: any): this;
on(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
on(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
on(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn: TileEventHandlerFn, context?: any): this;
on(type: "tileerror", fn: TileErrorEventHandlerFn, context?: any): this;
on(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
*/
on(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
off(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn?: LayersControlEventHandlerFn,
context?: any,
): this;
off(type: "layeradd" | "layerremove", fn?: LayerEventHandlerFn, context?: any): this;
off(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn?: LeafletEventHandlerFn,
context?: any,
): this;
off(type: "resize", fn?: ResizeEventHandlerFn, context?: any): this;
off(type: "popupopen" | "popupclose", fn?: PopupEventHandlerFn, context?: any): this;
off(type: "tooltipopen" | "tooltipclose", fn?: TooltipEventHandlerFn, context?: any): this;
off(type: "locationerror", fn?: ErrorEventHandlerFn, context?: any): this;
off(type: "locationfound", fn?: LocationEventHandlerFn, context?: any): this;
off(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn?: LeafletMouseEventHandlerFn,
context?: any,
): this;
off(type: "keypress" | "keydown" | "keyup", fn?: LeafletKeyboardEventHandlerFn, context?: any): this;
off(type: "zoomanim", fn?: ZoomAnimEventHandlerFn, context?: any): this;
off(type: "dragend", fn?: DragEndEventHandlerFn, context?: any): this;
off(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn?: TileEventHandlerFn, context?: any): this;
off(type: "tileerror", fn?: TileErrorEventHandlerFn, context?: any): this;
off(type: string, fn?: LeafletEventHandlerFn, context?: any): this;
/**
* Removes a set of type/listener pairs.
*/
// With an eventMap there are no additional arguments allowed
off(eventMap: LeafletEventHandlerFnMap): this;
/**
* Removes all listeners to all events on the object.
*/
off(): this;
// tslint:enable:unified-signatures
/**
* 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.
*/
// tslint:disable:unified-signatures
listens(
type:
| "baselayerchange"
| "overlayadd"
| "overlayremove"
| "layeradd"
| "layerremove"
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag"
| "resize"
| "popupopen"
| "tooltipopen"
| "tooltipclose"
| "locationerror"
| "locationfound"
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick"
| "keypress"
| "keydown"
| "keyup"
| "zoomanim"
| "dragend"
| "tileunload"
| "tileloadstart"
| "tileload"
| "tileabort"
| "tileerror",
propagate?: boolean,
): boolean;
listens(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "resize", fn: ResizeEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type: "tooltipopen" | "tooltipclose",
fn: TooltipEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "locationerror", fn: ErrorEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "locationfound", fn: LocationEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(
type: "keypress" | "keydown" | "keyup",
fn: LeafletKeyboardEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: "dragend", fn: DragEndEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(
type: "tileunload" | "tileloadstart" | "tileload" | "tileabort",
fn: TileEventHandlerFn,
context?: any,
propagate?: boolean,
): boolean;
listens(type: "tileerror", fn: TileEventHandlerFn, context?: any, propagate?: boolean): boolean;
listens(type: string, fn: LeafletEventHandlerFn, context?: any, propagate?: boolean): boolean;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
// tslint:disable:unified-signatures
once(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
): this;
once(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
once(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
once(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
once(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
once(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;
once(type: "locationerror", fn: ErrorEventHandlerFn, context?: any): this;
once(type: "locationfound", fn: LocationEventHandlerFn, context?: any): this;
once(
type:
| "click"
| "dblclick"
| "mousedown"
| "mouseup"
| "mouseover"
| "mouseout"
| "mousemove"
| "contextmenu"
| "preclick",
fn: LeafletMouseEventHandlerFn,
context?: any,
): this;
once(type: "keypress" | "keydown" | "keyup", fn: LeafletKeyboardEventHandlerFn, context?: any): this;
once(type: "zoomanim", fn: ZoomAnimEventHandlerFn, context?: any): this;
once(type: "dragend", fn: DragEndEventHandlerFn, context?: any): this;
once(type: "tileunload" | "tileloadstart" | "tileload" | "tileabort", fn: TileEventHandlerFn, context?: any): this;
once(type: "tileerror", fn: TileEventHandlerFn, context?: any): this;
once(type: string, fn: LeafletEventHandlerFn, context?: any): this;
/**
* Behaves as on(...), except the listener will only get fired once and then removed.
*/
once(eventMap: LeafletEventHandlerFnMap): this;
// tslint:enable:unified-signatures
/**
* 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').
*/
// tslint:disable:unified-signatures
addEventListener(
type: "baselayerchange" | "overlayadd" | "overlayremove",
fn: LayersControlEventHandlerFn,
context?: any,
): this;
addEventListener(type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this;
addEventListener(
type:
| "zoomlevelschange"
| "unload"
| "viewreset"
| "load"
| "zoomstart"
| "movestart"
| "zoom"
| "move"
| "zoomend"
| "moveend"
| "autopanstart"
| "dragstart"
| "drag"
| "add"
| "remove"
| "loading"
| "error"
| "update"
| "down"
| "predrag",
fn: LeafletEventHandlerFn,
context?: any,
): this;
addEventListener(type: "resize", fn: ResizeEventHandlerFn, context?: any): this;
addEventListener(type: "popupopen" | "popupclose", fn: PopupEventHandlerFn, context?: any): this;
addEventListener(type: "tooltipopen" | "tooltipclose", fn: TooltipEventHandlerFn, context?: any): this;