Class Map

L.Class powers the OOP facilities of Leaflet and is used to create almost all of the Leaflet classes documented.

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(id: HTMLElement, options?: MapOptions): Map

Instantiates a map object given a div element and optionally an object literal with map options described below.

constructor

Parameters

Returns

Map

constructor(id: string, options?: MapOptions): Map

Instantiates a map object given a div element id and optionally an object literal with map options described below.

constructor

Parameters

Returns

Map

Properties

public attributionControl: Attribution

Attribution control.

public boxZoom: IHandler

Box (shift-drag with mouse) zoom handler.

public doubleClickZoom: IHandler

Double click zoom handler.

public dragging: IHandler

Map dragging handler (by both mouse and touch).

public featureLayer: FeatureLayer

public gridControl: GridControl

public gridLayer: GridLayer

public infoControl: InfoControl

public keyboard: IHandler

Keyboard navigation handler.

public legendControl: LegendControl

public scrollWheelZoom: IHandler

Scroll wheel zoom handler.

public shareControl: ShareControl

public tap: IHandler

Mobile touch hacks (quick tap and touch hold) handler.

public tileLayer: TileLayer

public touchZoom: IHandler

Touch zoom handler.

public zoomControl: Zoom

Zoom control.

Methods

public addControl(control: IControl): Map

Adds the given control to the map.

Parameters

Returns

Map

public addEventListener(type: string, fn: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

Map

public addEventListener(eventMap: any, context?: any): Map

Parameters

  • eventMap: any
  • context?: any optional

Returns

Map

public addLayer(layer: any): any

Parameters

  • layer: any

Returns

any

public addOneTimeEventListener(type: string, fn: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

Map

public clearAllEventListeners(): Map

Returns

Map

public closePopup(): Map

Closes the popup previously opened with openPopup (or the given one).

Returns

Map

public containerPointToLatLng(point: Point): LatLng

Returns the geographical coordinates of a given map container point.

Parameters

Returns

LatLng

public containerPointToLayerPoint(point: Point): Point

Converts the point relative to the map container to a point relative to the map layer.

Parameters

Returns

Point

public fire(type: string, data?: any): Map

Parameters

  • type: string
  • data?: any optional

Returns

Map

public fireEvent(type: string, data?: any): Map

Parameters

  • type: string
  • data?: any optional

Returns

Map

public fitBounds(bounds: LatLngBounds, options?: FitBoundsOptions): Map

Sets a map view that contains the given geographical bounds with the maximum zoom level possible.

Parameters

Returns

Map

public fitWorld(options?: FitBoundsOptions): Map

Sets a map view that mostly contains the whole world with the maximum zoom level possible.

Parameters

Returns

Map

public getBounds(): LatLngBounds

Returns the LatLngBounds of the current map view.

Returns

LatLngBounds

public getBoundsZoom(bounds: LatLngBounds, inside?: boolean): number

Returns the maximum zoom level on which the given bounds fit to the map view in its entirety. If inside (optional) is set to true, the method instead returns the minimum zoom level on which the map view fits into the given bounds in its entirety.

Parameters

Returns

number

public getCenter(): LatLng

Returns the geographical center of the map view.

Returns

LatLng

public getContainer(): HTMLElement

Returns the container element of the map.

Returns

HTMLElement

public getMaxZoom(): number

Returns the maximum zoom level of the map.

Returns

number

public getMinZoom(): number

Returns the minimum zoom level of the map.

Returns

number

public getPanes(): MapPanes

Returns an object with different map panes (to render overlays in).

Returns

MapPanes

public getPixelBounds(): Bounds

Returns the bounds of the current map view in projected pixel coordinates (sometimes useful in layer and overlay implementations).

Returns

Bounds

public getPixelOrigin(): Point

Returns the projected pixel coordinates of the top left point of the map layer (useful in custom layer and overlay implementations).

Returns

Point

public getSize(): Point

Returns the current size of the map container.

Returns

Point

public getTileJSON(): any

Returns

any

public getZoom(): number

Returns the current zoom of the map view.

Returns

number

public hasEventListeners(type: string): boolean

Parameters

  • type: string

Returns

boolean

public hasLayer(layer: ILayer): boolean

Returns true if the given layer is currently added to the map.

Parameters

Returns

boolean

public invalidateSize(options: ZoomPanOptions): Map

Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default. If options.pan is false, panning will not occur.

Parameters

Returns

Map

public invalidateSize(animate: boolean): Map

Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default.

Parameters

  • animate: boolean

Returns

Map

public latLngToContainerPoint(latlng: LatLng): Point

Returns the map container point that corresponds to the given geographical coordinates.

Parameters

Returns

Point

public latLngToLayerPoint(latlng: LatLng): Point

Returns the map layer point that corresponds to the given geographical coordinates (useful for placing overlays on the map).

Parameters

Returns

Point

public layerPointToContainerPoint(point: Point): Point

Converts the point relative to the map layer to a point relative to the map container.

Parameters

Returns

Point

public layerPointToLatLng(point: Point): LatLng

Returns the geographical coordinates of a given map layer point.

Parameters

Returns

LatLng

public locate(options?: LocateOptions): Map

Tries to locate the user using Geolocation API, firing locationfound event with location data on success or locationerror event on failure, and optionally sets the map view to the user location with respect to detection accuracy (or to the world view if geolocation failed). See Locate options for more details.

Parameters

Returns

Map

public mouseEventToContainerPoint(event: LeafletMouseEvent): Point

Returns the pixel coordinates of a mouse click (relative to the top left corner of the map) given its event object.

Parameters

Returns

Point

public mouseEventToLatLng(event: LeafletMouseEvent): LatLng

Returns the geographical coordinates of the point the mouse clicked on given the click's event object.

Parameters

Returns

LatLng

public mouseEventToLayerPoint(event: LeafletMouseEvent): Point

Returns the pixel coordinates of a mouse click relative to the map layer given its event object.

Parameters

Returns

Point

public off(type: string, fn?: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn?: (e: L.LeafletEvent) => void optional
  • context?: any optional

Returns

Map

public off(eventMap?: any, context?: any): Map

Parameters

  • eventMap?: any optional
  • context?: any optional

Returns

Map

public on(type: string, fn: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

Map

public on(eventMap: any, context?: any): Map

Parameters

  • eventMap: any
  • context?: any optional

Returns

Map

public once(type: string, fn: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

Map

public openPopup(popup: Popup): Map

Opens the specified popup while closing the previously opened (to make sure only one is opened at one time for usability).

Parameters

Returns

Map

public openPopup(html: string, latlng: LatLng, options?: PopupOptions): Map

Creates a popup with the specified options and opens it in the given point on a map.

Parameters

Returns

Map

public openPopup(el: HTMLElement, latlng: LatLng, options?: PopupOptions): Map

Creates a popup with the specified options and opens it in the given point on a map.

Parameters

Returns

Map

public panBy(point: Point, options?: PanOptions): Map

Pans the map by a given number of pixels (animated).

Parameters

Returns

Map

public panInsideBounds(bounds: LatLngBounds): Map

Pans the map to the closest view that would lie inside the given bounds (if it's not already).

Parameters

Returns

Map

public panTo(latlng: LatLng, options?: PanOptions): Map

Pans the map to a given center. Makes an animated pan if new center is not more than one screen away from the current one.

Parameters

Returns

Map

public project(latlng: LatLng, zoom?: number): Point

Projects the given geographical coordinates to absolute pixel coordinates for the given zoom level (current zoom level by default).

Parameters

  • latlng: LatLng
  • zoom?: number optional

Returns

Point

public remove(): Map

Destroys the map and clears all related event listeners.

Returns

Map

public removeControl(control: IControl): Map

Removes the given control from the map.

Parameters

Returns

Map

public removeEventListener(type: string, fn?: (e: L.LeafletEvent) => void, context?: any): Map

Parameters

  • type: string
  • fn?: (e: L.LeafletEvent) => void optional
  • context?: any optional

Returns

Map

public removeEventListener(eventMap?: any, context?: any): Map

Parameters

  • eventMap?: any optional
  • context?: any optional

Returns

Map

public removeLayer(layer: ILayer): Map

Removes the given layer from the map.

Parameters

Returns

Map

public setMaxBounds(bounds: LatLngBounds, options?: ZoomPanOptions): Map

Restricts the map view to the given bounds (see map maxBounds option), passing the given animation options through to setView, if required.

Parameters

Returns

Map

public setView(center: LatLng, zoom: number, options?: ZoomPanOptions): Map

Sets the view of the map (geographical center and zoom) with the given animation options.

Parameters

Returns

Map

public setZoom(zoom: number, options?: ZoomOptions): Map

Sets the zoom of the map.

Parameters

Returns

Map

public setZoomAround(latlng: LatLng, zoom: number, options?: ZoomOptions): Map

Zooms the map while keeping a specified point on the map stationary (e.g. used internally for scroll zoom and double-click zoom).

Parameters

Returns

Map

public stopLocate(): Map

Stops watching location previously initiated by map.locate({watch: true}) and aborts resetting the map view if map.locate was called with {setView: true}.

Returns

Map

public unproject(point: Point, zoom?: number): LatLng

Projects the given absolute pixel coordinates to geographical coordinates for the given zoom level (current zoom level by default).

Parameters

  • point: Point
  • zoom?: number optional

Returns

LatLng

public whenReady(fn: (map: L.Map) => void, context?: any): Map

Runs the given callback when the map gets initialized with a place and zoom, or immediately if it happened already, optionally passing a function context.

Parameters

  • fn: (map: L.Map) => void
  • context?: any optional

Returns

Map

public zoomIn(delta?: number, options?: ZoomOptions): Map

Increases the zoom of the map by delta (1 by default).

Parameters

  • delta?: number optional
  • options?: ZoomOptions optional

Returns

Map

public zoomOut(delta?: number, options?: ZoomOptions): Map

Decreases the zoom of the map by delta (1 by default).

Parameters

  • delta?: number optional
  • options?: ZoomOptions optional

Returns

Map