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.
maxZoom
Number
undefined
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.
layers
Layer[]
[]
Array of layers that will be added to the map initially
When 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.
The default method for drawing vector layers on the map. A new SVG renderer
by default; pass new Canvas() to draw them on a canvas instead.
Animation Options
Option
Type
Default
Description
zoomAnimation
Boolean
true
Whether the map zoom animation is enabled.
zoomAnimationThreshold
Number
4
Won't animate zoom if the zoom difference exceeds this value (or 1 if the user prefers
reduced motion
and animate: true isn't passed).
fadeAnimation
Boolean
true
Whether the tile and popup fade animation is enabled.
markerZoomAnimation
Boolean
true
Whether markers animate their zoom with the zoom animation, if
disabled they will disappear for the length of the animation.
transform3DLimit
Number
8388608
Defines 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.
Interaction Options
Option
Type
Default
Description
zoomSnap
Number
1
Forces 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.
zoomDelta
Number
1
Controls 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.
trackResize
Boolean
true
Whether the map automatically handles browser window resize to update itself.
closePopupOnClick
Boolean
true
Set it to false if you don't want popups to close when user clicks the map.
boxZoom
Boolean
true
Whether the map can be zoomed to a rectangular area specified
by dragging the pointer while pressing the shift key.
doubleClickZoom
Boolean|String
true
Whether the map can be zoomed in by double clicking on it and zoomed out by
double clicking while holding shift. If passed 'center', double-click zoom
will zoom to the center of the view regardless of where the pointer was.
dragging
Boolean
true
Whether the map is draggable with pointer or not.
Panning Inertia Options
Option
Type
Default
Description
inertia
Boolean
true
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.
inertiaDeceleration
Number
3400
The rate with which the inertial movement slows down, in pixels/second².
inertiaMaxSpeed
Number
1400
Max speed of the inertial movement, in pixels/second.
worldCopyJump
Boolean
false
With 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. A
map with an infinite CRS, such as SimpleCRS, does not jump, as it has no copies of the world.
maxBoundsViscosity
Number
0.0
If 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
Option
Type
Default
Description
keyboard
Boolean
true
Makes the map focusable and allows users to navigate the map with keyboard arrows and +/- keys.
keyboardPanDelta
Number
80
Amount of pixels to pan when pressing an arrow key.
ariaKeyShortcuts
Boolean|String
false
Sets the aria-keyshortcuts attribute of the map container. ARIA names keys by what they type
on a given layout, so true uses the names for a US English layout, which can be wrong for pages
in other languages; pass a string to set the value for your audience's layout instead.
Mouse wheel options
Option
Type
Default
Description
scrollWheelZoom
Boolean|String
true
Whether the map can be zoomed by using the mouse wheel. If passed 'center',
it will zoom to the center of the view regardless of where the pointer was.
wheelDebounceTime
Number
40
Limits the rate at which a wheel can fire (in milliseconds). By default,
the user can't zoom via wheel more often than once per 40 ms.
wheelPxPerZoomLevel
Number
60
How 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).
Touch interaction options
Option
Type
Default
Description
tapHold
Boolean
true
Fires a contextmenu event on a long touch press. iOS Safari doesn't fire one natively.
tapTolerance
Number
15
The max number of pixels a user can shift his finger during touch for it to be considered a valid tap.
pinchZoom
Boolean|String
true
Whether the map can be zoomed by touch-dragging with two fingers. If passed 'center', it will zoom to the
center of the view regardless of where the touch events (fingers) were. Enabled for touch-capable web
browsers.
bounceAtZoomLimits
Boolean
true
Set it to false if you don't want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming.
Control options
Option
Type
Default
Description
zoomControl
Boolean
true
Whether a zoom control is added to the map by default.
Fired 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).
Pans the map by a given number of pixels (animated unless animate: false is passed, or the user
prefers reduced motion and the pan is longer than half the map size without animate: true).
Sets the view of the map (geographical center and zoom) performing a smooth pan-zoom
animation. If the user prefers reduced motion (and animate: true isn't passed),
it behaves like setView instead, only animating short pans and zooms.
Sets the view of the map with a smooth animation like flyTo,
but takes a bounds parameter like fitBounds, or anything with a getBounds() method, like a
FeatureGroup.
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.
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.
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. true is a shorthand
for {animate: true}.
stop(): this
Stops the currently running panTo or flyTo animation, if any.
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 geolocation only works on pages served over HTTPS. See LocateOptions
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}.
Opens the specified popup while closing the previously opened
(to make sure only one is opened at one time for usability).
openPopup(content: String|HTMLElement,latlng: LatLng,options?: Popup options): this
Creates a popup with the specified content and options and opens it in the given point on a map. String
content is rendered as HTML; sanitize untrusted input or pass an HTMLElement with safe textContent
instead.
openTooltip(content: String|HTMLElement,latlng: LatLng,options?: Tooltip options): this
Creates a tooltip with the specified content and options and open it. String content is rendered
as HTML; sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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.
Other Methods
Method
Description
addHandler(name: String,HandlerClass: Function): 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.
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(pane: String|HTMLElement): HTMLElement
Returns a map pane, given its name or its HTML element (its identity).
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(callback: Function,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.
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(bounds: LatLngBounds,inside?: Boolean,padding?: Point): 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.
Returns the bounds of the current map view in projected pixel coordinates (sometimes useful in layer and
overlay implementations). If center and zoom is omitted, the map's current zoom level and center is used.
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
Method
Description
getZoomScale(toZoom: Number,fromZoom?: Number): 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(scale: Number,fromZoom?: Number): 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.
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.
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.
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.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The default zoom control (only available if the
zoomControl option was true when creating the map).
Handlers
Map properties include interaction handlers that allow you to control interaction behavior in runtime,
enabling or disabling certain features such as dragging or touch zoom (see Handler methods). For example:
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 z-index.
Options for the Map methods that change the zoom level.
ZoomOptions
Option
Type
Default
Description
animate
Boolean
If not specified, zoom animation will happen if the zoom origin is inside
the current view, and if the user prefers reduced motion, only when zooming by at most one level. If
true, the map will attempt animating zoom disregarding where zoom origin is and the user's reduced
motion preference. Setting false will make it always reset the view completely without animation.
Options for the Map methods that change the center of the map.
PanOptions
Option
Type
Default
Description
animate
Boolean
If true, panning will always be animated if possible, even if
the user prefers reduced motion. 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). If not specified, panning is
animated, except for pans longer than half the map size when the user prefers reduced motion.
duration
Number
0.25
Duration of animated panning, in seconds.
easeLinearity
Number
0.25
The 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.
noMoveStart
Boolean
false
If true, panning won't fire movestart event on
start (used internally for panning inertia).
Options for the Map methods that change both the center and the zoom level.
If not specified, zoom animation will happen if the zoom origin is inside
the current view, and if the user prefers reduced motion, only when zooming by at most one level. If
true, the map will attempt animating zoom disregarding where zoom origin is and the user's reduced
motion preference. Setting false will make it always reset the view completely without animation.
The 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.
noMoveStart
Boolean
false
If true, panning won't fire movestart event on
start (used internally for panning inertia).
InvalidateSizeOptions
Option
Type
Default
Description
pan
Boolean
true
If false, panning will not occur.
debounceMoveend
Boolean
false
If true, it will delay moveend event so that
it doesn't happen often even if the method is called many times in a row.
If not specified, zoom animation will happen if the zoom origin is inside
the current view, and if the user prefers reduced motion, only when zooming by at most one level. If
true, the map will attempt animating zoom disregarding where zoom origin is and the user's reduced
motion preference. Setting false will make it always reset the view completely without animation.
The 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.
noMoveStart
Boolean
false
If true, panning won't fire movestart event on
start (used internally for panning inertia).
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.
If true, panning will always be animated if possible, even if
the user prefers reduced motion. 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). If not specified, panning is
animated, except for pans longer than half the map size when the user prefers reduced motion.
duration
Number
0.25
Duration of animated panning, in seconds.
easeLinearity
Number
0.25
The 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.
noMoveStart
Boolean
false
If true, panning won't fire movestart event on
start (used internally for panning inertia).
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.
If not specified, zoom animation will happen if the zoom origin is inside
the current view, and if the user prefers reduced motion, only when zooming by at most one level. If
true, the map will attempt animating zoom disregarding where zoom origin is and the user's reduced
motion preference. Setting false will make it always reset the view completely without animation.
The 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.
noMoveStart
Boolean
false
If true, panning won't fire movestart event on
start (used internally for panning inertia).
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.
If 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.
setView
Boolean
false
If true, automatically sets the map view to the user
location with respect to detection accuracy, or to world view if geolocation failed.
maxZoom
Number
Infinity
The maximum zoom for automatic view setting when using setView option.
timeout
Number
10000
Number of milliseconds to wait for a response from
geolocation before firing a locationerror event.
maximumAge
Number
0
Maximum age of detected location. If less than this amount of
milliseconds passed since last geolocation response, locate will return a cached location.
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 DefaultIcon is used.
keyboard
Boolean
true
Whether the marker can be tabbed to with a keyboard and, if interactive, clicked by pressing Enter or Space.
title
String
''
Text for the browser tooltip that appear on marker hover (no tooltip by default). Useful for
accessibility.
By 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).
opacity
Number
1
The opacity of the marker.
rotation
Number
null
Rotation of the marker icon in degrees, clockwise, around the icon anchor. A rotated marker, even at 0°, has
no shadow, since the shadow of an upright pin looks wrong under a tilted one. null means no rotation.
riseOnHover
Boolean
false
If true, the marker will get on top of others when you hover the pointer over it.
riseOffset
Number
250
The z-index offset used for the riseOnHover feature.
pane
String
'markerPane'
Map pane where the markers icon will be added.
shadowPane
String
'shadowPane'
Map pane where the markers shadow will be added.
bubblingPointerEvents
Boolean
false
When true, a pointer event on this marker will trigger the same event on the
map (unless DomEvent.stopPropagation is used).
autoPanOnFocus
Boolean
true
When 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
Option
Type
Default
Description
draggable
Boolean
false
Whether the marker is draggable with pointer or not.
autoPan
Boolean
false
Whether to pan the map when dragging this marker near its edge or not.
Fired 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).
Returns the instance of HTMLElement
used by Marker layer.
update(): this
Updates the marker position on the map, e.g. after changing its zIndexOffset option directly.
getRotation(): Number
Returns the current rotation of the marker in degrees.
setRotation(rotation: Number): this
Changes the rotation of the marker; null removes it.
setOpacity(opacity: Number): this
Changes the opacity of the marker.
Other methods
Method
Description
toGeoJSON(precision?: Number|false): Feature
Coordinates values are rounded with formatNum function
with given precision. Returns a GeoJSON
representation of the marker (as a GeoJSON Point Feature).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Removes an event parent, so it will stop receiving propagated events
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:
Sets the HTML content of the overlay while initializing. 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.
String content is rendered as HTML; sanitize untrusted input or pass an HTMLElement with safe textContent
instead.
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).
Fired 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).
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().
Sets the geographical point where the overlay will open.
getContent(): OverlayContent
Returns the content of the overlay.
setContent(content: String|HTMLElement|Function): this
Sets the HTML content of the overlay. A String argument is rendered as HTML; if it may contain
untrusted input, sanitize it (e.g. with DOMPurify) or pass an HTMLElement with safe textContent
instead. 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(): HTMLElement
Returns the HTML container of the overlay.
update()
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
Popup
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!<br />This is a nice popup.</p>')
.openOn(map);
or
const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})
.openOn(map);
Security note. Popup string content is rendered as HTML. If your content
may include untrusted input (e.g. data from users or external APIs), sanitize
it with a library like DOMPurify, or
build a DOM element using textContent to render it as plain text:
const el = document.createElement('div');
el.textContent = untrustedString;
marker.bindPopup(el);
If 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.
autoPan
Boolean
true
Set it to false if you don't want the map to do panning animation to fit the opened popup.
If true, the popup/tooltip will listen to the pointer events.
content
String|HTMLElement|Function
''
Sets the HTML content of the overlay while initializing. 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.
String content is rendered as HTML; sanitize untrusted input or pass an HTMLElement with safe textContent
instead.
Fired 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).
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().
Sets the geographical point where the overlay will open.
getContent(): OverlayContent
Returns the content of the overlay.
setContent(content: String|HTMLElement|Function): this
Sets the HTML content of the overlay. A String argument is rendered as HTML; if it may contain
untrusted input, sanitize it (e.g. with DOMPurify) or pass an HTMLElement with safe textContent
instead. 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(): HTMLElement
Returns the HTML container of the overlay.
update()
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Path overlays like polylines also have a bindTooltip method.
A tooltip can be also standalone:
const tooltip = new Tooltip()
.setLatLng(latlng)
.setContent('Hello world!<br />This is a nice tooltip.')
.addTo(map);
or
const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})
.addTo(map);
Security note. Tooltip string content is rendered as HTML. If your content
may include untrusted input (e.g. data from users or external APIs), sanitize
it with a library like DOMPurify, or
build a DOM element using textContent to render it as plain text:
const el = document.createElement('div');
el.textContent = untrustedString;
marker.bindTooltip(el);
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.
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.
permanent
Boolean
false
Whether to open the tooltip permanently or only on pointerover.
sticky
Boolean
false
If true, the tooltip will follow the pointer instead of being fixed at the feature center.
If true, the popup/tooltip will listen to the pointer events.
className
String
''
A custom CSS class name to assign to the overlay.
content
String|HTMLElement|Function
''
Sets the HTML content of the overlay while initializing. 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.
String content is rendered as HTML; sanitize untrusted input or pass an HTMLElement with safe textContent
instead.
Fired 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).
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().
Sets the geographical point where the overlay will open.
getContent(): OverlayContent
Returns the content of the overlay.
setContent(content: String|HTMLElement|Function): this
Sets the HTML content of the overlay. A String argument is rendered as HTML; if it may contain
untrusted input, sanitize it (e.g. with DOMPurify) or pass an HTMLElement with safe textContent
instead. 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(): HTMLElement
Returns the HTML container of the overlay.
update()
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
{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'});
Instantiates a tile layer object given a URL template and optionally an options object.
Options
Option
Type
Default
Description
minZoom
Number
0
The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoom
Number
18
The maximum zoom level up to which this layer will be displayed (inclusive).
subdomains
String|String[]
'abc'
Subdomains of the tile service. Can be passed in the form of one string
(where each letter is a subdomain name) or an array of strings.
errorTileUrl
String
''
URL to the tile image to show in place of the tile that failed to load.
zoomOffset
Number
0
The zoom number used in tile URLs will be offset with this value.
tms
Boolean
false
If true, inverses Y axis numbering for tiles (turn this on for
TMS services).
zoomReverse
Boolean
false
If set to true, the zoom number used in tile URLs will be reversed (maxZoom - zoom instead of zoom)
detectRetina
Boolean
false
If 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
Boolean|String
false
Whether the crossOrigin attribute will be added to the tiles. If a String is provided,
all tiles will have their crossOrigin attribute set to the String provided. This is needed
if you want to access tile pixel data. Refer to CORS
Settings for valid String values.
referrerPolicy
ReferrerPolicy|false
'strict-origin-when-cross-origin'
Sets the tiles' referrerPolicy attribute set to the String provided. See
HTMLImageElement.referrerPolicy
for possible values.
Tile providers might require you to use a specific referrer policy (e.g. to verify API tokens or
prevent abuse). Specifically, if you are using tiles from tile.openstreetmap.org or tile.osm.org,
you should not change this value.
Width and height of tiles in the grid. Use a number if width
and height are equal, or Point(width, height) otherwise.
opacity
Number
1
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
false
Load new tiles only when panning ends.
updateWhenZooming
Boolean
true
By 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.
updateInterval
Number
200
Tiles will not update more than once every updateInterval milliseconds when panning.
If set, tiles will only be loaded inside the set LatLngBounds.
maxNativeZoom
Number
undefined
Maximum 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.
minNativeZoom
Number
undefined
Minimum 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.
noWrap
Boolean
false
Whether 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.
pane
String
'tilePane'
Map pane where the grid layer will be added.
className
String
''
A custom class name to assign to the tile layer. Empty by default.
keepBuffer
Number
2
When panning the map, keep this many rows and columns of tiles before unloading them.
Fired when a tooltip bound to this layer is closed.
Methods
Method
Description
setUrl(url: String,noRedraw?: Boolean): 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.
Called only internally, overrides GridLayer's createTile()
to return an <img> HTML element with the appropriate image URL given coords.
The done callback is called when the tile has been loaded.
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.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
WMSTileLayer
Used to display WMS
services as tile layers on the map. Extends TileLayer.
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.
The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoom
Number
18
The maximum zoom level up to which this layer will be displayed (inclusive).
subdomains
String|String[]
'abc'
Subdomains of the tile service. Can be passed in the form of one string
(where each letter is a subdomain name) or an array of strings.
errorTileUrl
String
''
URL to the tile image to show in place of the tile that failed to load.
zoomOffset
Number
0
The zoom number used in tile URLs will be offset with this value.
tms
Boolean
false
If true, inverses Y axis numbering for tiles (turn this on for
TMS services).
zoomReverse
Boolean
false
If set to true, the zoom number used in tile URLs will be reversed (maxZoom - zoom instead of zoom)
detectRetina
Boolean
false
If 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
Boolean|String
false
Whether the crossOrigin attribute will be added to the tiles. If a String is provided,
all tiles will have their crossOrigin attribute set to the String provided. This is needed
if you want to access tile pixel data. Refer to CORS
Settings for valid String values.
referrerPolicy
ReferrerPolicy|false
'strict-origin-when-cross-origin'
Sets the tiles' referrerPolicy attribute set to the String provided. See
HTMLImageElement.referrerPolicy
for possible values.
Tile providers might require you to use a specific referrer policy (e.g. to verify API tokens or
prevent abuse). Specifically, if you are using tiles from tile.openstreetmap.org or tile.osm.org,
you should not change this value.
Width and height of tiles in the grid. Use a number if width
and height are equal, or Point(width, height) otherwise.
opacity
Number
1
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
false
Load new tiles only when panning ends.
updateWhenZooming
Boolean
true
By 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.
updateInterval
Number
200
Tiles will not update more than once every updateInterval milliseconds when panning.
If set, tiles will only be loaded inside the set LatLngBounds.
maxNativeZoom
Number
undefined
Maximum 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.
minNativeZoom
Number
undefined
Minimum 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.
noWrap
Boolean
false
Whether 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.
pane
String
'tilePane'
Map pane where the grid layer will be added.
className
String
''
A custom class name to assign to the tile layer. Empty by default.
keepBuffer
Number
2
When panning the map, keep this many rows and columns of tiles before unloading them.
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.
Called only internally, overrides GridLayer's createTile()
to return an <img> HTML element with the appropriate image URL given coords.
The done callback is called when the tile has been loaded.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Instantiates an image overlay object given the URL of the image (or an image element) and the geographical
bounds it is tied to.
Options
Option
Type
Default
Description
opacity
Number
1
The opacity of the image overlay.
alt
String
''
Text for the alt attribute of the image (useful for accessibility).
interactive
Boolean
false
If true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the image. If a String is provided, the image will have
its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data.
Refer to CORS Settings for valid
String values.
errorOverlayUrl
String
''
URL to the overlay image to show in place of the overlay that failed to load.
A custom class name to assign to the image. Empty by default.
decoding
String
'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'.
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).
Fired 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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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. The
constructor takes the URL of the video (or an array of URLs, or even a video element) in place of the image URL.
Text for the alt attribute of the image (useful for accessibility).
interactive
Boolean
false
If true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the image. If a String is provided, the image will have
its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data.
Refer to CORS Settings for valid
String values.
errorOverlayUrl
String
''
URL to the overlay image to show in place of the overlay that failed to load.
A custom class name to assign to the image. Empty by default.
decoding
String
'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'.
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).
Fired 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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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, passed to the
constructor in place of the image URL. A viewBox attribute is required on the SVG element to zoom in and out
properly.
Text for the alt attribute of the image (useful for accessibility).
interactive
Boolean
false
If true, the image overlay will emit pointer events when clicked or hovered.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the image. If a String is provided, the image will have
its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data.
Refer to CORS Settings for valid
String values.
errorOverlayUrl
String
''
URL to the overlay image to show in place of the overlay that failed to load.
A custom class name to assign to the image. Empty by default.
decoding
String
'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'.
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).
Fired 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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
Path
An abstract class that contains options and constants shared between vector overlays (Polygon, Polyline,
Circle). Do not use it directly. Extends Layer.
Options
Option
Type
Default
Description
stroke
Boolean
true
Whether to draw stroke along the path. Set it to false to disable borders on polygons or circles.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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
Constructor
Description
new Polyline(latlngs: LatLng[]|LatLng[][]|LatLng[][][],options?: Polyline 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
Option
Type
Default
Description
smoothFactor
Number
0.5
How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values
mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
addLatLng(latlng: LatLng,latlngs?: LatLng[]): 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).
toGeoJSON(precision?: Number|false): Feature
Coordinates values are rounded with formatNum function with given
precision. Returns a GeoJSON representation
of the polyline (as a GeoJSON LineString or MultiLineString Feature).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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:
new Polygon(latlngs: LatLng[]|LatLng[][]|LatLng[][][],options?: Polyline 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.
How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values
mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
Coordinates values are rounded with formatNum function with given
precision. Returns a GeoJSON representation
of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).
addLatLng(latlng: LatLng,latlngs?: LatLng[]): 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).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values
mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
Coordinates values are rounded with formatNum function with given
precision. Returns a GeoJSON representation
of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).
addLatLng(latlng: LatLng,latlngs?: LatLng[]): 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).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
Returns the current geographical position of the circle marker
setRadius(radius: Number): this
Sets the radius of a circle marker. Units are in CSS pixels (meters for a Circle).
getRadius(): Number
Returns the current radius of the circle. Units are in CSS pixels (meters for a Circle).
toGeoJSON(precision?: Number|false): Feature
Coordinates values are rounded with formatNum function with
given precision. Returns a GeoJSON
representation of the circle marker (as a GeoJSON Point Feature).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Use this specific instance of Renderer for this path. If not set, the path uses the map's
renderer, which is SVG by default. If set, it overrides the pane option.
className
String
Custom class name set on an element. Only for SVG renderer. Applied when the element is created;
setStyle does not update it afterwards.
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).
Fired 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).
Returns the current geographical position of the circle marker
setRadius(radius: Number): this
Sets the radius of a circle marker. Units are in CSS pixels (meters for a Circle).
getRadius(): Number
Returns the current radius of the circle. Units are in CSS pixels (meters for a Circle).
toGeoJSON(precision?: Number|false): Feature
Coordinates values are rounded with formatNum function with
given precision. Returns a GeoJSON
representation of the circle marker (as a GeoJSON Point Feature).
Changes the appearance of a Path based on the options in the Path options object. Note that
className is an exception: it is applied only when the path element is created,
so passing it here updates the option but leaves the element's class unchanged.
bringToFront(): this
Brings the layer to the top of all path layers.
bringToBack(): this
Brings the layer to the bottom of all path layers.
getElement(): SVGElement
Returns the SVG element of the path, or undefined when it's drawn on a Canvas.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
How 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.
continuous
Boolean
false
When 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)
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
How 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.
continuous
Boolean
false
When 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)
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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);
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).
Fired 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).
Returns a GeoJSON MultiPoint feature with the positions of the group's markers. precision is the number of
decimal places for coordinates, as in toGeoJSON.
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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);
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).
Fired 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).
Returns a GeoJSON MultiPoint feature with the positions of the group's markers. precision is the number of
decimal places for coordinates, as in toGeoJSON.
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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
Constructor
Description
new GeoJSON(geojson?: GeoJSONData|GeoJSONData[],options?: GeoJSON 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
Option
Type
Default
Description
pointToLayer
Function
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);
}
Path options, or a function returning them for a feature, 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. It will receive the feature as the first argument and
its corresponding spawned layer from asFeature as the second. 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.
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).
Fired 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).
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.
Returns a GeoJSON MultiPoint feature with the positions of the group's markers. precision is the number of
decimal places for coordinates, as in toGeoJSON.
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Creates a Layer from a given GeoJSON feature. Can use a custom pointToLayer
and/or coordsToLatLng functions if provided as options. Returns null for a
feature without a geometry.
Creates a multidimensional array of LatLngs from a GeoJSON coordinates array. levelsDeep specifies
the nesting level (0 is for an array of points, 1 for an array of arrays of points, etc., 0 by
default). Can use a custom coordsToLatLng function.
latLngToCoords(latlng: LatLng,precision?: Number|false): Position
Reverse of coordsToLatLngs, with the nesting detected from the array, so
levelsDeep is ignored. close determines whether the first point should be appended to the end of each
flat array to close the feature. False by default. Coordinates values are rounded with
formatNum function.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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>, <img> 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.
class CanvasLayer extends GridLayer {
createTile(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.
class CanvasLayer extends GridLayer {
createTile(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;
}
}
Width and height of tiles in the grid. Use a number if width
and height are equal, or Point(width, height) otherwise.
opacity
Number
1
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
false
Load new tiles only when panning ends.
updateWhenZooming
Boolean
true
By 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.
updateInterval
Number
200
Tiles will not update more than once every updateInterval milliseconds when panning.
If set, tiles will only be loaded inside the set LatLngBounds.
minZoom
Number
0
The minimum zoom level down to which this layer will be displayed (inclusive).
maxZoom
Number
undefined
The maximum zoom level up to which this layer will be displayed (inclusive).
maxNativeZoom
Number
undefined
Maximum 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.
minNativeZoom
Number
undefined
Minimum 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.
noWrap
Boolean
false
Whether 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.
pane
String
'tilePane'
Map pane where the grid layer will be added.
className
String
''
A custom class name to assign to the tile layer. Empty by default.
keepBuffer
Number
2
When panning the map, keep this many rows and columns of tiles before unloading them.
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.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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:
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
Constructor
Description
new LatLng(lat: Number,lng: Number,alt?: Number)
Creates an object representing a geographical point with the given latitude and longitude (and optionally
altitude).
Expects an array of the form [Number, Number] or [Number, Number, Number], or a 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.
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(precision?: Number): String
Returns a string representation of the point (for debugging purposes).
Expects an array of the form [Number, Number] or [Number, Number, Number], or a plain object of the form
{lat: Number, lng: Number}. Returns true if the LatLng object can be properly initialized.
Properties
Property
Type
Description
lat
Number
Latitude in degrees
lng
Number
Longitude in degrees
alt
Number
Altitude 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:
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.
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.
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.
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.
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:
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
Constructor
Description
new Point(x: Number,y: Number,round?: Boolean)
Creates a Point object with the given x and y coordinates. If
optional round is set to true, rounds the x and y values.
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.
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:
Function
Description
validate(x: Number,y?: Number): Boolean
Returns true if the Point object can be properly initialized.
validate(coords: *): Boolean
Expects an array of the form [x, y] or a plain object of the form {x: Number, y: Number}. Returns true if
the Point object can be properly initialized.
Properties
Property
Type
Description
x
Number
The x coordinate of the point
y
Number
The 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.
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.
The 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.
The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not
specified).
className
String
''
A custom class name to assign to both icon and shadow images.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will
have their crossOrigin attribute set to the String provided. Refer to CORS
Settings for valid String values.
Methods
Method
Description
createIcon(oldIcon?: HTMLElement): HTMLElement
Called internally when the icon has to be shown, returns
a <img> HTML element styled according to the options.
A subclass of Icon, represents the icon to use in Markers when no icon is specified. The marker, with a soft
shadow under its tip, is one inlined SVG data URI, so it needs no image files.
DefaultIcon
new Marker(latlng, {icon: new DefaultIcon({color: 'crimson'})}).addTo(map);
In order to customize the default icon, just change the properties of DefaultIcon.defaultOptions (which is a
set of Icon options).
If you want to completely replace the default icon, override the Marker.defaultOptions.icon with your own
icon instead.
The 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.
The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not
specified).
className
String
''
A custom class name to assign to both icon and shadow images.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will
have their crossOrigin attribute set to the String provided. Refer to CORS
Settings for valid String values.
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.
The 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.
The coordinates of the "tip" of the shadow (relative to its top left corner) (the same as iconAnchor if not
specified).
className
String
''
A custom class name to assign to both icon and shadow images.
crossOrigin
Boolean|String
false
Whether the crossOrigin attribute will be added to the icon images. If a String is provided, all images will
have their crossOrigin attribute set to the String provided. Refer to CORS
Settings for valid String values.
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.
Removes the control from the map it is currently active on.
AttributionControl
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.
Removes the control from the map it is currently active on.
LayersControl
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.
new LayersControl(baseLayers?: Object,overlays?: Object,options?: LayersControl 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
Option
Type
Default
Description
collapsed
Boolean
true
If true, the control will be collapsed into an icon and expanded
on pointer hover, touch, or keyboard activation.
collapseDelay
Number
0
Collapse delay in milliseconds. If greater than 0, the control will remain
open longer, making it easier to scroll through long layer lists.
autoZIndex
Boolean
true
If 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.
hideSingleBase
Boolean
false
If true, the base layers in the control will be hidden when there is only one.
sortLayers
Boolean
false
Whether to sort the layers. When false, layers will keep
the order in which they were added to the control.
sortFunction
Function
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.
Removes the control from the map it is currently active on.
Util
Various utility functions, used by Leaflet internally.
Functions
Function
Description
stamp(obj: Object): Number
Returns the unique ID of an object, assigning it one if it doesn't have it.
throttle(fn: Function,time: Number,context?: Object): Function
Returns 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(num: Number,range: Number[],includeMax?: Boolean): Number
Returns the number num modulo range in such a way so it lies within range[0] and range[1].
The returned value will always be smaller than range[1] unless includeMax is set to true.
falseFn(): false
Always returns false. Handy as a listener or callback that does nothing.
formatNum(num: Number,precision?: Number|false): Number
Returns the number num rounded with specified precision. The default precision value is 6 decimal
places. false can be passed to skip any processing (can be useful to avoid round-off errors).
splitWords(str: String): String[]
Trims and splits the string on whitespace and returns the array of parts.
setOptions(obj: Object,options?: Object): Object
Merges the given properties to the options of the obj object, returning the resulting options. See
Class options.
template(str: String,data: Object): String
Simple 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.
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
Constructor
Description
new Transformation(a: Number,b: Number,c: Number,d: Number)
Instantiates a Transformation object with the given coefficients.
new Transformation(coefficients: Number[])
Expects an coefficients array of the form [a: Number, b: Number, c: Number, d: Number].
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(p: Point,p1: Point,p2: Point): Number
Returns the distance between point p and segment p1 to p2.
Clips the segment a to b by rectangular bounds with the Cohen-Sutherland
algorithm. Used by Leaflet to only show
polyline points that are on the screen or near, increasing performance. Returns the clipped endpoints (new points
where clipped, rounded with round), or false if the segment is entirely outside the bounds. useLastCode
reuses the bit code of b from the previous call as the code of a, for clipping consecutive segments of a line.
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.
Adds 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(el: EventTarget,eventMap: Object,context?: *)
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
Removes 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(el: EventTarget,eventMap: Object,context?: *)
Removes a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(el: EventTarget,types: String)
Removes all previously added listeners of given types.
off(el: EventTarget)
Removes all previously added listeners from given element.
Given a Leaflet event, it stops the map from handling the original DOM event.
disableScrollPropagation(el: HTMLElement)
Adds stopPropagation to the element's 'wheel' events (plus browser variants).
disableClickPropagation(el: HTMLElement)
Adds stopPropagation to the element's 'dblclick', 'contextmenu' and 'pointerdown'
events (plus browser variants). For 'click' events, prevents the map from handling the
click while still allowing the native DOM click event to propagate normally.
Prevents the default action of the DOM Event e 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.
Does stopPropagation and preventDefault at the same time. Given a Leaflet event, it only stops propagation:
the default action of the original DOM event still happens.
getPointerPosition(e: MouseEvent,container?: HTMLElement): Point
Gets normalized pointer position from a DOM event relative to the container
(border excluded) or to the whole page if not specified.
getWheelDelta(e: WheelEvent): 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.
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
Function
Description
get(id: String|HTMLElement): HTMLElement
Returns an element given its DOM id, or returns the element itself if it was passed directly.
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.
Sets the position of el to coordinates specified by point using a CSS translate (used
by Leaflet internally to position its layers). With flat, the translate is 2D, so el is
painted into its parent's compositor layer instead of getting a layer of its own.
Finds the closest parent node which size (width and height) is not null.
getScale(element: HTMLElement): Object
Computes 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().
Draggable
A class for making DOM elements draggable. Used internally
for map and marker dragging. Works on any DOM element
Usage example
const draggable = new Draggable(elementToDrag);
draggable.enable();
Constructor
Constructor
Description
new Draggable(element: HTMLElement,dragStartTarget?: HTMLElement,options?: Draggable options)
Creates a Draggable object for moving element when you start dragging
the dragStartTarget element (equals element itself by default).
Options
Option
Type
Default
Description
clickTolerance
Number
3
The 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).
Ends the current drag, firing dragend if the element was moved. noInertia is passed on in the event, so
that the map doesn't keep panning after a drag ended this way.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Removes an event parent, so it will stop receiving propagated events
Class
Class is the base of Evented, Handler, Icon and Control, and
through them of almost all of the Leaflet classes documented here.
Leaflet classes are plain JavaScript classes: extend them with extends and
put setup code in constructor(), after calling super(). Class adds what plugins
need on top of that: default options, mixins and constructor hooks.
Usage example
class MyClass extends Class {
constructor(greeter) {
super();
this.greeter = greeter;
}
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");
Leaflet 1.x classes used an initialize() method instead of constructor(). Constructing
a class that still has an initialize() method throws an error.
Options
Declare the default options of a class with a static defaultOptions field. They
are merged with the default options of the parent class instead of replacing them,
which makes managing configuration of objects and default values convenient:
class MyClass extends Class {
static defaultOptions = {
myOption1: 'foo',
myOption2: 'bar'
};
}
class MyChildClass extends MyClass {
static defaultOptions = {
myOption1: 'baz',
myOption3: 5
};
}
const a = new MyChildClass();
a.options.myOption1; // 'baz'
a.options.myOption2; // 'bar'
a.options.myOption3; // 5
Every instance gets its own options object, which inherits from the default options of its class. Changing
a default later, like Marker.defaultOptions.riseOnHover = true, affects all instances that don't set
the option themselves. mergeOptions() adds or changes defaults of an existing class without touching
the defaults of its parent, which makes it the way to change defaults from a plugin:
MyChildClass.mergeOptions({myOption4: true});
There's also Util.setOptions, a method for conveniently merging
options passed to constructor with the defaults defined in the class:
class MyClass extends Class {
static defaultOptions = {
foo: 'bar',
bla: 5
};
constructor(options) {
super();
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.
Mixins
You can add methods and properties from other objects using the include method (such objects are called
mixins). An options property of the mixin is merged into the default options of the class:
const MyMixin = {
foo() { ... },
bar: 5
};
class MyClass extends Class {}
MyClass.include(MyMixin);
const a = new MyClass();
a.foo();
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(function () {
// ... 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, …);
Hooks added to a class also run for instances of its subclasses, parent class hooks first, and
each hook runs once per instance. For Leaflet's own classes, they run after the constructor
has finished, so a hook added to Layer sees a fully built Polygon. For a class of your own
that extends a Leaflet class, they run before the constructor body of your class.
If other code adds hooks to a class of yours and these hooks need the constructor of your class to have run,
mark the class with static initHooks = true and end its constructor with this.callInitHooks():
Called at the end of the constructor of every class with static initHooks = true. The last of these calls,
from the deepest such class, runs all hooks of the chain once, so they see a fully built instance.
Deprecated alias of mergeOptions, kept for code written for 2.0.0-alpha.1.
addInitHook(fn: Function|String,…args: *): this
Adds a constructor hook to the class: a function called with the instance as
this, or the name of a method to call with the given arguments.
Properties
Property
Type
Description
initHooks
Boolean
Marks a class whose constructor ends with this.callInitHooks(). Set it as static initHooks = true on a
plugin class whose own constructor hooks need its constructor to run first.
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).
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
Method
Description
on(type: String,fn: Function,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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Removes an event parent, so it will stop receiving propagated events
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
Option
Type
Default
Description
pane
String
'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).
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.
Method
Description
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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();
Method
Description
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
Every layer should extend from Layer and (re-)implement the following methods.
Method
Description
getElement(): Element
Optional method. Should return the layer's main element. A layer that has one gets keyboard access to its
bound tooltip: the tooltip opens when the element is focused, and the element is described by it.
eachLayer(fn: Function,context?: *): *
Optional method. Should call fn on each of the layer's member layers. A layer without its own
getElement that has it gives keyboard access to its bound tooltip through the
elements of its members instead.
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).
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 on.
The event handlers in this object will be automatically added and removed from the map with your layer.
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.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Removes an event parent, so it will stop receiving propagated events
Properties
Property
Type
Description
feature
Feature
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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
Option
Type
Default
Description
interactive
Boolean
If false, the layer will not emit pointer events and will
act as a part of the underlying map.
bubblingPointerEvents
Boolean
When true, a pointer event on this layer will trigger the
same event on the map (unless DomEvent.stopPropagation is used).
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).
Fired 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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
Adds 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. Leaflet comes with LonLatProjection,
MercatorProjection and SphericalMercatorProjection out of the box.
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.
The bounds (specified in CRS units) where the projection is valid.
Defined projections
Projection
Description
LonLatProjection
Equirectangular, 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.
MercatorProjection
Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that Earth is an ellipsoid. Used by
the EPSG:3395 CRS.
SphericalMercatorProjection
Spherical 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
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.
Given a projected coordinate returns the corresponding LatLng. The inverse of project.
scale(zoom: Number): 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(scale: Number): Number
Inverse of scale(), returns the zoom level corresponding to a scale factor of scale.
The transformation the CRS uses to turn projected coordinates into pixels at zoom 0.
wrapLng
Number[]
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.
wrapLat
Number[]
Like wrapLng, but for the latitude (vertical) axis.
infinite
Boolean
If true, the coordinate space will be unbounded (infinite in both axes)
Defined CRSs
CRS
Description
EPSG3395
Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.
EPSG3857
The 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.
EPSG4326
A 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.
EarthCRS
Serves 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.
SimpleCRS
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.
How 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.
continuous
Boolean
false
When 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)
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).
Fired when a tooltip bound to this layer is closed.
Methods
Subclass interface
Subclasses must define the following methods:
Method
Description
_initContainer()
Must initialize the HTML element to use as blanket, and store it as this._container. The base
implementation creates a blank <div>.
_destroyContainer()
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.
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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).
How 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.
continuous
Boolean
false
When 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)
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).
bindPopup(content: String|HTMLElement|Function|Popup,options?: Popup options): this
Binds a popup to the layer with the passed content and sets up the necessary event listeners. A
String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the popup bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
bindTooltip(content: String|HTMLElement|Function|Tooltip,options?: Tooltip options): this
Binds a tooltip to the layer with the passed content and sets up the necessary event listeners.
A String argument is rendered as HTML; if it may contain untrusted input, sanitize it (e.g. with
DOMPurify) or pass an HTMLElement with safe textContent instead. 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.
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(content: String|HTMLElement|Function): this
Sets the content of the tooltip bound to this layer. String content is rendered as HTML;
sanitize untrusted input or pass an HTMLElement with safe textContent instead.
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(eventMap: Object,context?: *): this
Adds a set of type/listener pairs, e.g. {click: onClick, pointermove: onPointerMove}
off(type: String,fn?: Function,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(eventMap: Object,context?: *): 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(type: String,data?: Object,propagate?: Boolean): 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.
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.
The GeoJSON feature the layer was created from, set by GeoJSON on each layer it creates and
used by toGeoJSON to keep its properties.
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. This is the base event object: all other event objects
contain these properties too.
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. This is the base event object: all other event objects
contain these properties too.
Handlermethods). For example: