Back to Leaflet

Reference 2.0.0

docs/reference-2.0.0.html

1.9.4415.1 KB
Original Source

--- layout: v2 title: Documentation bodyclass: api-page ---

Leaflet API reference

This reference reflects Leaflet 2.0.0. Check this list if you are using a different version of Leaflet.

Map

Map Methods

Map Misc

UI Layers

Raster Layers

Vector Layers

Other Layers

Basic Types

Controls

Utility

DOM Utility

Base Classes

Misc

Map

The central class of the API — it is used to create a map on a page and manipulate it.

Usage example

// initialize the map on the "map" div with a given center and zoom
const map = new Map('map', {
	center: [51.505, -0.09],
	zoom: 13
});

Constructor

ConstructorDescription
new Map(<String> id, <Map options> options?)Instantiates a map object given the DOM ID of a <div> element and optionally an object literal with Map options.
new Map(<HTMLElement> el, <Map options> options?)Instantiates a map object given an instance of a <div> HTML element and optionally an object literal with Map options.

Options

OptionTypeDefaultDescription
preferCanvasBooleanfalseWhether Paths should be rendered on a Canvas renderer. By default, all Paths are rendered in a SVG renderer.

Control options

OptionTypeDefaultDescription
attributionControlBooleantrueWhether a attribution control is added to the map by default.
zoomControlBooleantrueWhether a zoom control is added to the map by default.

Interaction Options

OptionTypeDefaultDescription
closePopupOnClickBooleantrueSet it to false if you don't want popups to close when user clicks the map.
boxZoomBooleantrueWhether the map can be zoomed to a rectangular area specified by dragging the pointer while pressing the shift key.
doubleClickZoom`BooleanString`true
draggingBooleantrueWhether the map is draggable with pointer or not.
zoomSnapNumber1Forces the map's zoom level to always be a multiple of this, particularly right after a fitBounds() or a pinch-zoom. By default, the zoom level snaps to the nearest integer; lower values (e.g. 0.5 or 0.1) allow for greater granularity. A value of 0 means the zoom level will not be snapped after fitBounds or a pinch-zoom.
zoomDeltaNumber1Controls how much the map's zoom level will change after a zoomIn(), zoomOut(), pressing + or - on the keyboard, or using the zoom controls. Values smaller than 1 (e.g. 0.5) allow for greater granularity.
trackResizeBooleantrueWhether the map automatically handles browser window resize to update itself.

Panning Inertia Options

OptionTypeDefaultDescription
inertiaBoolean*If enabled, panning of the map will have an inertia effect where the map builds momentum while dragging and continues moving in the same direction for some time. Feels especially nice on touch devices. Enabled by default.
inertiaDecelerationNumber3000The rate with which the inertial movement slows down, in pixels/second².
inertiaMaxSpeedNumberInfinityMax speed of the inertial movement, in pixels/second.
easeLinearityNumber0.2
worldCopyJumpBooleanfalseWith this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.
maxBoundsViscosityNumber0.0If maxBounds is set, this option will control how solid the bounds are when dragging the map around. The default value of 0.0 allows the user to drag outside the bounds at normal speed, higher values will slow down map dragging outside bounds, and 1.0 makes the bounds fully solid, preventing the user from dragging outside the bounds.

Keyboard Navigation Options

OptionTypeDefaultDescription
keyboardBooleantrueMakes the map focusable and allows users to navigate the map with keyboard arrows and +/- keys.
keyboardPanDeltaNumber80Amount of pixels to pan when pressing an arrow key.

Touch interaction options

OptionTypeDefaultDescription
pinchZoom`BooleanString`*
bounceAtZoomLimitsBooleantrueSet it to false if you don't want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming.
tapHoldBoolean``Enables simulation of contextmenu event, default is true for mobile Safari.
tapToleranceNumber15The max number of pixels a user can shift his finger during touch for it to be considered a valid tap.

Mouse wheel options

OptionTypeDefaultDescription
scrollWheelZoom`BooleanString`true
wheelDebounceTimeNumber40Limits the rate at which a wheel can fire (in milliseconds). By default user can't zoom via wheel more often than once per 40 ms.
wheelPxPerZoomLevelNumber60How many scroll pixels (as reported by DomEvent.getWheelDelta) mean a change of one full zoom level. Smaller values will make wheel-zooming faster (and vice versa).

Map State Options

OptionTypeDefaultDescription
crsCRSCRS.EPSG3857The Coordinate Reference System to use. Don't change this if you're not sure what it means.
centerLatLngundefinedInitial geographic center of the map
zoomNumberundefinedInitial map zoom level
minZoomNumber*Minimum zoom level of the map. If not specified and at least one GridLayer or TileLayer is in the map, the lowest of their minZoom options will be used instead.
maxZoomNumber*Maximum zoom level of the map. If not specified and at least one GridLayer or TileLayer is in the map, the highest of their maxZoom options will be used instead.
layersLayer[][]Array of layers that will be added to the map initially
maxBoundsLatLngBoundsnullWhen this option is set, the map restricts the view to the given geographical bounds, bouncing the user back if the user tries to pan outside the view. To set the restriction dynamically, use setMaxBounds method.
rendererRenderer*The default method for drawing vector layers on the map. SVG or Canvas by default depending on browser support.

Animation Options

OptionTypeDefaultDescription
zoomAnimationBooleantrueWhether the map zoom animation is enabled. By default it's enabled in all browsers that support CSS Transitions except Android.
zoomAnimationThresholdNumber4Won't animate zoom if the zoom difference exceeds this value.
fadeAnimationBooleantrueWhether the tile fade animation is enabled. By default it's enabled in all browsers that support CSS Transitions except Android.
markerZoomAnimationBooleantrueWhether markers animate their zoom with the zoom animation, if disabled they will disappear for the length of the animation. By default it's enabled in all browsers that support CSS Transitions except Android.
transform3DLimitNumber2^23Defines the maximum size of a CSS translation transform. The default value should not be changed unless a web browser positions layers in the wrong place after doing a large panBy.

Events

Layer events

EventDataDescription
baselayerchangeLayersControlEventFired when the base layer is changed through the layers control.
overlayaddLayersControlEventFired when an overlay is selected through the layers control.
overlayremoveLayersControlEventFired when an overlay is deselected through the layers control.
layeraddLayerEventFired when a new layer is added to the map.
layerremoveLayerEventFired when some layer is removed from the map

Map state change events

EventDataDescription
zoomlevelschangeEventFired when the number of zoomlevels on the map is changed due to adding or removing a layer.
resizeResizeEventFired when the map is resized.
unloadEventFired when the map is destroyed with remove method.
viewresetEventFired when the map needs to redraw its content (this usually happens on map zoom or load). Very useful for creating custom overlays.
loadEventFired when the map is initialized (when its center and zoom are set for the first time).
zoomstartEventFired when the map zoom is about to change (e.g. before zoom animation).
movestartEventFired when the view of the map starts changing (e.g. user starts dragging the map).
zoomEventFired repeatedly during any change in zoom level, including zoom and fly animations.
moveEventFired repeatedly during any movement of the map, including pan and fly animations.
zoomendEventFired when the map zoom changed, after any animations.
moveendEventFired when the center of the map stops changing (e.g. user stopped dragging the map or after non-centered zoom).

Popup events

EventDataDescription
popupopenPopupEventFired when a popup is opened in the map
popupclosePopupEventFired when a popup in the map is closed
autopanstartEventFired when the map starts autopanning when opening a popup.

Tooltip events

EventDataDescription
tooltipopenTooltipEventFired when a tooltip is opened in the map.
tooltipcloseTooltipEventFired when a tooltip in the map is closed.

Location events

EventDataDescription
locationerrorErrorEventFired when geolocation (using the locate method) failed.
locationfoundLocationEventFired when geolocation (using the locate method) went successfully.

Interaction events

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the map.
dblclickPointerEventFired when the user double-clicks (or double-taps) the map.
pointerdownPointerEventFired when the user pushes the pointer on the map.
pointerupPointerEventFired when the user releases the pointer on the map.
pointeroverPointerEventFired when the pointer enters the map.
pointeroutPointerEventFired when the pointer leaves the map.
pointermovePointerEventFired while the pointer moves over the map.
contextmenuPointerEventFired when the user pushes the right mouse button on the map, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).
keypressKeyboardEventFired when the user presses a key from the keyboard that produces a character value while the map is focused.
keydownKeyboardEventFired when the user presses a key from the keyboard while the map is focused. Unlike the keypress event, the keydown event is fired for keys that produce a character value and for keys that do not produce a character value.
keyupKeyboardEventFired when the user releases a key from the keyboard while the map is focused.
preclickPointerEventFired before pointer click on the map (sometimes useful when you want something to happen on click before any existing click handlers start running).

Other Events

EventDataDescription
zoomanimZoomAnimEventFired at least once per zoom animation. For continuous zoom, like pinch zooming, fired once per frame during zoom.

Methods

MethodReturnsDescription
getRenderer(<Path> layer)Renderer

Returns the instance of Renderer that should be used to render the given Path. It will ensure that the renderer options of the map and paths are respected, and that the renderers do exist on the map.

|

Methods for Layers and Controls

MethodReturnsDescription
addControl(<Control> control)this

Adds the given control to the map

| | removeControl(<Control> control) | this |

Removes the given control from the map

| | addLayer(<Layer> layer) | this |

Adds the given layer to the map

| | removeLayer(<Layer> layer) | this |

Removes the given layer from the map.

| | hasLayer(<Layer> layer) | Boolean |

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

| | eachLayer(<Function> fn, <Object> context?) | this |

Iterates over the layers of the map, optionally specifying context of the iterator function.

map.eachLayer(function(layer){
    layer.bindPopup('Hello');
});

| | openPopup(<Popup> popup) | this |

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

| | openPopup(<String|HTMLElement> content, <LatLng> latlng, <Popup options> options?) | this |

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

| | closePopup(<Popup> popup?) | this |

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

| | openTooltip(<Tooltip> tooltip) | this |

Opens the specified tooltip.

| | openTooltip(<String|HTMLElement> content, <LatLng> latlng, <Tooltip options> options?) | this |

Creates a tooltip with the specified content and options and open it.

| | closeTooltip(<Tooltip> tooltip) | this |

Closes the tooltip given as parameter.

|

Methods for modifying map state

MethodReturnsDescription
setView(<LatLng> center, <Number> zoom, <Zoom/pan options> options?)this

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

| | setZoom(<Number> zoom, <Zoom/pan options> options?) | this |

Sets the zoom of the map.

| | zoomIn(<Number> delta?, <Zoom options> options?) | this |

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

| | zoomOut(<Number> delta?, <Zoom options> options?) | this |

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

| | setZoomAround(<LatLng> latlng, <Number> zoom, <Zoom options> options) | this |

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

| | setZoomAround(<Point> offset, <Number> zoom, <Zoom options> options) | this |

Zooms the map while keeping a specified pixel on the map (relative to the top-left corner) stationary.

| | fitBounds(<LatLngBounds> bounds, <fitBounds options> options?) | this |

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

| | fitWorld(<fitBounds options> options?) | this |

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

| | panTo(<LatLng> latlng, <Pan options> options?) | this |

Pans the map to a given center.

| | panBy(<Point> offset, <Pan options> options?) | this |

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

| | flyTo(<LatLng> latlng, <Number> zoom?, <Zoom/pan options> options?) | this |

Sets the view of the map (geographical center and zoom) performing a smooth pan-zoom animation.

| | flyToBounds(<LatLngBounds> bounds, <fitBounds options> options?) | this |

Sets the view of the map with a smooth animation like flyTo, but takes a bounds parameter like fitBounds.

| | setMaxBounds(<LatLngBounds> bounds) | this |

Restricts the map view to the given bounds (see the maxBounds option).

| | setMinZoom(<Number> zoom) | this |

Sets the lower limit for the available zoom levels (see the minZoom option).

| | setMaxZoom(<Number> zoom) | this |

Sets the upper limit for the available zoom levels (see the maxZoom option).

| | panInsideBounds(<LatLngBounds> bounds, <Pan options> options?) | this |

Pans the map to the closest view that would lie inside the given bounds (if it's not already), controlling the animation using the options specific, if any.

| | panInside(<LatLng> latlng, <padding options> options?) | this |

Pans the map the minimum amount to make the latlng visible. Use padding options to fit the display to more restricted bounds. If latlng is already within the (optionally padded) display bounds, the map will not be panned.

| | invalidateSize(<Zoom/pan options> options) | this |

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. If options.debounceMoveend is true, it will delay moveend event so that it doesn't happen often even if the method is called many times in a row.

| | invalidateSize(<Boolean> animate) | this |

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.

| | stop() | this |

Stops the currently running panTo or flyTo animation, if any.

|

Geolocation methods

MethodReturnsDescription
locate(<Locate options> options?)this

Tries to locate the user using the Geolocation API, firing a locationfound event with location data on success or a locationerror event on failure, and optionally sets the map view to the user's location with respect to detection accuracy (or to the world view if geolocation failed). Note that, if your page doesn't use HTTPS, this method will fail in modern browsers (Chrome 50 and newer) See Locate options for more details.

| | stopLocate() | this |

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

|

Other Methods

MethodReturnsDescription
addHandler(<String> name, <Function> HandlerClass)this

Adds a new Handler to the map, given its name and constructor function.

| | remove() | this |

Destroys the map and clears all related event listeners.

| | createPane(<String> name, <HTMLElement> container?) | HTMLElement |

Creates a new map pane with the given name if it doesn't exist already, then returns it. The pane is created as a child of container, or as a child of the main map pane if not set.

| | getPane(<String|HTMLElement> pane) | HTMLElement |

Returns a map pane, given its name or its HTML element (its identity).

| | getPanes() | Object |

Returns a plain object containing the names of all panes as keys and the panes as values.

| | getContainer() | HTMLElement |

Returns the HTML element that contains the map.

| | whenReady(<Function> fn, <Object> context?) | this |

Runs the given function fn when the map gets initialized with a view (center and zoom) and at least one layer, or immediately if it's already initialized, optionally passing a function context.

|

Methods for Getting Map State

MethodReturnsDescription
getCenter()LatLng

Returns the geographical center of the map view

| | getZoom() | Number |

Returns the current zoom level of the map view

| | getBounds() | LatLngBounds |

Returns the geographical bounds visible in the current map view

| | getMinZoom() | Number |

Returns the minimum zoom level of the map (if set in the minZoom option of the map or of any layers), or 0 by default.

| | getMaxZoom() | Number |

Returns the maximum zoom level of the map (if set in the maxZoom option of the map or of any layers).

| | getBoundsZoom(<LatLngBounds> bounds, <Boolean> inside?, <Point> padding?) | 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.

| | getSize() | Point |

Returns the current size of the map container (in pixels).

| | getPixelBounds() | Bounds |

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

| | getPixelOrigin() | Point |

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

| | getPixelWorldBounds(<Number> zoom?) | Bounds |

Returns the world's bounds in pixel coordinates for zoom level zoom. If zoom is omitted, the map's current zoom level is used.

|

Conversion Methods

MethodReturnsDescription
getZoomScale(<Number> toZoom, <Number> fromZoom)Number

Returns the scale factor to be applied to a map transition from zoom level fromZoom to toZoom. Used internally to help with zoom animations.

| | getScaleZoom(<Number> scale, <Number> fromZoom) | Number |

Returns the zoom level that the map would end up at, if it is at fromZoom level and everything is scaled by a factor of scale. Inverse of getZoomScale.

| | project(<LatLng> latlng, <Number> zoom) | Point |

Projects a geographical coordinate LatLng according to the projection of the map's CRS, then scales it according to zoom and the CRS's Transformation. The result is pixel coordinate relative to the CRS origin.

| | unproject(<Point> point, <Number> zoom) | LatLng |

Inverse of project.

| | layerPointToLatLng(<Point> point) | LatLng |

Given a pixel coordinate relative to the origin pixel, returns the corresponding geographical coordinate (for the current zoom level).

| | latLngToLayerPoint(<LatLng> latlng) | Point |

Given a geographical coordinate, returns the corresponding pixel coordinate relative to the origin pixel.

| | wrapLatLng(<LatLng> latlng) | LatLng |

Returns a LatLng where lat and lng has been wrapped according to the map's CRS's wrapLat and wrapLng properties, if they are outside the CRS's bounds. By default this means longitude is wrapped around the dateline so its value is between -180 and +180 degrees.

| | wrapLatLngBounds(<LatLngBounds> bounds) | LatLngBounds |

Returns a LatLngBounds with the same size as the given one, ensuring that its center is within the CRS's bounds. By default this means the center longitude is wrapped around the dateline so its value is between -180 and +180 degrees, and the majority of the bounds overlaps the CRS's bounds.

| | distance(<LatLng> latlng1, <LatLng> latlng2) | Number |

Returns the distance between two geographical coordinates according to the map's CRS. By default this measures distance in meters.

| | containerPointToLayerPoint(<Point> point) | Point |

Given a pixel coordinate relative to the map container, returns the corresponding pixel coordinate relative to the origin pixel.

| | layerPointToContainerPoint(<Point> point) | Point |

Given a pixel coordinate relative to the origin pixel, returns the corresponding pixel coordinate relative to the map container.

| | containerPointToLatLng(<Point> point) | LatLng |

Given a pixel coordinate relative to the map container, returns the corresponding geographical coordinate (for the current zoom level).

| | latLngToContainerPoint(<LatLng> latlng) | Point |

Given a geographical coordinate, returns the corresponding pixel coordinate relative to the map container.

| | pointerEventToContainerPoint(<PointerEvent> ev) | Point |

Given a PointerEvent object, returns the pixel coordinate relative to the map container where the event took place.

| | pointerEventToLayerPoint(<PointerEvent> ev) | Point |

Given a PointerEvent object, returns the pixel coordinate relative to the origin pixel where the event took place. Given a PointerEvent object, returns geographical coordinate where the event took place.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Properties

Controls

PropertyTypeDescription
zoomControlControl.ZoomThe default zoom control (only available if the zoomControl option was true when creating the map).

Handlers

PropertyTypeDescription
boxZoomHandlerBox (shift-drag with pointer) zoom handler.
doubleClickZoomHandlerDouble click zoom handler.
draggingHandlerMap dragging handler.
keyboardHandlerKeyboard navigation handler.
pinchZoomHandlerPinch zoom handler.
scrollWheelZoomHandlerScroll wheel zoom handler.
tapHoldHandlerLong tap handler to simulate contextmenu event (useful in mobile Safari).

Map panes

Panes are DOM elements used to control the ordering of layers on the map. You can access panes with map.getPane or map.getPanes methods. New panes can be created with the map.createPane method.

Every map has the following default panes that differ only in zIndex.

PaneTypeZ-indexDescription
mapPaneHTMLElement'auto'Pane that contains all other map panes
tilePaneHTMLElement200Pane for GridLayers and TileLayers
overlayPaneHTMLElement400Pane for vectors (Paths, like Polylines and Polygons), ImageOverlays and VideoOverlays
shadowPaneHTMLElement500Pane for overlay shadows (e.g. Marker shadows)
markerPaneHTMLElement600Pane for Icons of Markers
tooltipPaneHTMLElement650Pane for Tooltips.
popupPaneHTMLElement700Pane for Popups.

Locate options

Some of the geolocation methods for Map take in an options parameter. This is a plain javascript object with the following optional components:

OptionTypeDefaultDescription
watchBooleanfalseIf true, starts continuous watching of location changes (instead of detecting it once) using W3C watchPosition method. You can later stop watching using map.stopLocate() method.
setViewBooleanfalseIf true, automatically sets the map view to the user location with respect to detection accuracy, or to world view if geolocation failed.
maxZoomNumberInfinityThe maximum zoom for automatic view setting when using setView option.
timeoutNumber10000Number of milliseconds to wait for a response from geolocation before firing a locationerror event.
maximumAgeNumber0Maximum age of detected location. If less than this amount of milliseconds passed since last geolocation response, locate will return a cached location.
enableHighAccuracyBooleanfalseEnables high accuracy, see description in the W3C spec.

Zoom options

Some of the Map methods which modify the zoom level take in an options parameter. This is a plain javascript object with the following optional components:

OptionTypeDefaultDescription
animateBoolean``If not specified, zoom animation will happen if the zoom origin is inside the current view. If true, the map will attempt animating zoom disregarding where zoom origin is. Setting false will make it always reset the view completely without animation.

Pan options

Some of the Map methods which modify the center of the map take in an options parameter. This is a plain javascript object with the following optional components:

OptionTypeDefaultDescription
animateBoolean``If true, panning will always be animated if possible. If false, it will not animate panning, either resetting the map view if panning more than a screen away, or just setting a new offset for the map pane (except for panBy which always does the latter).
durationNumber0.25Duration of animated panning, in seconds.
easeLinearityNumber0.25The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve.
noMoveStartBooleanfalseIf true, panning won't fire movestart event on start (used internally for panning inertia).

Zoom/pan options

▶ Options inherited from Zoom options

OptionTypeDefaultDescription
animateBoolean``If not specified, zoom animation will happen if the zoom origin is inside the current view. If true, the map will attempt animating zoom disregarding where zoom origin is. Setting false will make it always reset the view completely without animation.

▶ Options inherited from Pan options

OptionTypeDefaultDescription
durationNumber0.25Duration of animated panning, in seconds.
easeLinearityNumber0.25The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve.
noMoveStartBooleanfalseIf true, panning won't fire movestart event on start (used internally for panning inertia).

Padding options

OptionTypeDefaultDescription
paddingTopLeftPoint[0, 0]Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.
paddingBottomRightPoint[0, 0]The same for the bottom right corner of the map.
paddingPoint[0, 0]Equivalent of setting both top left and bottom right padding to the same value.

FitBounds options

OptionTypeDefaultDescription
maxZoomNumbernullThe maximum possible zoom to use.

▶ Options inherited from Zoom options

OptionTypeDefaultDescription
animateBoolean``If not specified, zoom animation will happen if the zoom origin is inside the current view. If true, the map will attempt animating zoom disregarding where zoom origin is. Setting false will make it always reset the view completely without animation.

▶ Options inherited from Pan options

OptionTypeDefaultDescription
durationNumber0.25Duration of animated panning, in seconds.
easeLinearityNumber0.25The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, and the smaller this number, the more bowed the curve.
noMoveStartBooleanfalseIf true, panning won't fire movestart event on start (used internally for panning inertia).

▶ Options inherited from Padding options

OptionTypeDefaultDescription
paddingTopLeftPoint[0, 0]Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.
paddingBottomRightPoint[0, 0]The same for the bottom right corner of the map.
paddingPoint[0, 0]Equivalent of setting both top left and bottom right padding to the same value.

Marker

Marker is used to display clickable/draggable icons on the map. Extends Layer.

Usage example

new Marker([50.5, 30.5]).addTo(map);

Constructor

ConstructorDescription
new Marker(<LatLng> latlng, <Marker options> options?)Instantiates a Marker object given a geographical point and optionally an options object.

Options

OptionTypeDefaultDescription
iconIcon*Icon instance to use for rendering the marker. See Icon documentation for details on how to customize the marker icon. If not specified, a common instance of Icon.Default is used.
keyboardBooleantrueWhether the marker can be tabbed to with a keyboard and clicked by pressing enter.
titleString''Text for the browser tooltip that appear on marker hover (no tooltip by default). Useful for accessibility.
altString'Marker'Text for the alt attribute of the icon image. Useful for accessibility.
zIndexOffsetNumber0By default, marker images zIndex is set automatically based on its latitude. Use this option if you want to put the marker on top of all others (or below), specifying a high value like 1000 (or high negative value, respectively).
opacityNumber1.0The opacity of the marker.
riseOnHoverBooleanfalseIf true, the marker will get on top of others when you hover the pointer over it.
riseOffsetNumber250The z-index offset used for the riseOnHover feature.
paneString'markerPane'Map pane where the markers icon will be added.
shadowPaneString'shadowPane'Map pane where the markers shadow will be added.
bubblingPointerEventsBooleanfalseWhen true, a pointer event on this marker will trigger the same event on the map (unless DomEvent.stopPropagation is used).
autoPanOnFocusBooleantrueWhen true, the map will pan whenever the marker is focused (via e.g. pressing tab on the keyboard) to ensure the marker is visible within the map's bounds

Draggable marker options

OptionTypeDefaultDescription
draggableBooleanfalseWhether the marker is draggable with pointer or not.
autoPanBooleanfalseWhether to pan the map when dragging this marker near its edge or not.
autoPanPaddingPointPoint(50, 50)Distance (in pixels to the left/right and to the top/bottom) of the map edge to start panning the map.
autoPanSpeedNumber10Number of pixels the map should pan by.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
moveEventFired when the marker is moved via setLatLng or by dragging. Old and new coordinates are included in event arguments as oldLatLng, latlng.

Dragging events

EventDataDescription
dragstartEventFired when the user starts dragging the marker.
movestartEventFired when the marker starts moving (because of dragging).
dragEventFired repeatedly while the user drags the marker.
dragendDragEndEventFired when the user stops dragging the marker.
moveendEventFired when the marker stops moving (because of dragging).

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

In addition to shared layer methods like addTo() and remove() and popup methods like bindPopup() you can also use the following methods:

MethodReturnsDescription
getLatLng()LatLng

Returns the current geographical position of the marker.

| | setLatLng(<LatLng> latlng) | this |

Changes the marker position to the given point.

| | setZIndexOffset(<Number> offset) | this |

Changes the zIndex offset of the marker.

| | getIcon() | Icon |

Returns the current icon used by the marker

| | setIcon(<Icon> icon) | this |

Changes the marker icon.

| | getElement() | HTMLElement |

Returns the instance of HTMLElement used by Marker layer.

| | setOpacity(<Number> opacity) | this |

Changes the opacity of the marker.

|

Other methods

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the marker (as a GeoJSON Point Feature).

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Properties

Interaction handlers

Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see Handler methods). Example:

marker.dragging.disable();
PropertyTypeDescription
draggingHandlerMarker dragging handler. Only valid when the marker is on the map (Otherwise set marker.options.draggable).

DivOverlay

Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.

Options

OptionTypeDefaultDescription
interactiveBooleanfalseIf true, the popup/tooltip will listen to the pointer events.
offsetPointPoint(0, 0)The offset of the overlay position.
classNameString''A custom CSS class name to assign to the overlay.
paneStringundefinedMap pane where the overlay will be added.
content`StringHTMLElementFunction`

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

DivOverlay events

EventDataDescription
contentupdateEventFired when the content of the overlay is updated

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
openOn(<Map> map)this

Adds the overlay to the map. Alternative to map.openPopup(popup)/.openTooltip(tooltip).

| | close() | this |

Closes the overlay. Alternative to map.closePopup(popup)/.closeTooltip(tooltip) and layer.closePopup()/.closeTooltip().

| | toggle(<Layer> layer?) | this |

Opens or closes the overlay bound to layer depending on its current state. Argument may be omitted only for overlay bound to layer. Alternative to layer.togglePopup()/.toggleTooltip().

| | getLatLng() | LatLng |

Returns the geographical point of the overlay.

| | setLatLng(<LatLng> latlng) | this |

Sets the geographical point where the overlay will open.

| | getContent() | String|HTMLElement |

Returns the content of the overlay.

| | setContent(<String|HTMLElement|Function> htmlContent) | this |

Sets the HTML content of the overlay. If a function is passed the source layer will be passed to the function. The function should return a String or HTMLElement to be used in the overlay.

| | getElement() | String|HTMLElement |

Returns the HTML container of the overlay.

| | update() | null |

Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded.

| | isOpen() | Boolean |

Returns true when the overlay is visible on the map.

| | bringToFront() | this |

Brings this overlay in front of other overlays (in the same map pane).

| | bringToBack() | this |

Brings this overlay to the back of other overlays (in the same map pane).

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Used to open popups in certain places of the map. Use Map.openPopup to open popups while making sure that only one popup is open at one time (recommended for usability), or use Map.addLayer to open as many as you want.

Usage example

If you want to just bind a popup to marker click and then open it, it's really easy:

marker.bindPopup(popupContent).openPopup();

Path overlays like polylines also have a bindPopup method.

A popup can be also standalone:

const popup = new Popup()
	.setLatLng(latlng)
	.setContent('<p>Hello world!
This is a nice popup.</p>')
	.openOn(map);

or

const popup = new Popup(latlng, {content: '<p>Hello world!
This is a nice popup.</p>'})
	.openOn(map);

Constructor

ConstructorDescription
new Popup(<Popup options> options?, <Layer> source?)Instantiates a Popup object given an optional options object that describes its appearance and location and an optional source object that is used to tag the popup with a reference to the Layer to which it refers.
new Popup(<LatLng> latlng, <Popup options> options?)Instantiates a Popup object given latlng where the popup will open and an optional options object that describes its appearance and location.

Options

OptionTypeDefaultDescription
paneString'popupPane'Map pane where the popup will be added.
offsetPointPoint(0, 7)The offset of the popup position.
maxWidthNumber300Max width of the popup, in pixels.
minWidthNumber50Min width of the popup, in pixels.
maxHeightNumbernullIf set, creates a scrollable container of the given height inside a popup if its content exceeds it. The scrollable container can be styled using the leaflet-popup-scrolled CSS class selector.
autoPanBooleantrueSet it to false if you don't want the map to do panning animation to fit the opened popup.
autoPanPaddingTopLeftPointnullThe margin between the popup and the top left corner of the map view after autopanning was performed.
autoPanPaddingBottomRightPointnullThe margin between the popup and the bottom right corner of the map view after autopanning was performed.
autoPanPaddingPointPoint(5, 5)Equivalent of setting both top left and bottom right autopan padding to the same value.
keepInViewBooleanfalseSet it to true if you want to prevent users from panning the popup off of the screen while it is open.
closeButtonBooleantrueControls the presence of a close button in the popup.
closeButtonLabelString'Close popup'Specifies the 'aria-label' attribute of the close button.
autoCloseBooleantrueSet it to false if you want to override the default behavior of the popup closing when another popup is opened.
closeOnEscapeKeyBooleantrueSet it to false if you want to override the default behavior of the ESC key for closing of the popup.
closeOnClickBoolean*Set it if you want to override the default behavior of the popup closing when user clicks on the map. Defaults to the map's closePopupOnClick option.
classNameString''A custom CSS class name to assign to the popup.
trackResizeBooleantrueWhether the popup shall react to changes in the size of its contents (e.g. when an image inside the popup loads) and reposition itself.

▶ Options inherited from DivOverlay

OptionTypeDefaultDescription
interactiveBooleanfalseIf true, the popup/tooltip will listen to the pointer events.
content`StringHTMLElementFunction`

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ DivOverlay events inherited from DivOverlay

EventDataDescription
contentupdateEventFired when the content of the overlay is updated

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
openOn(<Map> map)this

Alternative to map.openPopup(popup). Adds the popup to the map and closes the previous one.

|

▶ Methods inherited from DivOverlay

MethodReturnsDescription
close()this

Closes the overlay. Alternative to map.closePopup(popup)/.closeTooltip(tooltip) and layer.closePopup()/.closeTooltip().

| | toggle(<Layer> layer?) | this |

Opens or closes the overlay bound to layer depending on its current state. Argument may be omitted only for overlay bound to layer. Alternative to layer.togglePopup()/.toggleTooltip().

| | getLatLng() | LatLng |

Returns the geographical point of the overlay.

| | setLatLng(<LatLng> latlng) | this |

Sets the geographical point where the overlay will open.

| | getContent() | String|HTMLElement |

Returns the content of the overlay.

| | setContent(<String|HTMLElement|Function> htmlContent) | this |

Sets the HTML content of the overlay. If a function is passed the source layer will be passed to the function. The function should return a String or HTMLElement to be used in the overlay.

| | getElement() | String|HTMLElement |

Returns the HTML container of the overlay.

| | update() | null |

Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded.

| | isOpen() | Boolean |

Returns true when the overlay is visible on the map.

| | bringToFront() | this |

Brings this overlay in front of other overlays (in the same map pane).

| | bringToBack() | this |

Brings this overlay to the back of other overlays (in the same map pane).

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Tooltip

Used to display small texts on top of map layers.

Usage example

If you want to just bind a tooltip to marker:

marker.bindTooltip("my tooltip text").openTooltip();

Path overlays like polylines also have a bindTooltip method.

A tooltip can be also standalone:

const tooltip = new Tooltip()
	.setLatLng(latlng)
	.setContent('Hello world!
This is a nice tooltip.')
	.addTo(map);

or

const tooltip = new Tooltip(latlng, {content: 'Hello world!
This is a nice tooltip.'})
	.addTo(map);

Note about tooltip offset. Leaflet takes two options in consideration for computing tooltip offsetting:

  • the offset Tooltip option: it defaults to [0, 0], and it's specific to one tooltip. Add a positive x offset to move the tooltip to the right, and a positive y offset to move it to the bottom. Negatives will move to the left and top.
  • the tooltipAnchor Icon option: this will only be considered for Marker. You should adapt this value if you use a custom icon.

Constructor

ConstructorDescription
new Tooltip(<Tooltip options> options?, <Layer> source?)Instantiates a Tooltip object given an optional options object that describes its appearance and location and an optional source object that is used to tag the tooltip with a reference to the Layer to which it refers.
new Tooltip(<LatLng> latlng, <Tooltip options> options?)Instantiates a Tooltip object given latlng where the tooltip will open and an optional options object that describes its appearance and location.

Options

OptionTypeDefaultDescription
paneString'tooltipPane'Map pane where the tooltip will be added.
offsetPointPoint(0, 0)Optional offset of the tooltip position.
directionString'auto'Direction where to open the tooltip. Possible values are: right, left, top, bottom, center, auto. auto will dynamically switch between right and left according to the tooltip position on the map.
permanentBooleanfalseWhether to open the tooltip permanently or only on pointerover.
stickyBooleanfalseIf true, the tooltip will follow the pointer instead of being fixed at the feature center.
opacityNumber0.9Tooltip container opacity.

▶ Options inherited from DivOverlay

OptionTypeDefaultDescription
interactiveBooleanfalseIf true, the popup/tooltip will listen to the pointer events.
classNameString''A custom CSS class name to assign to the overlay.
content`StringHTMLElementFunction`

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ DivOverlay events inherited from DivOverlay

EventDataDescription
contentupdateEventFired when the content of the overlay is updated

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

▶ Methods inherited from DivOverlay

MethodReturnsDescription
openOn(<Map> map)this

Adds the overlay to the map. Alternative to map.openPopup(popup)/.openTooltip(tooltip).

| | close() | this |

Closes the overlay. Alternative to map.closePopup(popup)/.closeTooltip(tooltip) and layer.closePopup()/.closeTooltip().

| | toggle(<Layer> layer?) | this |

Opens or closes the overlay bound to layer depending on its current state. Argument may be omitted only for overlay bound to layer. Alternative to layer.togglePopup()/.toggleTooltip().

| | getLatLng() | LatLng |

Returns the geographical point of the overlay.

| | setLatLng(<LatLng> latlng) | this |

Sets the geographical point where the overlay will open.

| | getContent() | String|HTMLElement |

Returns the content of the overlay.

| | setContent(<String|HTMLElement|Function> htmlContent) | this |

Sets the HTML content of the overlay. If a function is passed the source layer will be passed to the function. The function should return a String or HTMLElement to be used in the overlay.

| | getElement() | String|HTMLElement |

Returns the HTML container of the overlay.

| | update() | null |

Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded.

| | isOpen() | Boolean |

Returns true when the overlay is visible on the map.

| | bringToFront() | this |

Brings this overlay in front of other overlays (in the same map pane).

| | bringToBack() | this |

Brings this overlay to the back of other overlays (in the same map pane).

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

TileLayer

Used to load and display tile layers on the map. Note that most tile servers require attribution, which you can set under Layer. Extends GridLayer.

Usage example

new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);

URL template

A string of the following form:

'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'

{s} means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; a, b or c by default, can be omitted), {z} — zoom level, {x} and {y} — tile coordinates. {r} can be used to add "@2x" to the URL to load retina tiles.

You can use custom keys in the template, which will be evaluated from TileLayer options, like this:

new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});

Constructor

URL template

ConstructorDescription
new Tilelayer(<String> urlTemplate, <TileLayer options> options?)Instantiates a tile layer object given a URL template and optionally an options object.

Options

OptionTypeDefaultDescription
minZoomNumber0The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoomNumber18The maximum zoom level up to which this layer will be displayed (inclusive).
subdomains`StringString[]`'abc'
errorTileUrlString''URL to the tile image to show in place of the tile that failed to load.
zoomOffsetNumber0The zoom number used in tile URLs will be offset with this value.
tmsBooleanfalseIf true, inverses Y axis numbering for tiles (turn this on for TMS services).
zoomReverseBooleanfalseIf set to true, the zoom number used in tile URLs will be reversed (maxZoom - zoom instead of zoom)
detectRetinaBooleanfalseIf true and user is on a retina display, it will request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution.
crossOrigin`BooleanString`false
referrerPolicy`BooleanString`false

▶ Options inherited from GridLayer

OptionTypeDefaultDescription
tileSize`NumberPoint`256
opacityNumber1.0Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdleBoolean(depends)Load new tiles only when panning ends. true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation. false otherwise in order to display new tiles during panning, since it is easy to pan outside the keepBuffer option in desktop browsers.
updateWhenZoomingBooleantrueBy default, a smooth zoom animation (during a pinch zoom or a flyTo()) will update grid layers every integer zoom level. Setting this option to false will update the grid layer only when the smooth animation ends.
updateIntervalNumber200Tiles will not update more than once every updateInterval milliseconds when panning.
zIndexNumber1The explicit zIndex of the tile layer.
boundsLatLngBoundsundefinedIf set, tiles will only be loaded inside the set LatLngBounds.
maxNativeZoomNumberundefinedMaximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than maxNativeZoom will be loaded from maxNativeZoom level and auto-scaled.
minNativeZoomNumberundefinedMinimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than minNativeZoom will be loaded from minNativeZoom level and auto-scaled.
noWrapBooleanfalseWhether the layer is wrapped around the antimeridian. If true, the GridLayer will only be displayed once at low zoom levels. Has no effect when the map CRS doesn't wrap around. Can be used in combination with bounds to prevent requesting tiles outside the CRS limits.
paneString'tilePane'Map pane where the grid layer will be added.
classNameString''A custom class name to assign to the tile layer. Empty by default.
keepBufferNumber2When panning the map, keep this many rows and columns of tiles before unloading them.

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

Extension methods

EventDataDescription
tileabortTileEventFired when a tile was loading but is now not wanted.

▶ Events inherited from GridLayer

EventDataDescription
loadingEventFired when the grid layer starts loading tiles.
tileunloadTileEventFired when a tile is removed (e.g. when a tile goes off the screen).
tileloadstartTileEventFired when a tile is requested and starts loading.
tileerrorTileErrorEventFired when there is an error loading a tile.
tileloadTileEventFired when a tile loads.
loadEventFired when the grid layer loaded all visible tiles.

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setUrl(<String> url, <Boolean> noRedraw?)this

Updates the layer's URL template and redraws it (unless noRedraw is set to true). If the URL does not change, the layer will not be redrawn unless the noRedraw parameter is set to false.

| | createTile(<Object> coords, <Function> done?) | HTMLElement |

Called only internally, overrides GridLayer's createTile() to return an `` HTML element with the appropriate image URL given coords. The done callback is called when the tile has been loaded.

|

Extension methods

Layers extending TileLayer might reimplement the following method.

MethodReturnsDescription
getTileUrl(<Object> coords)String

Called only internally, returns the URL for a tile given its coordinates. Classes extending TileLayer can override this function to provide custom tile URL naming schemes.

|

▶ Methods inherited from GridLayer

MethodReturnsDescription
bringToFront()this

Brings the tile layer to the top of all tile layers.

| | bringToBack() | this |

Brings the tile layer to the bottom of all tile layers.

| | getContainer() | HTMLElement |

Returns the HTML element that contains the tiles for this layer.

| | setOpacity(<Number> opacity) | this |

Changes the opacity of the grid layer.

| | setZIndex(<Number> zIndex) | this |

Changes the zIndex of the grid layer.

| | isLoading() | Boolean |

Returns true if any tile in the grid layer has not finished loading.

| | redraw() | this |

Causes the layer to clear all the tiles and request them again.

| | getTileSize() | Point |

Normalizes the tileSize option into a point. Used by the createTile() method.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

TileLayer.WMS

Used to display WMS services as tile layers on the map. Extends TileLayer.

Usage example

const nexrad = new TileLayer.wms("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
	layers: 'nexrad-n0r-900913',
	format: 'image/png',
	transparent: true,
	attribution: "Weather data © 2012 IEM Nexrad"
});

Constructor

ConstructorDescription
new TileLayer.WMS(<String> baseUrl, <TileLayer.WMS options> options)Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object.

Options

If any custom options not documented here are used, they will be sent to the WMS server as extra parameters in each request URL. This can be useful for non-standard vendor WMS parameters.

OptionTypeDefaultDescription
layersString''(required) Comma-separated list of WMS layers to show.
stylesString''Comma-separated list of WMS styles.
formatString'image/jpeg'WMS image format (use 'image/png' for layers with transparency).
transparentBooleanfalseIf true, the WMS service will return images with transparency.
versionString'1.1.1'Version of the WMS service to use
crsCRSnullCoordinate Reference System to use for the WMS requests, defaults to map CRS. Don't change this if you're not sure what it means.
uppercaseBooleanfalseIf true, WMS request parameter keys will be uppercase.

▶ Options inherited from TileLayer

OptionTypeDefaultDescription
minZoomNumber0The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoomNumber18The maximum zoom level up to which this layer will be displayed (inclusive).
subdomains`StringString[]`'abc'
errorTileUrlString''URL to the tile image to show in place of the tile that failed to load.
zoomOffsetNumber0The zoom number used in tile URLs will be offset with this value.
tmsBooleanfalseIf true, inverses Y axis numbering for tiles (turn this on for TMS services).
zoomReverseBooleanfalseIf set to true, the zoom number used in tile URLs will be reversed (maxZoom - zoom instead of zoom)
detectRetinaBooleanfalseIf true and user is on a retina display, it will request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution.
crossOrigin`BooleanString`false
referrerPolicy`BooleanString`false

▶ Options inherited from GridLayer

OptionTypeDefaultDescription
tileSize`NumberPoint`256
opacityNumber1.0Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdleBoolean(depends)Load new tiles only when panning ends. true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation. false otherwise in order to display new tiles during panning, since it is easy to pan outside the keepBuffer option in desktop browsers.
updateWhenZoomingBooleantrueBy default, a smooth zoom animation (during a pinch zoom or a flyTo()) will update grid layers every integer zoom level. Setting this option to false will update the grid layer only when the smooth animation ends.
updateIntervalNumber200Tiles will not update more than once every updateInterval milliseconds when panning.
zIndexNumber1The explicit zIndex of the tile layer.
boundsLatLngBoundsundefinedIf set, tiles will only be loaded inside the set LatLngBounds.
maxNativeZoomNumberundefinedMaximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than maxNativeZoom will be loaded from maxNativeZoom level and auto-scaled.
minNativeZoomNumberundefinedMinimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than minNativeZoom will be loaded from minNativeZoom level and auto-scaled.
noWrapBooleanfalseWhether the layer is wrapped around the antimeridian. If true, the GridLayer will only be displayed once at low zoom levels. Has no effect when the map CRS doesn't wrap around. Can be used in combination with bounds to prevent requesting tiles outside the CRS limits.
paneString'tilePane'Map pane where the grid layer will be added.
classNameString''A custom class name to assign to the tile layer. Empty by default.
keepBufferNumber2When panning the map, keep this many rows and columns of tiles before unloading them.

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Extension methods inherited from TileLayer

EventDataDescription
tileabortTileEventFired when a tile was loading but is now not wanted.

▶ Events inherited from GridLayer

EventDataDescription
loadingEventFired when the grid layer starts loading tiles.
tileunloadTileEventFired when a tile is removed (e.g. when a tile goes off the screen).
tileloadstartTileEventFired when a tile is requested and starts loading.
tileerrorTileErrorEventFired when there is an error loading a tile.
tileloadTileEventFired when a tile loads.
loadEventFired when the grid layer loaded all visible tiles.

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setParams(<Object> params, <Boolean> noRedraw?)this

Merges an object with the new parameters and re-requests tiles on the current screen (unless noRedraw was set to true).

|

▶ Methods inherited from TileLayer

MethodReturnsDescription
setUrl(<String> url, <Boolean> noRedraw?)this

Updates the layer's URL template and redraws it (unless noRedraw is set to true). If the URL does not change, the layer will not be redrawn unless the noRedraw parameter is set to false.

| | createTile(<Object> coords, <Function> done?) | HTMLElement |

Called only internally, overrides GridLayer's createTile() to return an `` HTML element with the appropriate image URL given coords. The done callback is called when the tile has been loaded.

|

▶ Methods inherited from GridLayer

MethodReturnsDescription
bringToFront()this

Brings the tile layer to the top of all tile layers.

| | bringToBack() | this |

Brings the tile layer to the bottom of all tile layers.

| | getContainer() | HTMLElement |

Returns the HTML element that contains the tiles for this layer.

| | setOpacity(<Number> opacity) | this |

Changes the opacity of the grid layer.

| | setZIndex(<Number> zIndex) | this |

Changes the zIndex of the grid layer.

| | isLoading() | Boolean |

Returns true if any tile in the grid layer has not finished loading.

| | redraw() | this |

Causes the layer to clear all the tiles and request them again.

| | getTileSize() | Point |

Normalizes the tileSize option into a point. Used by the createTile() method.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

ImageOverlay

Used to load and display a single image over specific bounds of the map. Extends Layer.

Usage example

const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
	imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
new ImageOverlay(imageUrl, imageBounds).addTo(map);

Constructor

ConstructorDescription
new ImageOverlay(<String> imageUrl, <LatLngBounds> bounds, <ImageOverlay options> options?)Instantiates an image overlay object given the URL of the image and the geographical bounds it is tied to.

Options

OptionTypeDefaultDescription
opacityNumber1.0The opacity of the image overlay.
altString''Text for the alt attribute of the image (useful for accessibility).
interactiveBooleanfalseIf true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin`BooleanString`false
errorOverlayUrlString''URL to the overlay image to show in place of the overlay that failed to load.
zIndexNumber1The explicit zIndex of the overlay layer.
classNameString''A custom class name to assign to the image. Empty by default.
decodingString'auto'Tells the browser whether to decode the image in a synchronous fashion, as per the decoding HTML attribute. If the image overlay is flickering when being added/removed, set this option to 'sync'.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
loadEventFired when the ImageOverlay layer has loaded its image
errorEventFired when the ImageOverlay layer fails to load its image

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setOpacity(<Number> opacity)this

Sets the opacity of the overlay.

| | bringToFront() | this |

Brings the layer to the top of all overlays.

| | bringToBack() | this |

Brings the layer to the bottom of all overlays.

| | setUrl(<String> url) | this |

Changes the URL of the image.

| | setBounds(<LatLngBounds> bounds) | this |

Update the bounds that this ImageOverlay covers

| | setZIndex(<Number> value) | this |

Changes the zIndex of the image overlay.

| | getBounds() | LatLngBounds |

Get the bounds that this ImageOverlay covers

| | getElement() | HTMLElement |

Returns the instance of HTMLImageElement used by this overlay.

| | getCenter() | LatLng |

Returns the center of the ImageOverlay.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

VideoOverlay

Used to load and display a video player over specific bounds of the map. Extends ImageOverlay.

A video overlay uses the <video> HTML element.

Usage example

const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',
	videoBounds = [[32, -130], [13, -100]];
new VideoOverlay(videoUrl, videoBounds ).addTo(map);

Constructor

ConstructorDescription
`new VideoOverlay(<StringArray

Options

OptionTypeDefaultDescription
autoplayBooleantrueWhether the video starts playing automatically when loaded. On some browsers autoplay will only work with muted: true
loopBooleanfalseWhether the browser will offer controls to allow the user to control video playback, including volume, seeking, and pause/resume playback. Whether the video will loop back to the beginning when played.
keepAspectRatioBooleantrueWhether the video will save aspect ratio after the projection.
mutedBooleanfalseWhether the video starts on mute when loaded.
playsInlineBooleantrueMobile browsers will play the video right where it is instead of open it up in fullscreen mode.

▶ Options inherited from ImageOverlay

OptionTypeDefaultDescription
opacityNumber1.0The opacity of the image overlay.
altString''Text for the alt attribute of the image (useful for accessibility).
interactiveBooleanfalseIf true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin`BooleanString`false
errorOverlayUrlString''URL to the overlay image to show in place of the overlay that failed to load.
zIndexNumber1The explicit zIndex of the overlay layer.
classNameString''A custom class name to assign to the image. Empty by default.
decodingString'auto'Tells the browser whether to decode the image in a synchronous fashion, as per the decoding HTML attribute. If the image overlay is flickering when being added/removed, set this option to 'sync'.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
loadEventFired when the video has finished loading the first frame

▶ Events inherited from ImageOverlay

EventDataDescription
errorEventFired when the ImageOverlay layer fails to load its image

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
getElement()HTMLVideoElement

Returns the instance of HTMLVideoElement used by this overlay.

|

▶ Methods inherited from ImageOverlay

MethodReturnsDescription
setOpacity(<Number> opacity)this

Sets the opacity of the overlay.

| | bringToFront() | this |

Brings the layer to the top of all overlays.

| | bringToBack() | this |

Brings the layer to the bottom of all overlays.

| | setUrl(<String> url) | this |

Changes the URL of the image.

| | setBounds(<LatLngBounds> bounds) | this |

Update the bounds that this ImageOverlay covers

| | setZIndex(<Number> value) | this |

Changes the zIndex of the image overlay.

| | getBounds() | LatLngBounds |

Get the bounds that this ImageOverlay covers

| | getCenter() | LatLng |

Returns the center of the ImageOverlay.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

SVGOverlay

Used to load, display and provide DOM access to an SVG file over specific bounds of the map. Extends ImageOverlay.

An SVG overlay uses the <svg> element.

Usage example

const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', "0 0 200 200");
svgElement.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>';
const svgElementBounds = [[ 32, -130], [13, -100] ];
new SVGOverlay(svgElement, svgElementBounds).addTo(map);

Constructor

ConstructorDescription
`new SVGOverlay(<StringSVGElement> svg, <LatLngBounds> bounds, <SVGOverlay options> options?)`

Options

▶ Options inherited from ImageOverlay

OptionTypeDefaultDescription
opacityNumber1.0The opacity of the image overlay.
altString''Text for the alt attribute of the image (useful for accessibility).
interactiveBooleanfalseIf true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin`BooleanString`false
errorOverlayUrlString''URL to the overlay image to show in place of the overlay that failed to load.
zIndexNumber1The explicit zIndex of the overlay layer.
classNameString''A custom class name to assign to the image. Empty by default.
decodingString'auto'Tells the browser whether to decode the image in a synchronous fashion, as per the decoding HTML attribute. If the image overlay is flickering when being added/removed, set this option to 'sync'.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from ImageOverlay

EventDataDescription
loadEventFired when the ImageOverlay layer has loaded its image
errorEventFired when the ImageOverlay layer fails to load its image

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
getElement()SVGElement

Returns the instance of SVGElement used by this overlay.

|

▶ Methods inherited from ImageOverlay

MethodReturnsDescription
setOpacity(<Number> opacity)this

Sets the opacity of the overlay.

| | bringToFront() | this |

Brings the layer to the top of all overlays.

| | bringToBack() | this |

Brings the layer to the bottom of all overlays.

| | setUrl(<String> url) | this |

Changes the URL of the image.

| | setBounds(<LatLngBounds> bounds) | this |

Update the bounds that this ImageOverlay covers

| | setZIndex(<Number> value) | this |

Changes the zIndex of the image overlay.

| | getBounds() | LatLngBounds |

Get the bounds that this ImageOverlay covers

| | getCenter() | LatLng |

Returns the center of the ImageOverlay.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Path

An abstract class that contains options and constants shared between vector overlays (Polygon, Polyline, Circle). Do not use it directly. Extends Layer.

Options

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Polyline

A class for drawing polyline overlays on a map. Extends Path.

Usage example

// create a red polyline from an array of LatLng points
const latlngs = [
	[45.51, -122.68],
	[37.77, -122.43],
	[34.04, -118.2]
];

const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);

// zoom the map to the polyline
map.fitBounds(polyline.getBounds());

You can also pass a multi-dimensional array to represent a MultiPolyline shape:

// create a red polyline from an array of arrays of LatLng points
const latlngs = [
	[[45.51, -122.68],
	 [37.77, -122.43],
	 [34.04, -118.2]],
	[[40.78, -73.91],
	 [41.83, -87.62],
	 [32.76, -96.72]]
];

Constructor

ConstructorDescription
new Polyline(<LatLng[]> latlngs, <Polyline options> options?)Instantiates a polyline object given an array of geographical points and optionally an options object. You can create a Polyline object with multiple separate lines (MultiPolyline) by passing an array of arrays of geographic points.

Options

OptionTypeDefaultDescription
smoothFactorNumber1.0How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation.
noClipBooleanfalseDisable polyline clipping.

▶ Options inherited from Path

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the polyline (as a GeoJSON LineString or MultiLineString Feature).

| | getLatLngs() | LatLng[] |

Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.

| | setLatLngs(<LatLng[]> latlngs) | this |

Replaces all the points in the polyline with the given array of geographical points.

| | isEmpty() | Boolean |

Returns true if the Polyline has no LatLngs.

| | closestLayerPoint(<Point> p) | Point |

Returns the point closest to p on the Polyline.

| | getCenter() | LatLng |

Returns the center (centroid) of the polyline.

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the path.

| | addLatLng(<LatLng> latlng, <LatLng[]> latlngs?) | this |

Adds a given point to the polyline. By default, adds to the first ring of the polyline in case of a multi-polyline, but can be overridden by passing a specific ring as a LatLng array (that you can earlier access with getLatLngs).

|

▶ Methods inherited from Path

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Polygon

A class for drawing polygon overlays on a map. Extends Polyline.

Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.

Usage example

// create a red polygon from an array of LatLng points
const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];

const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);

// zoom the map to the polygon
map.fitBounds(polygon.getBounds());

You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing holes in the outer shape:

const latlngs = [
  [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
  [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
];

Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.

const latlngs = [
  [ // first polygon
    [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
    [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
  ],
  [ // second polygon
    [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
  ]
];

Constructor

ConstructorDescription
new Polygon(<LatLng[]> latlngs, <Polyline options> options?)

Options

▶ Options inherited from Polyline

OptionTypeDefaultDescription
smoothFactorNumber1.0How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation.
noClipBooleanfalseDisable polyline clipping.

▶ Options inherited from Path

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).

| | getCenter() | LatLng |

Returns the center (centroid) of the Polygon.

|

▶ Methods inherited from Polyline

MethodReturnsDescription
getLatLngs()LatLng[]

Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.

| | setLatLngs(<LatLng[]> latlngs) | this |

Replaces all the points in the polyline with the given array of geographical points.

| | isEmpty() | Boolean |

Returns true if the Polyline has no LatLngs.

| | closestLayerPoint(<Point> p) | Point |

Returns the point closest to p on the Polyline.

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the path.

| | addLatLng(<LatLng> latlng, <LatLng[]> latlngs?) | this |

Adds a given point to the polyline. By default, adds to the first ring of the polyline in case of a multi-polyline, but can be overridden by passing a specific ring as a LatLng array (that you can earlier access with getLatLngs).

|

▶ Methods inherited from Path

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Rectangle

A class for drawing rectangle overlays on a map. Extends Polygon.

Usage example

// define rectangle geographical bounds
const bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]];

// create an orange rectangle
new Rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);

// zoom the map to the rectangle bounds
map.fitBounds(bounds);

Constructor

ConstructorDescription
new Rectangle(<LatLngBounds> latLngBounds, <Polyline options> options?)

Options

▶ Options inherited from Polyline

OptionTypeDefaultDescription
smoothFactorNumber1.0How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation.
noClipBooleanfalseDisable polyline clipping.

▶ Options inherited from Path

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setBounds(<LatLngBounds> latLngBounds)this

Redraws the rectangle with the passed bounds.

|

▶ Methods inherited from Polygon

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).

| | getCenter() | LatLng |

Returns the center (centroid) of the Polygon.

|

▶ Methods inherited from Polyline

MethodReturnsDescription
getLatLngs()LatLng[]

Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.

| | setLatLngs(<LatLng[]> latlngs) | this |

Replaces all the points in the polyline with the given array of geographical points.

| | isEmpty() | Boolean |

Returns true if the Polyline has no LatLngs.

| | closestLayerPoint(<Point> p) | Point |

Returns the point closest to p on the Polyline.

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the path.

| | addLatLng(<LatLng> latlng, <LatLng[]> latlngs?) | this |

Adds a given point to the polyline. By default, adds to the first ring of the polyline in case of a multi-polyline, but can be overridden by passing a specific ring as a LatLng array (that you can earlier access with getLatLngs).

|

▶ Methods inherited from Path

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Circle

A class for drawing circle overlays on a map. Extends CircleMarker.

It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion).

Usage example

new Circle([50.5, 30.5], {radius: 200}).addTo(map);

Constructor

ConstructorDescription
new Circle(<LatLng> latlng, <Circle options> options?)Instantiates a circle object given a geographical point, and an options object which contains the circle radius.

Options

OptionTypeDefaultDescription
radiusNumber``Radius of the circle, in meters.

▶ Options inherited from Path

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from CircleMarker

EventDataDescription
moveEventFired when the marker is moved via setLatLng. Old and new coordinates are included in event arguments as oldLatLng, latlng.

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setRadius(<Number> radius)this

Sets the radius of a circle. Units are in meters.

| | getRadius() | Number |

Returns the current radius of a circle. Units are in meters.

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the path.

|

▶ Methods inherited from CircleMarker

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the circle marker (as a GeoJSON Point Feature).

| | setLatLng(<LatLng> latLng) | this |

Sets the position of a circle marker to a new location.

| | getLatLng() | LatLng |

Returns the current geographical position of the circle marker

|

▶ Methods inherited from Path

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

CircleMarker

A circle of a fixed size with radius specified in pixels. Extends Path.

Constructor

ConstructorDescription
new CircleMarker(<LatLng> latlng, <CircleMarker options> options?)Instantiates a circle marker object given a geographical point, and an optional options object.

Options

OptionTypeDefaultDescription
radiusNumber10Radius of the circle marker, in pixels

▶ Options inherited from Path

OptionTypeDefaultDescription
strokeBooleantrueWhether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
colorString'#3388ff'Stroke color
weightNumber3Stroke width in pixels
opacityNumber1.0Stroke opacity
lineCapString'round'A string that defines shape to be used at the end of the stroke.
lineJoinString'round'A string that defines shape to be used at the corners of the stroke.
dashArrayStringnullA string that defines the stroke dash pattern.
dashOffsetStringnullA string that defines the distance into the dash pattern to start the dash.
fillBooleandependsWhether to fill the path with color. Set it to false to disable filling on polygons or circles.
fillColorString*Fill color. Defaults to the value of the color option
fillOpacityNumber0.2Fill opacity.
fillRuleString'evenodd'A string that defines how the inside of a shape is determined.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this path will trigger the same event on the map (unless DomEvent.stopPropagation is used).
rendererRenderer``Use this specific instance of Renderer for this path. Takes precedence over the map's default renderer. If set, it will override the pane option of the path.
classNameStringnullCustom class name set on an element. Only for SVG renderer.

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
moveEventFired when the marker is moved via setLatLng. Old and new coordinates are included in event arguments as oldLatLng, latlng.

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the circle marker (as a GeoJSON Point Feature).

| | setLatLng(<LatLng> latLng) | this |

Sets the position of a circle marker to a new location.

| | getLatLng() | LatLng |

Returns the current geographical position of the circle marker

| | setRadius(<Number> radius) | this |

Sets the radius of a circle marker. Units are in pixels.

| | getRadius() | Number |

Returns the current radius of the circle

|

▶ Methods inherited from Path

MethodReturnsDescription
redraw()this

Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.

| | setStyle(<Path options> style) | this |

Changes the appearance of a Path based on the options in the Path options object.

| | bringToFront() | this |

Brings the layer to the top of all path layers.

| | bringToBack() | this |

Brings the layer to the bottom of all path layers.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

SVG

Allows vector layers to be displayed with SVG. Inherits Renderer.

Usage example

Use SVG by default for all paths in the map:

const map = new Map('map', {
	renderer: new SVG()
});

Use a SVG renderer with extra padding for specific vector geometries:

const map = new Map('map');
const myRenderer = new SVG({ padding: 0.5 });
const line = new Polyline( coordinates, { renderer: myRenderer } );
const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );

Constructor

ConstructorDescription
new SVG(<Renderer options> options?)Creates a SVG renderer with the given options.

Options

▶ Options inherited from BlanketOverlay

OptionTypeDefaultDescription
paddingNumber0.1How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction
continuousBooleanfalseWhen false, the blanket will update its position only when the map state settles (after a pan/zoom animation). When true, it will update when the map state changes (during pan/zoom animations)

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from Renderer

EventDataDescription
updateEventFired when the renderer updates its bounds, center and zoom, for example when its map has moved

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Functions

There are several static functions which can be called without instantiating SVG:

FunctionReturnsDescription
create(<String> name)SVGElementReturns a instance of SVGElement, corresponding to the class name passed. For example, using 'line' will return an instance of SVGLineElement.
pointsToPath(<Point[]> rings, <Boolean> closed)StringGenerates a SVG path string for multiple rings, with each ring turning into "M..L..L.." instructions

Canvas

Allows vector layers to be displayed with <canvas>. Inherits Renderer.

Usage example

Use Canvas by default for all paths in the map:

const map = new Map('map', {
	renderer: new Canvas()
});

Use a Canvas renderer with extra padding for specific vector geometries:

const map = new Map('map');
const myRenderer = new Canvas({ padding: 0.5 });
const line = new Polyline( coordinates, { renderer: myRenderer } );
const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );

Constructor

ConstructorDescription
new Canvas(<Renderer options> options?)Creates a Canvas renderer with the given options.

Options

OptionTypeDefaultDescription
toleranceNumber0How much to extend the click tolerance around a path/object on the map.

▶ Options inherited from BlanketOverlay

OptionTypeDefaultDescription
paddingNumber0.1How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction
continuousBooleanfalseWhen false, the blanket will update its position only when the map state settles (after a pan/zoom animation). When true, it will update when the map state changes (during pan/zoom animations)

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from Renderer

EventDataDescription
updateEventFired when the renderer updates its bounds, center and zoom, for example when its map has moved

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

LayerGroup

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.

Usage example

new LayerGroup([marker1, marker2])
	.addLayer(polyline)
	.addTo(map);

Constructor

ConstructorDescription
new LayerGroup(<Layer[]> layers?, <Object> options?)Create a layer group, optionally given an initial set of layers and an options object.

Options

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).

| | addLayer(<Layer> layer) | this |

Adds the given layer to the group.

| | removeLayer(<Layer> layer) | this |

Removes the given layer from the group.

| | removeLayer(<Number> id) | this |

Removes the layer with the given internal ID from the group.

| | hasLayer(<Layer> layer) | Boolean |

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

| | hasLayer(<Number> id) | Boolean |

Returns true if the given internal ID is currently added to the group.

| | clearLayers() | this |

Removes all the layers from the group.

| | invoke(<String> methodName, …) | 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.

| | eachLayer(<Function> fn, <Object> context?) | this |

Iterates over the layers of the group, optionally specifying context of the iterator function.

group.eachLayer(layer => layer.bindPopup('Hello'));

| | getLayer(<Number> id) | Layer |

Returns the layer with the given internal ID.

| | getLayers() | Layer[] |

Returns an array of all the layers added to the group.

| | setZIndex(<Number> zIndex) | this |

Calls setZIndex on every layer contained in this group, passing the z-index.

| | getLayerId(<Layer> layer) | Number |

Returns the internal ID for a layer

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

FeatureGroup

Extended LayerGroup that makes it easier to do the same thing to all its member layers:

  • bindPopup binds a popup to all of the layers at once (likewise with bindTooltip)
  • Events are propagated to the FeatureGroup, so if the group has an event handler, it will handle events from any of the layers. This includes pointer events and custom events.
  • Has layeradd and layerremove events

Usage example

new FeatureGroup([marker1, marker2, polyline])
	.bindPopup('Hello world!')
	.on('click', function() { alert('Clicked on a member of the group!'); })
	.addTo(map);

Constructor

ConstructorDescription
new FeatureGroup(<Layer[]> layers?, <Object> options?)Create a feature group, optionally given an initial set of layers and an options object.

Options

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
layeraddLayerEventFired when a layer is added to this FeatureGroup
layerremoveLayerEventFired when a layer is removed from this FeatureGroup

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
setStyle(<Path options> style)this

Sets the given path options to each layer of the group that has a setStyle method.

| | bringToFront() | this |

Brings the layer group to the top of all other layers

| | bringToBack() | this |

Brings the layer group to the back of all other layers

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).

|

▶ Methods inherited from LayerGroup

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).

| | addLayer(<Layer> layer) | this |

Adds the given layer to the group.

| | removeLayer(<Layer> layer) | this |

Removes the given layer from the group.

| | removeLayer(<Number> id) | this |

Removes the layer with the given internal ID from the group.

| | hasLayer(<Layer> layer) | Boolean |

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

| | hasLayer(<Number> id) | Boolean |

Returns true if the given internal ID is currently added to the group.

| | clearLayers() | this |

Removes all the layers from the group.

| | invoke(<String> methodName, …) | 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.

| | eachLayer(<Function> fn, <Object> context?) | this |

Iterates over the layers of the group, optionally specifying context of the iterator function.

group.eachLayer(layer => layer.bindPopup('Hello'));

| | getLayer(<Number> id) | Layer |

Returns the layer with the given internal ID.

| | getLayers() | Layer[] |

Returns an array of all the layers added to the group.

| | setZIndex(<Number> zIndex) | this |

Calls setZIndex on every layer contained in this group, passing the z-index.

| | getLayerId(<Layer> layer) | Number |

Returns the internal ID for a layer

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

GeoJSON

Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup.

Usage example

new GeoJSON(data, {
	style: function (feature) {
		return {color: feature.properties.color};
	}
}).bindPopup(function (layer) {
	return layer.feature.properties.description;
}).addTo(map);

Constructor

ConstructorDescription
new GeoJSON(<Object> geojson?, <GeoJSON options> options?)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.

Options

OptionTypeDefaultDescription
pointToLayerFunction*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 new Marker(latlng);
}

| | style | Function | * | 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 {}
}

| | onEachFeature | Function | * | 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) {}

| | filter | Function | * | A Function that will be used to decide whether to include a feature or not. The default is to include all features:

function (geoJsonFeature) {
	return true;
}

Note: dynamically changing the filter option will have effect only on newly added data. It will not re-evaluate already included features.

| | coordsToLatLng | Function | * | A Function that will be used for converting GeoJSON coordinates to LatLngs. The default is the coordsToLatLng static method. | | markersInheritOptions | Boolean | false | Whether default Markers for "Point" type Features inherit from group options. |

▶ Options inherited from Interactive layer

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from FeatureGroup

EventDataDescription
layeraddLayerEventFired when a layer is added to this FeatureGroup
layerremoveLayerEventFired when a layer is removed from this FeatureGroup

▶ Pointer events inherited from Interactive layer

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
addData(data)this

Adds a GeoJSON object to the layer.

| | resetStyle(layer?) | this |

Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events. If layer is omitted, the style of all features in the current layer is reset.

| | setStyle(style) | this |

Changes styles of GeoJSON vector layers with the given style function.

|

▶ Methods inherited from FeatureGroup

MethodReturnsDescription
bringToFront()this

Brings the layer group to the top of all other layers

| | bringToBack() | this |

Brings the layer group to the back of all other layers

| | getBounds() | LatLngBounds |

Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).

|

▶ Methods inherited from LayerGroup

MethodReturnsDescription
`toGeoJSON(<Numberfalse> precision?)`Object

Coordinates values are rounded with formatNum function with given precision. Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).

| | addLayer(<Layer> layer) | this |

Adds the given layer to the group.

| | removeLayer(<Layer> layer) | this |

Removes the given layer from the group.

| | removeLayer(<Number> id) | this |

Removes the layer with the given internal ID from the group.

| | hasLayer(<Layer> layer) | Boolean |

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

| | hasLayer(<Number> id) | Boolean |

Returns true if the given internal ID is currently added to the group.

| | clearLayers() | this |

Removes all the layers from the group.

| | invoke(<String> methodName, …) | 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.

| | eachLayer(<Function> fn, <Object> context?) | this |

Iterates over the layers of the group, optionally specifying context of the iterator function.

group.eachLayer(layer => layer.bindPopup('Hello'));

| | getLayer(<Number> id) | Layer |

Returns the layer with the given internal ID.

| | getLayers() | Layer[] |

Returns an array of all the layers added to the group.

| | setZIndex(<Number> zIndex) | this |

Calls setZIndex on every layer contained in this group, passing the z-index.

| | getLayerId(<Layer> layer) | Number |

Returns the internal ID for a layer

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Functions

There are several static functions which can be called without instantiating GeoJSON:

FunctionReturnsDescription
geometryToLayer(<Object> featureData, <GeoJSON options> options?)LayerCreates a Layer from a given GeoJSON feature. Can use a custom pointToLayer and/or coordsToLatLng functions if provided as options.
coordsToLatLng(<Array> coords)LatLngCreates a LatLng object from an array of 2 numbers (longitude, latitude) or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.
coordsToLatLngs(<Array> coords, <Number> levelsDeep?, <Function> coordsToLatLng?)ArrayCreates 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.
`latLngToCoords(<LatLng> latlng, <Numberfalse> precision?)`Array
`latLngsToCoords(<Array> latlngs, <Number> levelsDeep?, <Boolean> close?, <Numberfalse> precision?)`Array
asFeature(<Object> geojson)ObjectNormalize GeoJSON geometries/features into GeoJSON features.

GridLayer

Generic class for handling a tiled grid of HTML elements. This is the base class for all tile layers and replaces TileLayer.Canvas. GridLayer can be extended to create a tiled grid of HTML elements like <canvas>, `` or <div>. GridLayer will handle creating and animating these DOM elements for you.

Usage example

Synchronous usage

To create a custom layer, extend GridLayer and implement the createTile() method, which will be passed a Point object with the x, y, and z (zoom level) coordinates to draw your tile.

const CanvasLayer = GridLayer.extend({
    createTile: function(coords){
        // create a <canvas> element for drawing
        const tile = DomUtil.create('canvas', 'leaflet-tile');

        // setup tile width and height according to the options
        const size = this.getTileSize();
        tile.width = size.x;
        tile.height = size.y;

        // get a canvas context and draw something on it using coords.x, coords.y and coords.z
        const ctx = tile.getContext('2d');

        // return the tile so it can be rendered on screen
        return tile;
    }
});

Asynchronous usage

Tile creation can also be asynchronous, this is useful when using a third-party drawing library. Once the tile is finished drawing it can be passed to the done() callback.

const CanvasLayer = GridLayer.extend({
    createTile: function(coords, done){
        const error;

        // create a <canvas> element for drawing
        const tile = DomUtil.create('canvas', 'leaflet-tile');

        // setup tile width and height according to the options
        const size = this.getTileSize();
        tile.width = size.x;
        tile.height = size.y;

        // draw something asynchronously and pass the tile to the done() callback
        setTimeout(function() {
            done(error, tile);
        }, 1000);

        return tile;
    }
});

Constructor

ConstructorDescription
new GridLayer(<GridLayer options> options?)Creates a new instance of GridLayer with the supplied options.

Options

OptionTypeDefaultDescription
tileSize`NumberPoint`256
opacityNumber1.0Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdleBoolean(depends)Load new tiles only when panning ends. true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation. false otherwise in order to display new tiles during panning, since it is easy to pan outside the keepBuffer option in desktop browsers.
updateWhenZoomingBooleantrueBy default, a smooth zoom animation (during a pinch zoom or a flyTo()) will update grid layers every integer zoom level. Setting this option to false will update the grid layer only when the smooth animation ends.
updateIntervalNumber200Tiles will not update more than once every updateInterval milliseconds when panning.
zIndexNumber1The explicit zIndex of the tile layer.
boundsLatLngBoundsundefinedIf set, tiles will only be loaded inside the set LatLngBounds.
minZoomNumber0The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoomNumberundefinedThe maximum zoom level up to which this layer will be displayed (inclusive).
maxNativeZoomNumberundefinedMaximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than maxNativeZoom will be loaded from maxNativeZoom level and auto-scaled.
minNativeZoomNumberundefinedMinimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than minNativeZoom will be loaded from minNativeZoom level and auto-scaled.
noWrapBooleanfalseWhether the layer is wrapped around the antimeridian. If true, the GridLayer will only be displayed once at low zoom levels. Has no effect when the map CRS doesn't wrap around. Can be used in combination with bounds to prevent requesting tiles outside the CRS limits.
paneString'tilePane'Map pane where the grid layer will be added.
classNameString''A custom class name to assign to the tile layer. Empty by default.
keepBufferNumber2When panning the map, keep this many rows and columns of tiles before unloading them.

▶ Options inherited from Layer

OptionTypeDefaultDescription
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
loadingEventFired when the grid layer starts loading tiles.
tileunloadTileEventFired when a tile is removed (e.g. when a tile goes off the screen).
tileloadstartTileEventFired when a tile is requested and starts loading.
tileerrorTileErrorEventFired when there is an error loading a tile.
tileloadTileEventFired when a tile loads.
loadEventFired when the grid layer loaded all visible tiles.

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

MethodReturnsDescription
bringToFront()this

Brings the tile layer to the top of all tile layers.

| | bringToBack() | this |

Brings the tile layer to the bottom of all tile layers.

| | getContainer() | HTMLElement |

Returns the HTML element that contains the tiles for this layer.

| | setOpacity(<Number> opacity) | this |

Changes the opacity of the grid layer.

| | setZIndex(<Number> zIndex) | this |

Changes the zIndex of the grid layer.

| | isLoading() | Boolean |

Returns true if any tile in the grid layer has not finished loading.

| | redraw() | this |

Causes the layer to clear all the tiles and request them again.

| | getTileSize() | Point |

Normalizes the tileSize option into a point. Used by the createTile() method.

|

Extension methods

Layers extending GridLayer shall reimplement the following method.

MethodReturnsDescription
createTile(<Object> coords, <Function> done?)HTMLElement

Called only internally, must be overridden by classes extending GridLayer. Returns the HTMLElement corresponding to the given coords. If the done callback is specified, it must be called when the tile has finished loading and drawing.

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

LatLng

Represents a geographical point with a certain latitude and longitude.

Usage example

const latlng = new LatLng(50.5, 30.5);

All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:

map.panTo([50, 30]);
map.panTo({lat: 50, lng: 30});
map.panTo({lat: 50, lon: 30});
map.panTo(new LatLng(50, 30));

Note that LatLng does not inherit from Leaflet's Class object, which means new classes can't inherit from it, and new methods can't be added to it with the include function.

Constructor

ConstructorDescription
new LatLng(<Number> latitude, <Number> longitude, <Number> altitude?)Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).
new LatLng(<Array> coords)Expects an array of the form [Number, Number] or [Number, Number, Number] instead.
new LatLng(<Object> coords)Expects an plain object of the form {lat: Number, lng: Number} or {lat: Number, lng: Number, alt: Number} instead. You can also use lon in place of lng in the object form.

Methods

MethodReturnsDescription
equals(<LatLng> otherLatLng, <Number> maxMargin?)Boolean

Returns true if the given LatLng point is at the same position (within a small margin of error). The margin of error can be overridden by setting maxMargin to a small number.

| | toString() | String |

Returns a string representation of the point (for debugging purposes).

| | distanceTo(<LatLng> otherLatLng) | Number |

Returns the distance (in meters) to the given LatLng calculated using the Spherical Law of Cosines.

| | wrap() | LatLng |

Returns a new LatLng object with the longitude wrapped so it's always between -180 and +180 degrees.

| | toBounds(<Number> sizeInMeters) | LatLngBounds |

Returns a new LatLngBounds object in which each boundary is sizeInMeters/2 meters apart from the LatLng.

| | clone() | LatLng |

Returns a copy of the current LatLng.

|

Functions

There are several static functions which can be called without instantiating LatLng:

FunctionReturnsDescription
validate(<Number> latitude, <Number> longitude, <Number> altitude?)BooleanReturns true if the LatLng object can be properly initialized.
validate(<Array> coords)BooleanExpects an array of the form [Number, Number] or [Number, Number, Number]. Returns true if the LatLng object can be properly initialized.
validate(<Object> coords)BooleanReturns true if the LatLng object can be properly initialized.

Properties

PropertyTypeDescription
latNumberLatitude in degrees
lngNumberLongitude in degrees
altNumberAltitude in meters (optional)

LatLngBounds

Represents a rectangular geographical area on a map.

Usage example

const corner1 = new LatLng(40.712, -74.227),
corner2 = new LatLng(40.774, -74.125),
bounds = new LatLngBounds(corner1, corner2);

All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:

map.fitBounds([
	[40.712, -74.227],
	[40.774, -74.125]
]);

Caution: if the area crosses the antimeridian (often confused with the International Date Line), you must specify corners outside the [-180, 180] degrees longitude range.

Note that LatLngBounds does not inherit from Leaflet's Class object, which means new classes can't inherit from it, and new methods can't be added to it with the include function.

Constructor

ConstructorDescription
new LatLngBounds(<LatLng> corner1, <LatLng> corner2)Creates a LatLngBounds object by defining two diagonally opposite corners of the rectangle.
new LatLngBounds(<LatLng[]> latlngs)Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds.

Methods

MethodReturnsDescription
extend(<LatLng> latlng)this

Extend the bounds to contain the given point

| | extend(<LatLngBounds> otherBounds) | this |

Extend the bounds to contain the given bounds

| | pad(<Number> bufferRatio) | LatLngBounds |

Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds.

| | getCenter() | LatLng |

Returns the center point of the bounds.

| | getSouthWest() | LatLng |

Returns the south-west point of the bounds.

| | getNorthEast() | LatLng |

Returns the north-east point of the bounds.

| | getNorthWest() | LatLng |

Returns the north-west point of the bounds.

| | getSouthEast() | LatLng |

Returns the south-east point of the bounds.

| | getWest() | Number |

Returns the west longitude of the bounds

| | getSouth() | Number |

Returns the south latitude of the bounds

| | getEast() | Number |

Returns the east longitude of the bounds

| | getNorth() | Number |

Returns the north latitude of the bounds

| | contains(<LatLngBounds> otherBounds) | Boolean |

Returns true if the rectangle contains the given one.

| | contains(<LatLng> latlng) | Boolean |

Returns true if the rectangle contains the given point.

| | intersects(<LatLngBounds> otherBounds) | Boolean |

Returns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.

| | overlaps(<LatLngBounds> otherBounds) | Boolean |

Returns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.

| | toBBoxString() | String |

Returns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data.

| | equals(<LatLngBounds> otherBounds, <Number> maxMargin?) | Boolean |

Returns true if the rectangle is equivalent (within a small margin of error) to the given bounds. The margin of error can be overridden by setting maxMargin to a small number.

| | isValid() | Boolean |

Returns true if the bounds are properly initialized.

|

Point

Represents a point with x and y coordinates in pixels.

Usage example

const point = new Point(200, 300);

All Leaflet methods and options that accept Point objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:

map.panBy([200, 300]);
map.panBy(new Point(200, 300));

Note that Point does not inherit from Leaflet's Class object, which means new classes can't inherit from it, and new methods can't be added to it with the include function.

Constructor

ConstructorDescription
new Point(<Number> x, <Number> y, <Boolean> round?)Creates a Point object with the given x and y coordinates. If optional round is set to true, rounds the x and y values.
new Point(<Number[]> coords)Expects an array of the form [x, y] instead.
new Point(<Object> coords)Expects a plain object of the form {x: Number, y: Number} instead.

Methods

MethodReturnsDescription
clone()Point

Returns a copy of the current point.

| | add(<Point> otherPoint) | Point |

Returns the result of addition of the current and the given points.

| | subtract(<Point> otherPoint) | Point |

Returns the result of subtraction of the given point from the current.

| | divideBy(<Number> num) | Point |

Returns the result of division of the current point by the given number.

| | multiplyBy(<Number> num) | Point |

Returns the result of multiplication of the current point by the given number.

| | scaleBy(<Point> scale) | Point |

Multiply each coordinate of the current point by each coordinate of scale. In linear algebra terms, multiply the point by the scaling matrix defined by scale.

| | unscaleBy(<Point> scale) | Point |

Inverse of scaleBy. Divide each coordinate of the current point by each coordinate of scale.

| | floor() | Point |

Returns a copy of the current point with floored coordinates (rounded down).

| | ceil() | Point |

Returns a copy of the current point with ceiled coordinates (rounded up).

| | distanceTo(<Point> otherPoint) | Number |

Returns the cartesian distance between the current and the given points.

| | equals(<Point> otherPoint) | Boolean |

Returns true if the given point has the same coordinates.

| | contains(<Point> otherPoint) | Boolean |

Returns true if both coordinates of the given point are less than the corresponding current point coordinates (in absolute values).

| | toString() | String |

Returns a string representation of the point for debugging purposes.

|

Functions

There are several static functions which can be called without instantiating Point:

FunctionReturnsDescription
validate(<Number> x, <Number> y)BooleanReturns true if the Point object can be properly initialized.
validate(<Number[]> coords)BooleanExpects an array of the form [x, y]. Returns true if the Point object can be properly initialized.
validate(<Object> coords)BooleanReturns true if the Point object can be properly initialized.

Properties

PropertyTypeDescription
xNumberThe x coordinate of the point
yNumberThe y coordinate of the point

Bounds

Represents a rectangular area in pixel coordinates.

Usage example

const p1 = new Point(10, 10),
p2 = new Point(40, 60),
bounds = new Bounds(p1, p2);

All Leaflet methods that accept Bounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:

otherBounds.intersects([[10, 10], [40, 60]]);

Note that Bounds does not inherit from Leaflet's Class object, which means new classes can't inherit from it, and new methods can't be added to it with the include function.

Constructor

ConstructorDescription
new Bounds(<Point> corner1, <Point> corner2)Creates a Bounds object from two corners coordinate pairs.
new Bounds(<Point[]> points)Creates a Bounds object from the given array of points.

Methods

MethodReturnsDescription
extend(<Point> point)this

Extends the bounds to contain the given point.

| | extend(<Bounds> otherBounds) | this |

Extend the bounds to contain the given bounds

| | getCenter(<Boolean> round?) | Point |

Returns the center point of the bounds.

| | getBottomLeft() | Point |

Returns the bottom-left point of the bounds.

| | getTopRight() | Point |

Returns the top-right point of the bounds.

| | getTopLeft() | Point |

Returns the top-left point of the bounds (i.e. this.min).

| | getBottomRight() | Point |

Returns the bottom-right point of the bounds (i.e. this.max).

| | getSize() | Point |

Returns the size of the given bounds

| | contains(<Bounds> otherBounds) | Boolean |

Returns true if the rectangle contains the given one.

| | contains(<Point> point) | Boolean |

Returns true if the rectangle contains the given point.

| | intersects(<Bounds> otherBounds) | Boolean |

Returns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.

| | overlaps(<Bounds> otherBounds) | Boolean |

Returns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.

| | isValid() | Boolean |

Returns true if the bounds are properly initialized.

| | pad(<Number> bufferRatio) | Bounds |

Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds.

| | equals(<Bounds> otherBounds) | Boolean |

Returns true if the rectangle is equivalent to the given bounds.

|

Properties

PropertyTypeDescription
minPointThe top left corner of the rectangle.
maxPointThe bottom right corner of the rectangle.

Icon

Represents an icon to provide when creating a marker.

Usage example

const myIcon = new Icon({
    iconUrl: 'my-icon.png',
    iconSize: [38, 95],
    iconAnchor: [22, 94],
    popupAnchor: [-3, -76],
    shadowUrl: 'my-icon-shadow.png',
    shadowSize: [68, 95],
    shadowAnchor: [22, 94]
});

new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);

Icon.Default extends Icon and is the blue icon Leaflet uses for markers by default.

Constructor

ConstructorDescription
new Icon(<Icon options> options)Creates an icon instance with the given options.

Options

OptionTypeDefaultDescription
iconUrlStringnull(required) The URL to the icon image (absolute or relative to your script path).
iconRetinaUrlStringnullThe URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices.
iconSizePointnullSize of the icon image in pixels.
iconAnchorPointnullThe coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins.
popupAnchorPoint[0, 0]The coordinates of the point from which popups will "open", relative to the icon anchor.
tooltipAnchorPoint[0, 0]The coordinates of the point from which tooltips will "open", relative to the icon anchor.
shadowUrlStringnullThe URL to the icon shadow image. If not specified, no shadow image will be created.
shadowRetinaUrlStringnull
shadowSizePointnullSize of the shadow image in pixels.
shadowAnchorPointnullThe coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).
classNameString''A custom class name to assign to both icon and shadow images. Empty by default.
crossOrigin`BooleanString`false

Methods

MethodReturnsDescription
createIcon(<HTMLElement> oldIcon?)HTMLElement

Called internally when the icon has to be shown, returns a `` HTML element styled according to the options.

| | createShadow(<HTMLElement> oldIcon?) | HTMLElement |

As createIcon, but for the shadow beneath it.

|

Icon.Default

A trivial subclass of Icon, represents the icon to use in Markers when no icon is specified. Points to the blue marker image distributed with Leaflet releases.

In order to customize the default icon, just change the properties of Icon.Default.prototype.options (which is a set of Icon options).

If you want to completely replace the default icon, override the Marker.prototype.options.icon with your own icon instead.

OptionTypeDefaultDescription
imagePathString``Icon.Default will try to auto-detect the location of the blue icon images. If you are placing these images in a non-standard way, set this option to point to the right path.

DivIcon

Represents a lightweight icon for markers that uses a simple <div> element instead of an image. Inherits from Icon but ignores the iconUrl and shadow options.

Usage example

const myIcon = new DivIcon({className: 'my-div-icon'});
// you can set .my-div-icon styles in CSS

new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);

By default, it has a 'leaflet-div-icon' CSS class and is styled as a little white square with a shadow.

Constructor

ConstructorDescription
new DivIcon(<DivIcon options> options)Creates a DivIcon instance with the given options.

Options

OptionTypeDefaultDescription
html`StringHTMLElement`''
bgPosPoint[0, 0]Optional relative position of the background, in pixels

▶ Options inherited from Icon

OptionTypeDefaultDescription
iconUrlStringnull(required) The URL to the icon image (absolute or relative to your script path).
iconRetinaUrlStringnullThe URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices.
iconSizePointnullSize of the icon image in pixels.
iconAnchorPointnullThe coordinates of the "tip" of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker's geographical location. Centered by default if size is specified, also can be set in CSS with negative margins.
popupAnchorPoint[0, 0]The coordinates of the point from which popups will "open", relative to the icon anchor.
tooltipAnchorPoint[0, 0]The coordinates of the point from which tooltips will "open", relative to the icon anchor.
shadowUrlStringnullThe URL to the icon shadow image. If not specified, no shadow image will be created.
shadowRetinaUrlStringnull
shadowSizePointnullSize of the shadow image in pixels.
shadowAnchorPointnullThe coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).
classNameString''A custom class name to assign to both icon and shadow images. Empty by default.
crossOrigin`BooleanString`false

Methods

▶ Methods inherited from Icon

MethodReturnsDescription
createIcon(<HTMLElement> oldIcon?)HTMLElement

Called internally when the icon has to be shown, returns a `` HTML element styled according to the options.

| | createShadow(<HTMLElement> oldIcon?) | HTMLElement |

As createIcon, but for the shadow beneath it.

|

Control.Zoom

A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its zoomControl option to false. Extends Control.

Constructor

ConstructorDescription
new Control.Zoom(<Control.Zoom options> options)Creates a zoom control

Options

OptionTypeDefaultDescription
positionString'topleft'The position of the control (one of the map corners). Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'
zoomInTextString'<span aria-hidden="true">+</span>'The text set on the 'zoom in' button.
zoomInTitleString'Zoom in'The title set on the 'zoom in' button.
zoomOutTextString'<span aria-hidden="true">&#x2212;</span>'The text set on the 'zoom out' button.
zoomOutTitleString'Zoom out'The title set on the 'zoom out' button.

Methods

▶ Methods inherited from Control

MethodReturnsDescription
getPosition()string

Returns the position of the control.

| | setPosition(<string> position) | this |

Sets the position of the control.

| | getContainer() | HTMLElement |

Returns the HTMLElement that contains the control.

| | addTo(<Map> map) | this |

Adds the control to the given map.

| | remove() | this |

Removes the control from the map it is currently active on.

|

Control.Attribution

The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its attributionControl option to false, and it fetches attribution texts from layers with the getAttribution method automatically. Extends Control.

Constructor

ConstructorDescription
new Control.Attribution(<Control.Attribution options> options)Creates an attribution control.

Options

OptionTypeDefaultDescription
positionString'bottomright'The position of the control (one of the map corners). Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'
prefix`Stringfalse`'Leaflet'

Methods

MethodReturnsDescription
`setPrefix(<Stringfalse> prefix)`this

The HTML text shown before the attributions. Pass false to disable.

| | addAttribution(<String> text) | this |

Adds an attribution text (e.g. '&copy; OpenStreetMap contributors').

| | removeAttribution(<String> text) | this |

Removes an attribution text.

|

▶ Methods inherited from Control

MethodReturnsDescription
getPosition()string

Returns the position of the control.

| | setPosition(<string> position) | this |

Sets the position of the control.

| | getContainer() | HTMLElement |

Returns the HTMLElement that contains the control.

| | addTo(<Map> map) | this |

Adds the control to the given map.

| | remove() | this |

Removes the control from the map it is currently active on.

|

Control.Layers

The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the detailed example). Extends Control.

Usage example

const baseLayers = {
	"Mapbox": mapbox,
	"OpenStreetMap": osm
};

const overlays = {
	"Marker": marker,
	"Roads": roadsLayer
};

new Control.Layers(baseLayers, overlays).addTo(map);

The baseLayers and overlays parameters are object literals with layer names as keys and Layer objects as values:

{
    "<someName1>": layer1,
    "<someName2>": layer2
}

The layer names can contain HTML, which allows you to add additional styling to the items:

{" <span class='my-layer-item'>My Layer</span>": myLayer}

Constructor

ConstructorDescription
new Control.Layers(<Object> baselayers?, <Object> overlays?, <Control.Layers options> options?)Creates a layers control with the given layers. Base layers will be switched with radio buttons, while overlays will be switched with checkboxes. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation.

Options

OptionTypeDefaultDescription
collapsedBooleantrueIf true, the control will be collapsed into an icon and expanded on pointer hover, touch, or keyboard activation.
autoZIndexBooleantrueIf true, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.
hideSingleBaseBooleanfalseIf true, the base layers in the control will be hidden when there is only one.
sortLayersBooleanfalseWhether to sort the layers. When false, layers will keep the order in which they were added to the control.
sortFunctionFunction*A compare function that will be used for sorting the layers, when sortLayers is true. The function receives both the Layer instances and their names, as in sortFunction(layerA, layerB, nameA, nameB). By default, it sorts layers alphabetically by their name.

▶ Options inherited from Control

OptionTypeDefaultDescription
positionString'topright'The position of the control (one of the map corners). Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'

Methods

MethodReturnsDescription
addBaseLayer(<Layer> layer, <String> name)this

Adds a base layer (radio button entry) with the given name to the control.

| | addOverlay(<Layer> layer, <String> name) | this |

Adds an overlay (checkbox entry) with the given name to the control.

| | removeLayer(<Layer> layer) | this |

Remove the given layer from the control.

| | expand() | this |

Expand the control container if collapsed.

| | collapse() | this |

Collapse the control container if expanded.

|

▶ Methods inherited from Control

MethodReturnsDescription
getPosition()string

Returns the position of the control.

| | setPosition(<string> position) | this |

Sets the position of the control.

| | getContainer() | HTMLElement |

Returns the HTMLElement that contains the control.

| | addTo(<Map> map) | this |

Adds the control to the given map.

| | remove() | this |

Removes the control from the map it is currently active on.

|

Control.Scale

A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends Control.

Usage example

new Control.Scale().addTo(map);

Constructor

ConstructorDescription
new Control.Scale(<Control.Scale options> options?)Creates an scale control with the given options.

Options

OptionTypeDefaultDescription
positionString'bottomleft'The position of the control (one of the map corners). Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'
maxWidthNumber100Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).
metricBooleanTrueWhether to show the metric scale line (m/km).
imperialBooleanTrueWhether to show the imperial scale line (mi/ft).
updateWhenIdleBooleanfalseIf true, the control is updated on moveend, otherwise it's always up-to-date (updated on move).

Methods

▶ Methods inherited from Control

MethodReturnsDescription
getPosition()string

Returns the position of the control.

| | setPosition(<string> position) | this |

Sets the position of the control.

| | getContainer() | HTMLElement |

Returns the HTMLElement that contains the control.

| | addTo(<Map> map) | this |

Adds the control to the given map.

| | remove() | this |

Removes the control from the map it is currently active on.

|

Browser

A namespace with static properties for browser/feature detection used by Leaflet internally.

Usage example

if (Browser.chrome) {
  alert('You are running Chrome!');
}

Properties

PropertyTypeDescription
chromeBooleantrue for the Chrome browser.
safariBooleantrue for the Safari browser.
mobileBooleantrue for all browsers running in a mobile device.
pointerBooleantrue for all browsers supporting pointer events.
touchNativeBooleantrue for all browsers supporting touch events. This does not necessarily mean that the browser is running in a computer with a touchscreen, it only means that the browser is capable of understanding touch events.
touchBooleantrue for all browsers supporting either touch or pointer events. Note: pointer events will be preferred (if available), and processed for all touch* listeners.
retinaBooleantrue for browsers on a high-resolution "retina" screen or on any screen when browser's display zoom is more than 100%.
macBooleantrue when the browser is running in a Mac platform true when the browser is running in a Linux platform

Util

Various utility functions, used by Leaflet internally.

Functions

FunctionReturnsDescription
stamp(<Object> obj)NumberReturns the unique ID of an object, assigning it one if it doesn't have it.
throttle(<Function> fn, <Number> time, <Object> context)FunctionReturns a function which executes function fn with the given scope context (so that the this keyword refers to context inside fn's code). The function fn will be called no more than one time per given amount of time. The arguments received by the bound function will be any arguments passed when binding the function, followed by any arguments passed when invoking the bound function.
wrapNum(<Number> num, <Number[]> range, <Boolean> includeMax?)NumberReturns the number num modulo range in such a way so it lies within range[0] and range[1]. The returned value will be always smaller than range[1] unless includeMax is set to true.
falseFn()FunctionReturns a function which always returns false.
`formatNum(<Number> num, <Numberfalse> precision?)`Number
splitWords(<String> str)String[]Trims and splits the string on whitespace and returns the array of parts.
setOptions(<Object> obj, <Object> options)ObjectMerges the given properties to the options of the obj object, returning the resulting options. See Class options.
template(<String> str, <Object> data)StringSimple templating facility, accepts a template string of the form 'Hello {a}, {b}' and a data object like {a: 'foo', b: 'bar'}, returns evaluated string ('Hello foo, bar'). You can also specify functions instead of strings for data values — they will be evaluated passing data as an argument.

Properties

PropertyTypeDescription
lastIdNumberLast unique ID used by stamp()
emptyImageUrlStringData URI string containing a base64-encoded empty GIF image. Used as a hack to free memory from unused images on WebKit-powered mobile devices (by setting image src to this string).

Transformation

Represents an affine transformation: a set of coefficients a, b, c, d for transforming a point of a form (x, y) into (a*x + b, c*y + d) and doing the reverse. Used by Leaflet in its projections code.

Usage example

const transformation = new Transformation(2, 5, -1, 10),
	p = new Point(1, 2),
	p2 = transformation.transform(p), // new Point(7, 8)
	p3 = transformation.untransform(p2); // new Point(1, 2)

Constructor

ConstructorDescription
new Transformation(<Number> a, <Number> b, <Number> c, <Number> d)Instantiates a Transformation object with the given coefficients.
new Transformation(<Array> coefficients)Expects an coefficients array of the form [a: Number, b: Number, c: Number, d: Number].

Methods

MethodReturnsDescription
transform(<Point> point, <Number> scale?)Point

Returns a transformed point, optionally multiplied by the given scale. Only accepts actual Point instances, not arrays.

| | untransform(<Point> point, <Number> scale?) | Point |

Returns the reverse transformation of the given point, optionally divided by the given scale. Only accepts actual Point instances, not arrays.

|

LineUtil

Various utility functions for polyline points processing, used by Leaflet internally to make polylines lightning-fast.

Functions

FunctionReturnsDescription
simplify(<Point[]> points, <Number> tolerance)Point[]Dramatically reduces the number of points in a polyline while retaining its shape and returns a new array of simplified points, using the Ramer-Douglas-Peucker algorithm. Used for a huge performance boost when processing/displaying Leaflet polylines for each zoom level and also reducing visual noise. tolerance affects the amount of simplification (lesser value means higher quality but slower and with more points). Also released as a separated micro-library Simplify.js.
pointToSegmentDistance(<Point> p, <Point> p1, <Point> p2)NumberReturns the distance between point p and segment p1 to p2.
closestPointOnSegment(<Point> p, <Point> p1, <Point> p2)NumberReturns the closest point from a point p on a segment p1 to p2.
clipSegment(<Point> a, <Point> b, <Bounds> bounds, <Boolean> useLastCode?, <Boolean> round?)`Point[]Boolean`
isFlat(<LatLng[]> latlngs)BooleanReturns true if latlngs is a flat array, false is nested.
polylineCenter(<LatLng[]> latlngs, <CRS> crs)LatLngReturns the center (centroid) of the passed LatLngs (first ring) from a polyline.

PolyUtil

Various utility functions for polygon geometries.

Functions

FunctionReturnsDescription
clipPolygon(<Point[]> points, <Bounds> bounds, <Boolean> round?)Point[]Clips the polygon geometry defined by the given points by the given bounds (using the Sutherland-Hodgman algorithm). Used by Leaflet to only show polygon points that are on the screen or near, increasing performance. Note that polygon points needs different algorithm for clipping than polyline, so there's a separate method for it.
polygonCenter(<LatLng[]> latlngs, <CRS> crs)LatLngReturns the center (centroid) of the passed LatLngs (first ring) from a polygon.
centroid(<LatLng[]> latlngs)LatLngReturns the 'center of mass' of the passed LatLngs.

DomEvent

Utility functions to work with the DOM events, used by Leaflet internally.

Functions

FunctionReturnsDescription
on(<HTMLElement> el, <String> types, <Function> fn, <Object> context?)thisAdds a listener function (fn) to a particular DOM event type of the element el. 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(<HTMLElement> el, <Object> eventMap, <Object> context?)thisAdds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(<HTMLElement> el, <String> types, <Function> fn, <Object> context?)thisRemoves a previously added listener function. 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(<HTMLElement> el, <Object> eventMap, <Object> context?)thisRemoves a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(<HTMLElement> el, <String> types)thisRemoves all previously added listeners of given types.
off(<HTMLElement> el)thisRemoves all previously added listeners from given HTMLElement
stopPropagation(<DOMEvent> ev)thisStop the given event from propagation to parent elements. Used inside the listener functions:
DomEvent.on(div, 'click', DomEvent.stopPropagation);

| | disableScrollPropagation(<HTMLElement> el) | this | Adds stopPropagation to the element's 'wheel' events (plus browser variants). | | disableClickPropagation(<HTMLElement> el) | this | Adds stopPropagation to the element's 'click', 'dblclick', 'contextmenu' and 'pointerdown' events (plus browser variants). | | preventDefault(<DOMEvent> ev) | this | Prevents the default action of the DOM Event ev from happening (such as following a link in the href of the a element, or doing a POST request with page reload when a <form> is submitted). Use it inside listener functions. | | stop(<DOMEvent> ev) | this | Does stopPropagation and preventDefault at the same time. | | getPropagationPath(<DOMEvent> ev) | Array | Returns an array containing the HTMLElements that the given DOM event should propagate to (if not stopped). | | getPointerPosition(<DOMEvent> ev, <HTMLElement> container?) | Point | Gets normalized pointer position from a DOM event relative to the container (border excluded) or to the whole page if not specified. | | getWheelPxFactor() | Number | Gets the wheel pixel factor based on the devicePixelRatio | | getWheelDelta(<DOMEvent> ev) | Number | Gets normalized wheel delta from a wheel DOM event, in vertical pixels scrolled (negative if scrolling down). Events from pointing devices without precise scrolling are mapped to a best guess of 60 pixels. | | addListener(…) | this | Alias to DomEvent.on | | removeListener(…) | this | Alias to DomEvent.off |

Pointer detection

Detects the pointers that are currently active on the document.

FunctionReturnsDescription
enablePointerDetection()``Enables pointer detection for the document.
disablePointerDetection()``Disables pointer detection for the document.
getPointers()PointerEvents[]Returns the active pointers on the document.
cleanupPointers()``Clears the detected pointers on the document. Note: This function should be not necessary to call, as the pointers are automatically cleared with pointerup, pointercancel and pointerout events.

DomUtil

Utility functions to work with the DOM tree, used by Leaflet internally.

Most functions expecting or returning a HTMLElement also work for SVG elements. The only difference is that classes refer to CSS classes in HTML and SVG classes in SVG.

Functions

FunctionReturnsDescription
`get(<StringHTMLElement> id)`HTMLElement
create(<String> tagName, <String> className?, <HTMLElement> container?)HTMLElementCreates an HTML element with tagName, sets its class to className, and optionally appends it to container element.
toFront(<HTMLElement> el)``Makes el the last child of its parent, so it renders in front of the other children.
toBack(<HTMLElement> el)``Makes el the first child of its parent, so it renders behind the other children.
setTransform(<HTMLElement> el, <Point> offset, <Number> scale?)``Resets the 3D CSS transform of el so it is translated by offset pixels and optionally scaled by scale. Does not have an effect if the browser doesn't support 3D CSS transforms.
setPosition(<HTMLElement> el, <Point> position)``Sets the position of el to coordinates specified by position, using CSS translate or top/left positioning depending on the browser (used by Leaflet internally to position its layers).
getPosition(<HTMLElement> el)PointReturns the coordinates of an element previously positioned with setPosition.
disableTextSelection()``Prevents the user from selecting text in the document. Used internally by Leaflet to override the behaviour of any click-and-drag interaction on the map. Affects drag interactions on the whole document.
enableTextSelection()``Cancels the effects of a previous DomUtil.disableTextSelection.
disableImageDrag()``Prevents the user from generating dragstart DOM events, usually generated when the user drags an image.
enableImageDrag()``Cancels the effects of a previous DomUtil.disableImageDrag.
preventOutline(<HTMLElement> el)``Makes the outline of the element el invisible. Used internally by Leaflet to prevent focusable elements from displaying an outline when the user performs a drag interaction on them.
restoreOutline()``Cancels the effects of a previous DomUtil.preventOutline.
getSizedParentNode(<HTMLElement> el)HTMLElementFinds the closest parent node which size (width and height) is not null.
getScale(<HTMLElement> el)ObjectComputes the CSS scale currently applied on the element. Returns an object with x and y members as horizontal and vertical scales respectively, and boundingClientRect as the result of getBoundingClientRect().

PosAnimation

Used internally for panning animations and utilizing CSS Transitions for modern browsers.

Usage example

const myPositionMarker = new Marker([48.864716, 2.294694]).addTo(map);

myPositionMarker.on("click", function() {
	const pos = map.latLngToLayerPoint(myPositionMarker.getLatLng());
	pos.y -= 25;
	const fx = new PosAnimation();

	fx.once('end',function() {
		pos.y += 25;
		fx.run(myPositionMarker._icon, pos, 0.8);
	});

	fx.run(myPositionMarker._icon, pos, 0.3);
});

Constructor

ConstructorDescription
new PosAnimation()Creates a PosAnimation object.

Events

EventDataDescription
startEventFired when the animation starts
stepEventFired continuously during the animation.
endEventFired when the animation ends.

Methods

MethodReturnsDescription
run(<HTMLElement> el, <Point> newPos, <Number> duration?, <Number> easeLinearity?)``

Run an animation of a given element to a new position, optionally setting duration in seconds (0.25 by default) and easing linearity factor (3rd argument of the cubic bezier curve, 0.5 by default).

| | stop() | `` |

Stops the animation (if currently running).

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Draggable

A class for making DOM elements draggable. Used internally for map and marker dragging. Only works for elements that were positioned with DomUtil.setPosition.

Usage example

const draggable = new Draggable(elementToDrag);
draggable.enable();

Constructor

ConstructorDescription
new Draggable(<HTMLElement> el, <HTMLElement> dragHandle?, <Boolean> preventOutline?, <Draggable options> options?)Creates a Draggable object for moving el when you start dragging the dragHandle element (equals el itself by default).

Options

OptionTypeDefaultDescription
clickToleranceNumber3The max number of pixels a user can shift the pointer during a click for it to be considered a valid click (as opposed to a pointer drag).

Events

EventDataDescription
downEventFired when a drag is about to start.
dragstartEventFired when a drag starts
predragEventFired continuously during dragging before each corresponding update of the element's position.
dragEventFired continuously during dragging.
dragendDragEndEventFired when the drag ends.

Methods

MethodReturnsDescription
enable()``

Enables the dragging ability

| | disable() | `` |

Disables the dragging ability

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Class

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

In addition to implementing a simple classical inheritance model, it introduces several special properties for convenient code organization — options, includes and statics.

Usage example

const MyClass = Class.extend({
    initialize(greeter) {
        this.greeter = greeter;
        // class constructor
    },

    greet(name) {
        alert(this.greeter + ', ' + name)
    }
});

// create instance of MyClass, passing "Hello" to the constructor
const a = new MyClass("Hello");

// call greet method, alerting "Hello, World"
a.greet("World");

Inheritance

You use Class.extend to define new classes, but you can use the same method on any class to inherit from it:

const MyChildClass = MyClass.extend({
    // ... new properties and methods
});

This will create a class that inherits all methods and properties of the parent class (through a proper prototype chain), adding or overriding the ones you pass to extend. It will also properly react to instanceof:

const a = new MyChildClass();
a instanceof MyChildClass; // true
a instanceof MyClass; // true

You can call parent methods (including constructor) from corresponding child ones (as you do with super calls in other languages) by accessing parent class prototype and using JavaScript's call or apply:

const MyChildClass = MyClass.extend({
    initialize() {
        MyClass.prototype.initialize.call(this, "Yo");
    },

    greet(name) {
        MyClass.prototype.greet.call(this, 'bro ' + name + '!');
    }
});

const a = new MyChildClass();
a.greet('Jason'); // alerts "Yo, bro Jason!"

Options

options is a special property that unlike other objects that you pass to extend will be merged with the parent one instead of overriding it completely, which makes managing configuration of objects and default values convenient:

const MyClass = Class.extend({
    options: {
        myOption1: 'foo',
        myOption2: 'bar'
    }
});

const MyChildClass = MyClass.extend({
    options: {
        myOption1: 'baz',
        myOption3: 5
    }
});

const a = new MyChildClass();
a.options.myOption1; // 'baz'
a.options.myOption2; // 'bar'
a.options.myOption3; // 5

There's also Util.setOptions, a method for conveniently merging options passed to constructor with the defaults defines in the class:

const MyClass = Class.extend({
    options: {
        foo: 'bar',
        bla: 5
    },

    initialize(options) {
        Util.setOptions(this, options);
        ...
    }
});

const a = new MyClass({bla: 10});
a.options; // {foo: 'bar', bla: 10}

Note that the options object allows any keys, not just the options defined by the class and its base classes. This means you can use the options object to store application specific information, as long as you avoid keys that are already used by the class in question.

Includes

includes is a special class property that merges all specified objects into the class (such objects are called mixins).

const MyMixin = {
    foo() { ... },
    bar: 5
};

const MyClass = Class.extend({
    includes: MyMixin
});

const a = new MyClass();
a.foo();

You can also do such includes in runtime with the include method:

MyClass.include(MyMixin);

statics is just a convenience property that injects specified object properties as the static properties of the class, useful for defining constants:

const MyClass = Class.extend({
    statics: {
        FOO: 'bar',
        BLA: 5
    }
});

MyClass.FOO; // 'bar'

Constructor hooks

If you're a plugin developer, you often need to add additional initialization code to existing classes (e.g. editing hooks for Polyline). Leaflet comes with a way to do it easily using the addInitHook method:

MyClass.addInitHook(() => {
    // ... do something in constructor additionally
    // e.g. add event listeners, set custom properties etc.
});

You can also use the following shortcut when you just need to make one additional method call:

MyClass.addInitHook('methodName', arg1, arg2, …);

Functions

FunctionReturnsDescription
extend(<Object> props)FunctionExtends the current class given the properties to be included. Returns a Javascript function that is a class constructor (to be called with new).
include(<Object> properties)thisIncludes a mixin into the current class.
mergeOptions(<Object> options)thisMerges options into the defaults of the class.
addInitHook(<Function> fn)thisAdds a constructor hook to the class.

Evented

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).

Usage example

map.on('click', function(e) {
	alert(e.latlng);
} );

Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:

function onClick(e) { ... }

map.on('click', onClick);
map.off('click', onClick);

Methods

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Layer

A set of methods from the Layer base class that all Leaflet layers use. Inherits all methods, options and events from Evented.

Usage example

const layer = new Marker(latlng).addTo(map);
layer.addTo(map);
layer.remove();

Options

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

Popup events

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

Tooltip events

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

Classes extending Layer will inherit the following methods:

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

Extension methods

Every layer should extend from Layer and (re-)implement the following methods.

MethodReturnsDescription
onAdd(<Map> map)this

Should contain code that creates DOM elements for the layer, adds them to map panes where they should belong and puts listeners on relevant map events. Called on map.addLayer(layer).

| | onRemove(<Map> map) | this |

Should contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added in onAdd. Called on map.removeLayer(layer).

| | getEvents() | Object |

This optional method should return an object like { viewreset: this._reset } for addEventListener. The event handlers in this object will be automatically added and removed from the map with your layer.

| | getAttribution() | String |

This optional method should return a string containing HTML to be shown on the Attribution control whenever the layer is visible.

| | beforeAdd(<Map> map) | this |

Optional method. Called on map.addLayer(layer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.

|

Popup methods

All layers share a set of methods convenient for binding popups to it.

const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);
layer.openPopup();
layer.closePopup();

Popups will also be automatically opened when the layer is clicked on and closed when the layer is removed from the map or another popup is opened.

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

Tooltip methods

All layers share a set of methods convenient for binding tooltips to it.

const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);
layer.openTooltip();
layer.closeTooltip();
MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Interactive layer

Some Layers can be made interactive - when the user interacts with such a layer, pointer events like click and pointerover can be handled. Use the event handling methods to handle these events.

Options

OptionTypeDefaultDescription
interactiveBooleantrueIf false, the layer will not emit pointer events and will act as a part of the underlying map.
bubblingPointerEventsBooleantrueWhen true, a pointer event on this layer will trigger the same event on the map (unless DomEvent.stopPropagation is used).

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

Pointer events

EventDataDescription
clickPointerEventFired when the user clicks (or taps) the layer.
dblclickPointerEventFired when the user double-clicks (or double-taps) the layer.
pointerdownPointerEventFired when the user pushes the pointer on the layer.
pointerupPointerEventFired when the user releases the pointer pushed on the layer.
pointeroverPointerEventFired when the pointer enters the layer.
pointeroutPointerEventFired when the pointer leaves the layer.
contextmenuPointerEventFired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press).

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Control

Control is a base class for implementing map controls. Handles positioning. All other controls extend from this class.

Options

OptionTypeDefaultDescription
positionString'topright'The position of the control (one of the map corners). Possible values are 'topleft', 'topright', 'bottomleft' or 'bottomright'

Methods

Classes extending Control will inherit the following methods:

MethodReturnsDescription
getPosition()string

Returns the position of the control.

| | setPosition(<string> position) | this |

Sets the position of the control.

| | getContainer() | HTMLElement |

Returns the HTMLElement that contains the control.

| | addTo(<Map> map) | this |

Adds the control to the given map.

| | remove() | this |

Removes the control from the map it is currently active on.

|

Extension methods

Every control should extend from Control and (re-)implement the following methods.

MethodReturnsDescription
onAdd(<Map> map)HTMLElement

Should return the container DOM element for the control and add listeners on relevant map events. Called on control.addTo(map).

| | onRemove(<Map> map) | `` |

Optional method. Should contain all clean up code that removes the listeners previously added in onAdd. Called on control.remove().

|

Handler

Abstract class for map interaction handlers

Methods

MethodReturnsDescription
enable()this

Enables the handler

| | disable() | this |

Disables the handler

| | enabled() | Boolean |

Returns true if the handler is enabled

|

Extension methods

Classes inheriting from Handler must implement the two following methods:

MethodReturnsDescription
addHooks()``

Called when the handler is enabled, should add event hooks.

| | removeHooks() | `` |

Called when the handler is disabled, should remove the event hooks added previously.

|

Functions

There is static function which can be called without instantiating Handler:

FunctionReturnsDescription
addTo(<Map> map, <String> name)thisAdds a new Handler to the given map with the given name.

Projection

An object with methods for projecting geographical coordinates of the world onto a flat surface (and back). See Map projection.

Methods

MethodReturnsDescription
project(<LatLng> latlng)Point

Projects geographical coordinates into a 2D point. Only accepts actual LatLng instances, not arrays.

| | unproject(<Point> point) | LatLng |

The inverse of project. Projects a 2D point into a geographical location. Only accepts actual Point instances, not arrays.

Note that the projection instances do not inherit from Leaflet's Class object, and can't be instantiated. Also, new classes can't inherit from them, and methods can't be added to them with the include function.

|

Properties

PropertyTypeDescription
boundsBoundsThe bounds (specified in CRS units) where the projection is valid

Defined projections

Leaflet comes with a set of already defined Projections out of the box:

ProjectionDescription
Projection.LonLatEquirectangular, or Plate Carree projection — the most simple projection, mostly used by GIS enthusiasts. Directly maps x as longitude, and y as latitude. Also suitable for flat worlds, e.g. game maps. Used by the EPSG:4326 and Simple CRS.
Projection.MercatorElliptical Mercator projection — more complex than Spherical Mercator. Assumes that Earth is an ellipsoid. Used by the EPSG:3395 CRS.
Projection.SphericalMercatorSpherical Mercator projection — the most common projection for online maps, used by almost all free and commercial tile providers. Assumes that Earth is a sphere. Used by the EPSG:3857 CRS.

CRS

Methods

MethodReturnsDescription
latLngToPoint(<LatLng> latlng, <Number> zoom)Point

Projects geographical coordinates into pixel coordinates for a given zoom.

| | pointToLatLng(<Point> point, <Number> zoom) | LatLng |

The inverse of latLngToPoint. Projects pixel coordinates on a given zoom into geographical coordinates.

| | project(<LatLng> latlng) | Point |

Projects geographical coordinates into coordinates in units accepted for this CRS (e.g. meters for EPSG:3857, for passing it to WMS services).

| | unproject(<Point> point) | LatLng |

Given a projected coordinate returns the corresponding LatLng. The inverse of project.

| | scale(<Number> zoom) | Number |

Returns the scale used when transforming projected coordinates into pixel coordinates for a particular zoom. For example, it returns 256 * 2^zoom for Mercator-based CRS.

| | zoom(<Number> scale) | Number |

Inverse of scale(), returns the zoom level corresponding to a scale factor of scale.

| | getProjectedBounds(<Number> zoom) | Bounds |

Returns the projection's bounds scaled and transformed for the provided zoom.

| | distance(<LatLng> latlng1, <LatLng> latlng2) | Number |

Returns the distance between two geographical coordinates.

| | wrapLatLng(<LatLng> latlng) | LatLng |

Returns a LatLng where lat and lng has been wrapped according to the CRS's wrapLat and wrapLng properties, if they are outside the CRS's bounds.

| | wrapLatLngBounds(<LatLngBounds> bounds) | LatLngBounds |

Returns a LatLngBounds with the same size as the given one, ensuring that its center is within the CRS's bounds. Only accepts actual LatLngBounds instances, not arrays.

|

Properties

PropertyTypeDescription
codeStringStandard code name of the CRS passed into WMS services (e.g. 'EPSG:3857')
wrapLngNumber[]An array of two numbers defining whether the longitude (horizontal) coordinate axis wraps around a given range and how. Defaults to [-180, 180] in most geographical CRSs. If undefined, the longitude axis does not wrap around.
wrapLatNumber[]Like wrapLng, but for the latitude (vertical) axis.
infiniteBooleanIf true, the coordinate space will be unbounded (infinite in both axes)

Defined CRSs

CRSDescription
CRS.EarthServes as the base for CRS that are global such that they cover the earth. Can only be used as the base for other CRS and cannot be used directly, since it does not have a code, projection or transformation. distance() returns meters.
CRS.EPSG3395Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.
CRS.EPSG3857The most common CRS for online maps, used by almost all free and commercial tile providers. Uses Spherical Mercator projection. Set in by default in Map's crs option.
CRS.EPSG4326A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.

Leaflet complies with the TMS coordinate scheme for EPSG:4326. If you are using a TileLayer with this CRS, ensure that there are two 256x256 pixel tiles covering the whole earth at zoom level zero, and that the tile coordinate origin is (-180,+90), or (-180,-90) for TileLayers with the tms option set.

| | CRS.Base | Object that defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back (and to coordinates in other units for WMS services). See spatial reference system.

Leaflet defines the most usual CRSs by default. If you want to use a CRS not defined by default, take a look at the Proj4Leaflet plugin.

Note that the CRS instances do not inherit from Leaflet's Class object, and can't be instantiated. Also, new classes can't inherit from them, and methods can't be added to them with the include function.

| | CRS.Simple | A simple CRS that maps longitude and latitude into x and y directly. May be used for maps of flat surfaces (e.g. game maps). Note that the y axis should still be inverted (going from bottom to top). distance() returns simple euclidean distance. |

BlanketOverlay

Represents an HTML element that covers ("blankets") the entire surface of the map.

Do not use this class directly. It's meant for Renderer, and for plugins that rely on one single HTML element

Options

OptionTypeDefaultDescription
paddingNumber0.1How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction
continuousBooleanfalseWhen false, the blanket will update its position only when the map state settles (after a pan/zoom animation). When true, it will update when the map state changes (during pan/zoom animations)

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

Subclass interface

Subclasses must define the following methods:

MethodReturnsDescription
_initContainer()undefined

Must initialize the HTML element to use as blanket, and store it as this._container. The base implementation creates a blank <div>

| | _destroyContainer() | undefined |

Must destroy the HTML element in this._container and free any other resources. The base implementation destroys the element and removes any event handlers attached to it.

| | _resizeContainer() | Point |

The base implementation resizes the container (based on the map's size and taking into account the padding), returning the new size in CSS pixels.

Subclass implementations shall reset container parameters and data structures as needed.

| | _onZoomEnd(<PointerEvent> ev?) | undefined |

(Optional) Runs on the map's zoomend event.

| | _onViewReset(<PointerEvent> ev?) | undefined |

(Optional) Runs on the map's viewreset event.

| | _onSettled() | undefined |

Runs whenever the map state settles after changing (at the end of pan/zoom animations, etc). This should trigger the bulk of any rendering logic.

If the continuous option is set to true, then this also runs on any map state change (including during pan/zoom animations).

|

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Renderer

Base class for vector renderer implementations (SVG, Canvas). Handles the DOM container of the renderer, its bounds, and its zoom animation.

A Renderer works as an implicit layer group for all Paths - the renderer itself can be added or removed to the map. All paths use a renderer, which can be implicit (the map will decide the type of renderer and use it automatically) or explicit (using the renderer option of the path).

Do not use this class directly, use SVG and Canvas instead.

The continuous option inherited from BlanketOverlay cannot be set to true (otherwise, renderers get out of place during a pinch-zoom operation).

Options

▶ Options inherited from BlanketOverlay

OptionTypeDefaultDescription
paddingNumber0.1How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction
continuousBooleanfalseWhen false, the blanket will update its position only when the map state settles (after a pan/zoom animation). When true, it will update when the map state changes (during pan/zoom animations)

▶ Options inherited from Layer

OptionTypeDefaultDescription
paneString'overlayPane'By default the layer will be added to the map's overlay pane. Overriding this option will cause the layer to be placed on another pane by default. Not effective if the renderer option is set (the renderer option will override the pane option).
attributionStringnullString to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.

Events

EventDataDescription
updateEventFired when the renderer updates its bounds, center and zoom, for example when its map has moved

▶ Events inherited from Layer

EventDataDescription
addEventFired after the layer is added to a map
removeEventFired after the layer is removed from a map

▶ Popup events inherited from Layer

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
popupclosePopupEventFired when a popup bound to this layer is closed

▶ Tooltip events inherited from Layer

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.

Methods

▶ Methods inherited from Layer

MethodReturnsDescription
`addTo(<MapLayerGroup> map)`this

Adds the layer to the given map or layer group.

| | remove() | this |

Removes the layer from the map it is currently active on.

| | removeFrom(<Map> map) | this |

Removes the layer from the given map

| | removeFrom(<LayerGroup> group) | this |

Removes the layer from the given LayerGroup

| | getPane(<String> name?) | HTMLElement |

Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.

| | getAttribution() | String |

Used by the attribution control, returns the attribution option.

|

▶ Popup methods inherited from Layer

MethodReturnsDescription
`bindPopup(<StringHTMLElementFunction

Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindPopup() | this |

Removes the popup previously bound with bindPopup.

| | openPopup(<LatLng> latlng?) | this |

Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.

| | closePopup() | this |

Closes the popup bound to this layer if it is open.

| | togglePopup() | this |

Opens or closes the popup bound to this layer depending on its current state.

| | isPopupOpen() | boolean |

Returns true if the popup bound to this layer is currently open.

| | setPopupContent(<String|HTMLElement|Popup> content) | this |

Sets the content of the popup bound to this layer.

| | getPopup() | Popup |

Returns the popup bound to this layer.

|

▶ Tooltip methods inherited from Layer

MethodReturnsDescription
`bindTooltip(<StringHTMLElementFunction

Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement.

| | unbindTooltip() | this |

Removes the tooltip previously bound with bindTooltip.

| | openTooltip(<LatLng> latlng?) | this |

Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.

| | closeTooltip() | this |

Closes the tooltip bound to this layer if it is open.

| | toggleTooltip() | this |

Opens or closes the tooltip bound to this layer depending on its current state.

| | isTooltipOpen() | boolean |

Returns true if the tooltip bound to this layer is currently open.

| | setTooltipContent(<String|HTMLElement|Tooltip> content) | this |

Sets the content of the tooltip bound to this layer.

| | getTooltip() | Tooltip |

Returns the tooltip bound to this layer.

|

▶ Methods inherited from Evented

MethodReturnsDescription
on(<String> type, <Function> fn, <Object> context?)this

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(<Object> eventMap) | this |

Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}

| | off(<String> type, <Function> fn?, <Object> context?) | 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(<Object> eventMap) | this |

Removes a set of type/listener pairs.

| | off() | this |

Removes all listeners to all events on the object. This includes implicitly attached events.

| | fire(<String> type, <Object> data?, <Boolean> propagate?) | 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 can optionally be propagated to event parents.

| | listens(<String> type, <Boolean> propagate?) | Boolean |

Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.

| | once(…) | this |

Behaves as on(…), except the listener will only get fired once and then removed.

| | addEventParent(<Evented> obj) | this |

Adds an event parent - an Evented that will receive propagated events

| | removeEventParent(<Evented> obj) | this |

Removes an event parent, so it will stop receiving propagated events

| | addEventListener(…) | this |

Alias to on(…)

| | removeEventListener(…) | this |

Alias to off(…)

| | clearAllEventListeners(…) | this |

Alias to off()

| | addOneTimeEventListener(…) | this |

Alias to once(…)

| | fireEvent(…) | this |

Alias to fire(…)

| | hasEventListeners(…) | Boolean |

Alias to listens(…)

|

Event objects

Whenever a class inheriting from Evented fires an event, a listener function will be called with an event argument, which is a plain object containing information about the event. For example:

map.on('click', function(ev) {
    alert(ev.latlng); // ev is an event object (PointerEvent in this case)
});

The information available depends on the event type:

Event

The base event object. All other event objects contain these properties too.

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

KeyboardEvent

PropertyTypeDescription
originalEventDOMEventThe original DOM KeyboardEvent that triggered this Leaflet event.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

PointerEvent

PropertyTypeDescription
latlngLatLngThe geographical point where the pointer event occurred.
layerPointPointPixel coordinates of the point where the pointer event occurred relative to the map layer.
containerPointPointPixel coordinates of the point where the pointer event occurred relative to the map сontainer.
originalEventDOMEventThe original DOM MouseEvent or DOM PointerEvent that triggered this Leaflet event.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

LocationEvent

PropertyTypeDescription
latlngLatLngDetected geographical location of the user.
boundsLatLngBoundsGeographical bounds of the area user is located in (with respect to the accuracy of location).
accuracyNumberAccuracy of location in meters.
altitudeNumberHeight of the position above the WGS84 ellipsoid in meters.
altitudeAccuracyNumberAccuracy of altitude in meters.
headingNumberThe direction of travel in degrees counting clockwise from true North.
speedNumberCurrent velocity in meters per second.
timestampNumberThe time when the position was acquired.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

ErrorEvent

PropertyTypeDescription
messageStringError message.
codeNumberError code (if applicable).

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

LayerEvent

PropertyTypeDescription
layerLayerThe layer that was added or removed.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

LayersControlEvent

PropertyTypeDescription
layerLayerThe layer that was added or removed.
nameStringThe name of the layer that was added or removed.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

TileEvent

PropertyTypeDescription
tileHTMLElementThe tile element (image).
coordsPointPoint object with the tile's x, y, and z (zoom level) coordinates.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

TileErrorEvent

PropertyTypeDescription
tileHTMLElementThe tile element (image).
coordsPointPoint object with the tile's x, y, and z (zoom level) coordinates.
error*Error passed to the tile's done() callback.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

ResizeEvent

PropertyTypeDescription
oldSizePointThe old size before resize event.
newSizePointThe new size after the resize event.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

GeoJSONEvent

PropertyTypeDescription
layerLayerThe layer for the GeoJSON feature that is being added to the map.
propertiesObjectGeoJSON properties of the feature.
geometryTypeStringGeoJSON geometry type of the feature.
idStringGeoJSON ID of the feature (if present).

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

PopupEvent

PropertyTypeDescription
popupPopupThe popup that was opened or closed.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

TooltipEvent

PropertyTypeDescription
tooltipTooltipThe tooltip that was opened or closed.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

DragEndEvent

PropertyTypeDescription
distanceNumberThe distance in pixels the draggable element was moved by.

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

ZoomAnimEvent

PropertyTypeDescription
centerLatLngThe current center of the map
zoomNumberThe current zoom level of the map
noUpdateBooleanWhether layers should update their contents due to this event

▶ Properties inherited from Event

PropertyTypeDescription
typeStringThe event type (e.g. 'click').
targetObjectThe object that fired the event. For propagated events, the last object in the propagation chain that fired the event.
sourceTargetObjectThe object that originally fired the event. For non-propagated events, this will be the same as the target.
propagatedFromObjectFor propagated events, the last object that propagated the event to its event parent.

noConflict

This is only available when Leaflet is not imported as a module!

This method restores the L global variable to the original value it had before Leaflet inclusion, and returns the real Leaflet namespace so you can put it elsewhere, like this:

<script src='libs/l.js'>
<!-- L points to some other library -->

<script src='leaflet.js'>
<!-- you include Leaflet, it replaces the L variable to Leaflet namespace -->

<script>
const Leaflet = L.noConflict();
// now L points to that other library again, and you can use Leaflet.Map etc.
</script>

version

A constant that represents the Leaflet version in use.

L.version; // contains "1.0.0" (or whatever version is currently in use)