Whether a zoom control is added to the map by default.
Interaction Options
Option
Type
Default
Description
closePopupOnClick
Boolean
true
Set it to false if you don't want popups to close when user clicks the map.
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.
boxZoom
Boolean
true
Whether the map can be zoomed to a rectangular area specified by
dragging the mouse 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 mouse was.
dragging
Boolean
true
Whether the map be draggable with mouse/touch or not.
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
*
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. L.SVG
or L.Canvas by default depending on browser support.
Animation Options
Option
Type
Default
Description
zoomAnimation
Boolean
true
Whether the map zoom animation is enabled. By default it's enabled
in all browsers that support CSS3 Transitions except Android.
zoomAnimationThreshold
Number
4
Won't animate zoom if the zoom difference exceeds this value.
fadeAnimation
Boolean
true
Whether the tile fade animation is enabled. By default it's enabled
in all browsers that support CSS3 Transitions except Android.
markerZoomAnimation
Boolean
true
Whether markers animate their zoom with the zoom animation, if disabled
they will disappear for the length of the animation. By default it's
enabled in all browsers that support CSS3 Transitions except Android.
transform3DLimit
Number
2^23
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.
Panning Inertia Options
Option
Type
Default
Description
inertia
Boolean
*
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 unless running on old Android devices.
inertiaDeceleration
Number
3000
The rate with which the inertial movement slows down, in pixels/second².
inertiaMaxSpeed
Number
Infinity
Max speed of the inertial movement, in pixels/second.
easeLinearity
Number
0.2
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.
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.
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 mouse was.
wheelDebounceTime
Number
40
Limits the rate at which a wheel can fire (in milliseconds). By default
user can't zoom via wheel more often than once per 40 ms.
wheelPxPerZoomLevel
Number
60
How many scroll pixels (as reported by L.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
tap
Boolean
true
Enables mobile hacks for supporting instant taps (fixing 200ms click
delay on iOS/Android) and touch holds (fired as contextmenu events).
tapTolerance
Number
15
The max number of pixels a user can shift his finger during touch
for it to be considered a valid tap.
touchZoom
Boolean|String
*
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 except for old Androids.
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.
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).
Fired when the user presses a key from the keyboard while the map is focused. Unlike the keypress event,
the keydown event is fired for keys that produce a character value and for keys
that do not produce a character value.
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.
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, paddingTopLeft and paddingTopRight options to fit
the display to more restricted bounds, like fitBounds.
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.
invalidateSize(<Boolean>animate)
this
Checks if the map container size changed and updates the map if so —
call it after you've changed the map size dynamically, also animating
pan by default.
stop()
this
Stops the currently running panTo or flyTo animation, if any.
Tries to locate the user using the Geolocation API, firing a locationfound
event with location data on success or a locationerror event on failure,
and optionally sets the map view to the user's location with respect to
detection accuracy (or to the world view if geolocation failed).
Note that, if your page doesn't use HTTPS, this method will fail in
modern browsers (Chrome 50 and newer)
See Locate options for more details.
stopLocate()
this
Stops watching location previously initiated by map.locate({watch: true})
and aborts resetting the map view if map.locate was called with
{setView: true}.
Other Methods
Method
Returns
Description
addHandler(<String>name, <Function>HandlerClass)
this
Adds a new Handler to the map, given its name and constructor function.
remove()
this
Destroys the map and clears all related event listeners.
createPane(<String>name, <HTMLElement>container?)
HTMLElement
Creates a new map pane with the given name if it doesn't exist already,
then returns it. The pane is created as a child of container, or
as a child of the main map pane if not set.
getPane(<String|HTMLElement>pane)
HTMLElement
Returns a map pane, given its name or its HTML element (its identity).
getPanes()
Object
Returns a plain object containing the names of all panes as keys and
the panes as values.
getContainer()
HTMLElement
Returns the HTML element that contains the map.
whenReady(<Function>fn, <Object>context?)
this
Runs the given function fn when the map gets initialized with
a view (center and zoom) and at least one layer, or immediately
if it's already initialized, optionally passing a function context.
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 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
Returns
Description
getZoomScale(<Number>toZoom, <Number>fromZoom)
Number
Returns the scale factor to be applied to a map transition from zoom level
fromZoom to toZoom. Used internally to help with zoom animations.
getScaleZoom(<Number>scale, <Number>fromZoom)
Number
Returns the zoom level that the map would end up at, if it is at fromZoom
level and everything is scaled by a factor of scale. Inverse of
getZoomScale.
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.
Given a MouseEvent object, returns geographical coordinate where the
event took place.
Method
Returns
Description
on(<String>type, <Function>fn, <Object>context?)
this
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Panes are DOM elements used to control the ordering of layers on the map. You
can access panes with map.getPane or
map.getPanes methods. New panes can be created with the
map.createPane method.
Every map has the following default panes that differ only in zIndex.
Some of the geolocation methods for Map take in an options parameter. This
is a plain javascript object with the following optional components:
Option
Type
Default
Description
watch
Boolean
false
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.
Some of the Map methods which modify the zoom level take in an options
parameter. This is a plain javascript object with the following optional
components:
Option
Type
Default
Description
animate
Boolean
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true, the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation.
Pan options
Some of the Map methods which modify the center of the map take in an options
parameter. This is a plain javascript object with the following optional
components:
Option
Type
Default
Description
animate
Boolean
If true, panning will always be animated if possible. If false, it will
not animate panning, either resetting the map view if panning more than a
screen away, or just setting a new offset for the map pane (except for panBy
which always does the latter).
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).
Zoom/pan options
Option
Type
Default
Description
animate
Boolean
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true, the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation.
Option
Type
Default
Description
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.
Equivalent of setting both top left and bottom right padding to the same value.
maxZoom
Number
null
The maximum possible zoom to use.
Option
Type
Default
Description
animate
Boolean
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true, the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation.
Option
Type
Default
Description
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).
Marker
L.Marker is used to display clickable/draggable icons on the map. Extends Layer.
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 L.Icon.Default is used.
keyboard
Boolean
true
Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.
title
String
''
Text for the browser tooltip that appear on marker hover (no tooltip by default).
alt
String
''
Text for the alt attribute of the icon image (useful for accessibility).
zIndexOffset
Number
0
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.0
The opacity of the marker.
riseOnHover
Boolean
false
If true, the marker will get on top of others when you hover the mouse 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.
bubblingMouseEvents
Boolean
false
When true, a mouse event on this marker will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used).
Draggable marker options
Option
Type
Default
Description
draggable
Boolean
false
Whether the marker is draggable with mouse/touch 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).
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the marker (as a GeoJSON Point Feature).
Method
Returns
Description
addTo(<Map|LayerGroup>map)
this
Adds the layer to the given map or layer group.
remove()
this
Removes the layer from the map it is currently active on.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Interaction handlers are properties of a marker instance that allow you to control interaction behavior in runtime, enabling or disabling certain features such as dragging (see Handler methods). Example:
Marker dragging handler (by both mouse and touch). Only valid when the marker is on the map (Otherwise set marker.options.draggable).
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.
Here's a more complicated way to open a popup on a map:
var popup = L.popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);
Instantiates a Popup object given an optional options object that describes its appearance and location and an optional source object that is used to tag the popup with a reference to the Layer to which it refers.
Options
Option
Type
Default
Description
maxWidth
Number
300
Max width of the popup, in pixels.
minWidth
Number
50
Min width of the popup, in pixels.
maxHeight
Number
null
If set, creates a scrollable container of the given height
inside a popup if its content exceeds it.
autoPan
Boolean
true
Set it to false if you don't want the map to do panning animation
to fit the opened popup.
Sets the HTML content of the popup. 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 popup.
getElement()
String|HTMLElement
Returns the HTML container of the popup.
update()
null
Updates the popup content, layout and position. Useful for updating the popup after something inside changed, e.g. image loaded.
isOpen()
Boolean
Returns true when the popup is visible on the map.
bringToFront()
this
Brings this popup in front of other popups (in the same map pane).
bringToBack()
this
Brings this popup to the back of other popups (in the same map pane).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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.
Instantiates a Tooltip object given an optional options object that describes its appearance and location and an optional source object that is used to tag the tooltip with a reference to the Layer to which it refers.
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 mouseover.
sticky
Boolean
false
If true, the tooltip will follow the mouse instead of being fixed at the feature center.
interactive
Boolean
false
If true, the tooltip will listen to the feature events.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
{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:
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.
Option
Type
Default
Description
tileSize
Number|Point
256
Width and height of tiles in the grid. Use a number if width and height are equal, or L.point(width, height) otherwise.
opacity
Number
1.0
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
(depends)
Load new tiles only when panning ends.
true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation.
false otherwise in order to display new tiles during panning, since it is easy to pan outside the
keepBuffer option in desktop browsers.
updateWhenZooming
Boolean
true
By default, a smooth zoom animation (during a touch 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
Returns
Description
setUrl(<String>url, <Boolean>noRedraw?)
this
Updates the layer's URL template and redraws it (unless noRedraw is set to true).
If the URL does not change, the layer will not be redrawn unless
the noRedraw parameter is set to false.
createTile(<Object>coords, <Function>done?)
HTMLElement
Called only internally, overrides GridLayer's createTile()
to return an <img> HTML element with the appropriate image URL given coords. The done
callback is called when the tile has been loaded.
Extension methods
Layers extending TileLayer might reimplement the following method.
Method
Returns
Description
getTileUrl(<Object>coords)
String
Called only internally, returns the URL for a tile given its coordinates.
Classes extending TileLayer can override this function to provide custom tile URL naming schemes.
Method
Returns
Description
bringToFront()
this
Brings the tile layer to the top of all tile layers.
bringToBack()
this
Brings the tile layer to the bottom of all tile layers.
getContainer()
HTMLElement
Returns the HTML element that contains the tiles for this layer.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object.
Options
If any custom options not documented here are used, they will be sent to the
WMS server as extra parameters in each request URL. This can be useful for
non-standard vendor WMS parameters.
Option
Type
Default
Description
layers
String
''
(required) Comma-separated list of WMS layers to show.
styles
String
''
Comma-separated list of WMS styles.
format
String
'image/jpeg'
WMS image format (use 'image/png' for layers with transparency).
transparent
Boolean
false
If true, the WMS service will return images with transparency.
Coordinate Reference System to use for the WMS requests, defaults to
map CRS. Don't change this if you're not sure what it means.
uppercase
Boolean
false
If true, WMS request parameter keys will be uppercase.
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.
Option
Type
Default
Description
tileSize
Number|Point
256
Width and height of tiles in the grid. Use a number if width and height are equal, or L.point(width, height) otherwise.
opacity
Number
1.0
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
(depends)
Load new tiles only when panning ends.
true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation.
false otherwise in order to display new tiles during panning, since it is easy to pan outside the
keepBuffer option in desktop browsers.
updateWhenZooming
Boolean
true
By default, a smooth zoom animation (during a touch 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
Returns
Description
setParams(<Object>params, <Boolean>noRedraw?)
this
Merges an object with the new parameters and re-requests tiles on the current screen (unless noRedraw was set to true).
Method
Returns
Description
setUrl(<String>url, <Boolean>noRedraw?)
this
Updates the layer's URL template and redraws it (unless noRedraw is set to true).
If the URL does not change, the layer will not be redrawn unless
the noRedraw parameter is set to false.
createTile(<Object>coords, <Function>done?)
HTMLElement
Called only internally, overrides GridLayer's createTile()
to return an <img> HTML element with the appropriate image URL given coords. The done
callback is called when the tile has been loaded.
Method
Returns
Description
bringToFront()
this
Brings the tile layer to the top of all tile layers.
bringToBack()
this
Brings the tile layer to the bottom of all tile layers.
getContainer()
HTMLElement
Returns the HTML element that contains the tiles for this layer.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Instantiates an image overlay object given the URL of the image and the
geographical bounds it is tied to.
Options
Option
Type
Default
Description
opacity
Number
1.0
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 mouse 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.
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).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Text for the alt attribute of the image (useful for accessibility).
interactive
Boolean
false
If true, the image overlay will emit mouse 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.
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).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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.
Instantiates an image overlay object given an SVG element and the geographical bounds it is tied to.
A viewBox attribute is required on the SVG element to zoom in and out properly.
Options
Option
Type
Default
Description
opacity
Number
1.0
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 mouse 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.
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).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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.
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).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
A class for drawing polyline overlays on a map. Extends Path.
Usage example
// create a red polyline from an array of LatLng points
var latlngs = [
[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2]
];
var polyline = L.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
var 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]]
];
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
1.0
How much to simplify the polyline on each zoom level. More means
better performance and smoother look, and less means more accurate representation.
noClip
Boolean
false
Disable polyline clipping.
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.
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).
Fired when a tooltip bound to this layer is closed.
Methods
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the polyline (as a GeoJSON LineString or MultiLineString Feature).
getLatLngs()
LatLng[]
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
setLatLngs(<LatLng[]>latlngs)
this
Replaces all the points in the polyline with the given array of geographical points.
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).
Method
Returns
Description
redraw()
this
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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
var latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];
var polygon = L.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:
var latlngs = [
[[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
[[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
];
Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.
var latlngs = [
[ // first polygon
[[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
[[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
],
[ // second polygon
[[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
]
];
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).
Fired when a tooltip bound to this layer is closed.
Methods
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).
Method
Returns
Description
getLatLngs()
LatLng[]
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
setLatLngs(<LatLng[]>latlngs)
this
Replaces all the points in the polyline with the given array of geographical points.
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).
Method
Returns
Description
redraw()
this
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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).
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the polygon (as a GeoJSON Polygon or MultiPolygon Feature).
Method
Returns
Description
getLatLngs()
LatLng[]
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
setLatLngs(<LatLng[]>latlngs)
this
Replaces all the points in the polyline with the given array of geographical points.
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).
Method
Returns
Description
redraw()
this
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
A class for drawing circle overlays on a map. Extends CircleMarker.
It's an approximation and starts to diverge from a real circle closer to poles (due to projection distortion).
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).
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the circle marker (as a GeoJSON Point Feature).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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).
Fired when a tooltip bound to this layer is closed.
Methods
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the circle marker (as a GeoJSON Point Feature).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
VML was deprecated in 2012, which means VML functionality exists only for backwards compatibility
with old versions of Internet Explorer.
Allows vector layers to be displayed with SVG.
Inherits Renderer.
Due to technical limitations, SVG is not
available in all web browsers, notably Android 2.x and 3.x.
Although SVG is not available on IE7 and IE8, these browsers support
VML
(a now deprecated technology), and the SVG renderer will fall back to VML in
this case.
Usage example
Use SVG by default for all paths in the map:
var map = L.map('map', {
renderer: L.svg()
});
Use a SVG renderer with extra padding for specific vector geometries:
var map = L.map('map');
var myRenderer = L.svg({ padding: 0.5 });
var line = L.polyline( coordinates, { renderer: myRenderer } );
var circle = L.circle( center, { renderer: myRenderer } );
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
There are several static functions which can be called without instantiating L.SVG:
Function
Returns
Description
create(<String>name)
SVGElement
Returns a instance of SVGElement,
corresponding to the class name passed. For example, using 'line' will return
an instance of SVGLineElement.
pointsToPath(<Point[]>rings, <Boolean>closed)
String
Generates a SVG path string for multiple rings, with each ring turning
into "M..L..L.." instructions
Canvas
Allows vector layers to be displayed with <canvas>.
Inherits Renderer.
Due to technical limitations, Canvas is not
available in all web browsers, notably IE8, and overlapping geometries might
not display properly in some edge cases.
Usage example
Use Canvas by default for all paths in the map:
var map = L.map('map', {
renderer: L.canvas()
});
Use a Canvas renderer with extra padding for specific vector geometries:
var map = L.map('map');
var myRenderer = L.canvas({ padding: 0.5 });
var line = L.polyline( coordinates, { renderer: myRenderer } );
var circle = L.circle( center, { renderer: myRenderer } );
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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.
Fired when a tooltip bound to this layer is closed.
Methods
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).
Returns true if the given layer is currently added to the group.
hasLayer(<Number>id)
Boolean
Returns true if the given internal ID is currently added to the group.
clearLayers()
this
Removes all the layers from the group.
invoke(<String>methodName, …)
this
Calls methodName on every layer contained in this group, passing any
additional parameters. Has no effect if the layers contained do not
implement methodName.
eachLayer(<Function>fn, <Object>context?)
this
Iterates over the layers of the group, optionally specifying context of the iterator function.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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 mouse events
and custom events.
Has layeradd and layerremove events
Usage example
L.featureGroup([marker1, marker2, polyline])
.bindPopup('Hello world!')
.on('click', function() { alert('Clicked on a member of the group!'); })
.addTo(map);
Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).
Returns true if the given layer is currently added to the group.
hasLayer(<Number>id)
Boolean
Returns true if the given internal ID is currently added to the group.
clearLayers()
this
Removes all the layers from the group.
invoke(<String>methodName, …)
this
Calls methodName on every layer contained in this group, passing any
additional parameters. Has no effect if the layers contained do not
implement methodName.
eachLayer(<Function>fn, <Object>context?)
this
Iterates over the layers of the group, optionally specifying context of the iterator function.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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:
A Function defining the Path options for styling GeoJSON lines and polygons,
called internally when data is added.
The default value is to not override any defaults:
function (geoJsonFeature) {
return {}
}
onEachFeature
Function
*
A Function that will be called once for each created Feature, after it has
been created and styled. Useful for attaching events and popups to features.
The default is to do nothing with the newly created layers:
function (feature, layer) {}
filter
Function
*
A Function that will be used to decide whether to include a feature or not.
The default is to include all features:
function (geoJsonFeature) {
return true;
}
Note: dynamically changing the filter option will have effect only on newly
added data. It will not re-evaluate already included features.
coordsToLatLng
Function
*
A Function that will be used for converting GeoJSON coordinates to LatLngs.
The default is the coordsToLatLng static method.
markersInheritOptions
Boolean
false
Whether default Markers for "Point" type Features inherit from group options.
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.
Fired when a tooltip bound to this layer is closed.
Methods
Method
Returns
Description
addData(data)
this
Adds a GeoJSON object to the layer.
resetStyle(layer?)
this
Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events.
If layer is omitted, the style of all features in the current layer is reset.
setStyle(style)
this
Changes styles of GeoJSON vector layers with the given style function.
Method
Returns
Description
bringToFront()
this
Brings the layer group to the top of all other layers
bringToBack()
this
Brings the layer group to the back of all other layers
Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).
Method
Returns
Description
toGeoJSON(<Number>precision?)
Object
precision is the number of decimal places for coordinates.
The default value is 6 places.
Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection, GeometryCollection, or MultiPoint).
Returns true if the given layer is currently added to the group.
hasLayer(<Number>id)
Boolean
Returns true if the given internal ID is currently added to the group.
clearLayers()
this
Removes all the layers from the group.
invoke(<String>methodName, …)
this
Calls methodName on every layer contained in this group, passing any
additional parameters. Has no effect if the layers contained do not
implement methodName.
eachLayer(<Function>fn, <Object>context?)
this
Iterates over the layers of the group, optionally specifying context of the iterator function.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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.
Reverse of coordsToLatLngsclosed determines whether the first point should be appended to the end of the array to close the feature, only used when levelsDeep is 0. False by default.
asFeature(<Object>geojson)
Object
Normalize GeoJSON geometries/features into GeoJSON features.
GridLayer
Generic class for handling a tiled grid of HTML elements. This is the base class for all tile layers and replaces TileLayer.Canvas.
GridLayer can be extended to create a tiled grid of HTML elements like <canvas>, <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.
var CanvasLayer = L.GridLayer.extend({
createTile: function(coords){
// create a <canvas> element for drawing
var tile = L.DomUtil.create('canvas', 'leaflet-tile');
// setup tile width and height according to the options
var 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
var 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.
var CanvasLayer = L.GridLayer.extend({
createTile: function(coords, done){
var error;
// create a <canvas> element for drawing
var tile = L.DomUtil.create('canvas', 'leaflet-tile');
// setup tile width and height according to the options
var 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;
}
});
Creates a new instance of GridLayer with the supplied options.
Options
Option
Type
Default
Description
tileSize
Number|Point
256
Width and height of tiles in the grid. Use a number if width and height are equal, or L.point(width, height) otherwise.
opacity
Number
1.0
Opacity of the tiles. Can be used in the createTile() function.
updateWhenIdle
Boolean
(depends)
Load new tiles only when panning ends.
true by default on mobile browsers, in order to avoid too many requests and keep smooth navigation.
false otherwise in order to display new tiles during panning, since it is easy to pan outside the
keepBuffer option in desktop browsers.
updateWhenZooming
Boolean
true
By default, a smooth zoom animation (during a touch 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.
Normalizes the tileSize option into a point. Used by the createTile() method.
Extension methods
Layers extending GridLayer shall reimplement the following method.
Method
Returns
Description
createTile(<Object>coords, <Function>done?)
HTMLElement
Called only internally, must be overridden by classes extending GridLayer.
Returns the HTMLElement corresponding to the given coords. If the done callback
is specified, it must be called when the tile has finished loading and drawing.
Method
Returns
Description
addTo(<Map|LayerGroup>map)
this
Adds the layer to the given map or layer group.
remove()
this
Removes the layer from the map it is currently active on.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Represents a geographical point with a certain latitude and longitude.
Usage example
var latlng = L.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.
Returns true if the given LatLng point is at the same position (within a small margin of error). The margin of error can be overridden by setting maxMargin to a small number.
toString()
String
Returns a string representation of the point (for debugging purposes).
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 by defining two diagonally opposite corners of the rectangle.
L.latLngBounds(<LatLng[]>latlngs)
Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds.
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
var point = L.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.
Creation
Factory
Description
L.point(<Number>x, <Number>y, <Boolean>round?)
Creates a Point object with the given x and y coordinates. If optional round is set to true, rounds the x and y values.
L.point(<Number[]>coords)
Expects an array of the form [x, y] instead.
L.point(<Object>coords)
Expects a plain object of the form {x: Number, y: Number} instead.
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.
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.
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. Empty by default.
Methods
Method
Returns
Description
createIcon(<HTMLElement>oldIcon?)
HTMLElement
Called internally when the icon has to be shown, returns a <img> HTML element
styled according to the options.
createShadow(<HTMLElement>oldIcon?)
HTMLElement
As createIcon, but for the shadow beneath it.
Icon.Default
A trivial subclass of Icon, represents the icon to use in Markers when
no icon is specified. Points to the blue marker image distributed with Leaflet
releases.
In order to customize the default icon, just change the properties of L.Icon.Default.prototype.options
(which is a set of Icon options).
If you want to completely replace the default icon, override the
L.Marker.prototype.options.icon with your own icon instead.
Option
Type
Default
Description
imagePath
String
Icon.Default will try to auto-detect the location of the
blue icon images. If you are placing these images in a non-standard
way, set this option to point to the right path.
DivIcon
Represents a lightweight icon for markers that uses a simple <div>
element instead of an image. Inherits from Icon but ignores the iconUrl and shadow options.
Usage example
var myIcon = L.divIcon({className: 'my-div-icon'});
// you can set .my-div-icon styles in CSS
L.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. Empty by default.
Methods
Method
Returns
Description
createIcon(<HTMLElement>oldIcon?)
HTMLElement
Called internally when the icon has to be shown, returns a <img> HTML element
styled according to the options.
createShadow(<HTMLElement>oldIcon?)
HTMLElement
As createIcon, but for the shadow beneath it.
Control.Zoom
A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its zoomControl option to false. Extends Control.
Removes the control from the map it is currently active on.
Control.Attribution
The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its attributionControl option to false, and it fetches attribution texts from layers with the getAttribution method automatically. Extends Control.
Removes the control from the map it is currently active on.
Control.Layers
The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the detailed example). Extends Control.
Usage example
var baseLayers = {
"Mapbox": mapbox,
"OpenStreetMap": osm
};
var overlays = {
"Marker": marker,
"Roads": roadsLayer
};
L.control.layers(baseLayers, overlays).addTo(map);
The baseLayers and overlays parameters are object literals with layer names as keys and Layer objects as values:
{
"<someName1>": layer1,
"<someName2>": layer2
}
The layer names can contain HTML, which allows you to add additional styling to the items:
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 mouse hover or touch.
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 L.Layer instances and their names, as in
sortFunction(layerA, layerB, nameA, nameB).
By default, it sorts layers alphabetically by their name.
Option
Type
Default
Description
position
String
'topright'
The position of the control (one of the map corners). Possible values are 'topleft',
'topright', 'bottomleft' or 'bottomright'
true for all browsers supporting touch events.
This does not necessarily mean that the browser is running in a computer with
a touchscreen, it only means that the browser is capable of understanding
touch events.
mobileOpera
Boolean
true for the Opera browser in a mobile device.
mobileGecko
Boolean
true for gecko-based browsers running in a mobile device.
retina
Boolean
true for browsers on a high-resolution "retina" screen or on any screen when browser's display zoom is more than 100%.
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.
Has an L.throttle shortcut.
Returns the number num modulo range in such a way so it lies within
range[0] and range[1]. The returned value will be always smaller than
range[1] unless includeMax is set to true.
falseFn()
Function
Returns a function which always returns false.
formatNum(<Number>num, <Number>digits?)
Number
Returns the number num rounded to digits decimals, or to 6 decimals by default.
Converts an object into a parameter URL string, e.g. {a: "foo", b: "bar"}
translates to '?a=foo&b=bar'. If existingUrl is set, the parameters will
be appended at the end. If uppercase is true, the parameter names will
be uppercased (e.g. '?A=foo&B=bar')
template(<String>str, <Object>data)
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.
Schedules fn to be executed when the browser repaints. fn is bound to
context if given. When immediate is set, fn is called immediately if
the browser doesn't have native support for
window.requestAnimationFrame,
otherwise it's delayed. Returns a request ID that can be used to cancel the request.
Data URI string containing a base64-encoded empty GIF image.
Used as a hack to free memory from unused images on WebKit-powered
mobile devices (by setting image src to this string).
Transformation
Represents an affine transformation: a set of coefficients a, b, c, d
for transforming a point of a form (x, y) into (a*x + b, c*y + d) and doing
the reverse. Used by Leaflet in its projections code.
Returns the reverse transformation of the given point, optionally divided
by the given scale. Only accepts actual L.Point instances, not arrays.
LineUtil
Various utility functions for polyline points processing, used by Leaflet internally to make polylines lightning-fast.
Functions
Function
Returns
Description
simplify(<Point[]>points, <Number>tolerance)
Point[]
Dramatically reduces the number of points in a polyline while retaining
its shape and returns a new array of simplified points, using the
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.
Clips the segment a to b by rectangular bounds with the
Cohen-Sutherland algorithm
(modifying the segment points directly!). Used by Leaflet to only show polyline
points that are on the screen or near, increasing performance.
isFlat(<LatLng[]>latlngs)
Boolean
Returns true if latlngs is a flat array, false is nested.
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.
DomEvent
Utility functions to work with the DOM events, used by Leaflet internally.
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').
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.
Removes a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
stopPropagation(<DOMEvent>ev)
this
Stop the given event from propagation to parent elements. Used inside the listener functions:
L.DomEvent.on(div, 'click', function (ev) {
L.DomEvent.stopPropagation(ev);
});
disableScrollPropagation(<HTMLElement>el)
this
Adds stopPropagation to the element's 'wheel' events (plus browser variants).
disableClickPropagation(<HTMLElement>el)
this
Adds stopPropagation to the element's 'click', 'doubleclick',
'mousedown' and 'touchstart' events (plus browser variants).
preventDefault(<DOMEvent>ev)
this
Prevents the default action of the DOM Event ev from happening (such as
following a link in the href of the a element, or doing a POST request
with page reload when a <form> is submitted).
Use it inside listener functions.
stop(<DOMEvent>ev)
this
Does stopPropagation and preventDefault at the same time.
Gets normalized mouse position from a DOM event relative to the
container (border excluded) or to the whole page if not specified.
getWheelDelta(<DOMEvent>ev)
Number
Gets normalized wheel delta from a wheel DOM event, in vertical
pixels scrolled (negative if scrolling down).
Events from pointing devices without precise scrolling are mapped to
a best guess of 60 pixels.
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
Returns
Description
get(<String|HTMLElement>id)
HTMLElement
Returns an element given its DOM id, or returns the element itself
if it was passed directly.
getStyle(<HTMLElement>el, <String>styleAttrib)
String
Returns the value for a certain style attribute on an element,
including computed values or values set through CSS.
Creates an HTML element with tagName, sets its class to className, and optionally appends it to container element.
remove(<HTMLElement>el)
Removes el from its parent element
empty(<HTMLElement>el)
Removes all of el's children elements from el
toFront(<HTMLElement>el)
Makes el the last child of its parent, so it renders in front of the other children.
toBack(<HTMLElement>el)
Makes el the first child of its parent, so it renders behind the other children.
hasClass(<HTMLElement>el, <String>name)
Boolean
Returns true if the element's class attribute contains name.
addClass(<HTMLElement>el, <String>name)
Adds name to the element's class attribute.
removeClass(<HTMLElement>el, <String>name)
Removes name from the element's class attribute.
setClass(<HTMLElement>el, <String>name)
Sets the element's class.
getClass(<HTMLElement>el)
String
Returns the element's class.
setOpacity(<HTMLElement>el, <Number>opacity)
Set the opacity of an element (including old IE support).
opacity must be a number from 0 to 1.
testProp(<String[]>props)
String|false
Goes through the array of style names and returns the first name
that is a valid style name for an element. If no such name is found,
it returns false. Useful for vendor-prefixed styles like transform.
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 position,
using CSS translate or top/left positioning depending on the browser
(used by Leaflet internally to position its layers).
Returns the coordinates of an element previously positioned with setPosition.
disableTextSelection()
Prevents the user from generating selectstart DOM events, usually generated
when the user drags the mouse through a page with text. Used internally
by Leaflet to override the behaviour of any click-and-drag interaction on
the map. Affects drag interactions on the whole document.
Makes the outline
of the element el invisible. Used internally by Leaflet to prevent
focusable elements from displaying an outline when the user performs a
drag interaction on them.
Finds the closest parent node which size (width and height) is not null.
getScale(<HTMLElement>el)
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().
Properties
Property
Type
Description
TRANSFORM
String
Vendor-prefixed transform style name (e.g. 'webkitTransform' for WebKit).
TRANSITION
String
Vendor-prefixed transition style name.
TRANSITION_END
String
Vendor-prefixed transitionend event name.
PosAnimation
Used internally for panning animations, utilizing CSS3 Transitions for modern browsers and a timer fallback for IE6-9.
Usage example
var fx = new L.PosAnimation();
fx.run(el, [300, 500], 0.5);
Run an animation of a given element to a new position, optionally setting
duration in seconds (0.25 by default) and easing linearity factor (3rd
argument of the cubic bezier curve,
0.5 by default).
stop()
Stops the animation (if currently running).
Method
Returns
Description
on(<String>type, <Function>fn, <Object>context?)
this
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
A class for making DOM elements draggable (including touch support).
Used internally for map and marker dragging. Only works for elements
that were positioned with L.DomUtil.setPosition.
Usage example
var draggable = new L.Draggable(elementToDrag);
draggable.enable();
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
L.Class powers the OOP facilities of Leaflet and is used to create almost all of the Leaflet classes documented here.
In addition to implementing a simple classical inheritance model, it introduces several special properties for convenient code organization — options, includes and statics.
Usage example
var MyClass = L.Class.extend({
initialize: function (greeter) {
this.greeter = greeter;
// class constructor
},
greet: function (name) {
alert(this.greeter + ', ' + name)
}
});
// create instance of MyClass, passing "Hello" to the constructor
var a = new MyClass("Hello");
// call greet method, alerting "Hello, World"
a.greet("World");
Class Factories
You may have noticed that Leaflet objects are created without using
the new keyword. This is achieved by complementing each class with a
lowercase factory method:
new L.Map('map'); // becomes:
L.map('map');
The factories are implemented very easily, and you can do this for your own classes:
L.map = function (id, options) {
return new L.Map(id, options);
};
Inheritance
You use L.Class.extend to define new classes, but you can use the same method on any class to inherit from it:
var MyChildClass = MyClass.extend({
// ... new properties and methods
});
This will create a class that inherits all methods and properties of the parent class (through a proper prototype chain), adding or overriding the ones you pass to extend. It will also properly react to instanceof:
var a = new MyChildClass();
a instanceof MyChildClass; // true
a instanceof MyClass; // true
You can call parent methods (including constructor) from corresponding child ones (as you do with super calls in other languages) by accessing parent class prototype and using JavaScript's call or apply:
var MyChildClass = MyClass.extend({
initialize: function () {
MyClass.prototype.initialize.call(this, "Yo");
},
greet: function (name) {
MyClass.prototype.greet.call(this, 'bro ' + name + '!');
}
});
var a = new MyChildClass();
a.greet('Jason'); // alerts "Yo, bro Jason!"
Options
options is a special property that unlike other objects that you pass
to extend will be merged with the parent one instead of overriding it
completely, which makes managing configuration of objects and default
values convenient:
var MyClass = L.Class.extend({
options: {
myOption1: 'foo',
myOption2: 'bar'
}
});
var MyChildClass = MyClass.extend({
options: {
myOption1: 'baz',
myOption3: 5
}
});
var a = new MyChildClass();
a.options.myOption1; // 'baz'
a.options.myOption2; // 'bar'
a.options.myOption3; // 5
There's also L.Util.setOptions, a method for
conveniently merging options passed to constructor with the defaults
defines in the class:
var MyClass = L.Class.extend({
options: {
foo: 'bar',
bla: 5
},
initialize: function (options) {
L.Util.setOptions(this, options);
...
}
});
var a = new MyClass({bla: 10});
a.options; // {foo: 'bar', bla: 10}
Note that the options object allows any keys, not just
the options defined by the class and its base classes.
This means you can use the options object to store
application specific information, as long as you avoid
keys that are already used by the class in question.
Includes
includes is a special class property that merges all specified objects into the class (such objects are called mixins).
var MyMixin = {
foo: function () { ... },
bar: 5
};
var MyClass = L.Class.extend({
includes: MyMixin
});
var a = new MyClass();
a.foo();
You can also do such includes in runtime with the include method:
MyClass.include(MyMixin);
statics is just a convenience property that injects specified object properties as the static properties of the class, useful for defining constants:
If you're a plugin developer, you often need to add additional initialization code to existing classes (e.g. editing hooks for L.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, …);
Functions
Function
Returns
Description
extend(<Object>props)
Function
Extends the current class given the properties to be included.
Returns a Javascript function that is a class constructor (to be called with new).
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
Returns
Description
on(<String>type, <Function>fn, <Object>context?)
this
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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 addEventListener. The event handlers in this object will be automatically added and removed from the map with your layer.
getAttribution()
String
This optional method should return a string containing HTML to be shown on the Attribution control whenever the layer is visible.
Optional method. Called on map.addLayer(layer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.
Popup methods
All layers share a set of methods convenient for binding popups to it.
var layer = L.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.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Some Layers can be made interactive - when the user interacts
with such a layer, mouse events like click and mouseover can be handled.
Use the event handling methods to handle these events.
Options
Option
Type
Default
Description
interactive
Boolean
true
If false, the layer will not emit mouse events and will act as a part of the underlying map.
bubblingMouseEvents
Boolean
true
When true, a mouse event on this layer will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used).
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.
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).
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
The inverse of project. Projects a 2D point into a geographical location.
Only accepts actual L.Point instances, not arrays.
Note that the projection instances do not inherit from Leaflet's Class object,
and can't be instantiated. Also, new classes can't inherit from them,
and methods can't be added to them with the include function.
The bounds (specified in CRS units) where the projection is valid
Defined projections
Leaflet comes with a set of already defined Projections out of the box:
Projection
Description
L.Projection.LonLat
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.
L.Projection.Mercator
Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that Earth is an ellipsoid. Used by the EPSG:3395 CRS.
L.Projection.SphericalMercator
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.
Given a projected coordinate returns the corresponding LatLng.
The inverse of project.
scale(<Number>zoom)
Number
Returns the scale used when transforming projected coordinates into
pixel coordinates for a particular zoom. For example, it returns
256 * 2^zoom for Mercator-based CRS.
zoom(<Number>scale)
Number
Inverse of scale(), returns the zoom level corresponding to a scale
factor of scale.
Returns a LatLngBounds with the same size as the given one, ensuring
that its center is within the CRS's bounds.
Only accepts actual L.LatLngBounds instances, not arrays.
Properties
Property
Type
Description
code
String
Standard code name of the CRS passed into WMS services (e.g. 'EPSG:3857')
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 around.
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
L.CRS.EPSG3395
Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.
L.CRS.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.
L.CRS.EPSG4326
A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.
Leaflet 1.0.x complies with the TMS coordinate scheme for EPSG:4326,
which is a breaking change from 0.7.x behaviour. 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.
L.CRS.Earth
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.
L.CRS.Simple
A simple CRS that maps longitude and latitude into x and y directly.
May be used for maps of flat surfaces (e.g. game maps). Note that the y
axis should still be inverted (going from bottom to top). distance() returns
simple euclidean distance.
L.CRS.Base
Object that defines coordinate reference systems for projecting
geographical points into pixel (screen) coordinates and back (and to
coordinates in other units for WMS services). See
spatial reference system.
Leaflet defines the most usual CRSs by default. If you want to use a
CRS not defined by default, take a look at the
Proj4Leaflet plugin.
Note that the CRS instances do not inherit from Leaflet's Class object,
and can't be instantiated. Also, new classes can't inherit from them,
and methods can't be added to them with the include function.
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.
Options
Option
Type
Default
Description
padding
Number
0.1
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
tolerance
Number
0
How much to extend click tolerance round a path/object on the map
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.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
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 (MouseEvent in this case)
});
The information available depends on the event type:
Event
The base event object. All other event objects contain these properties too.
Property
Type
Description
type
String
The event type (e.g. 'click').
target
Object
The object that fired the event. For propagated events, the last object in
the propagation chain that fired the event.
sourceTarget
Object
The object that originally fired the event. For non-propagated events, this will
be the same as the target.
propagatedFrom
Object
For propagated events, the last object that propagated the event to its
event parent.
Binds a popup to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindPopup()
this
Removes the popup previously bound with bindPopup.
Binds a tooltip to the layer with the passed content and sets up the
necessary event listeners. If a Function is passed it will receive
the layer as the first argument and should return a String or HTMLElement.
unbindTooltip()
this
Removes the tooltip previously bound with bindTooltip.
Adds a listener function (fn) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick').
on(<Object>eventMap)
this
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on, you must pass the same context to off in order to remove the listener.
off(<Object>eventMap)
this
Removes a set of type/listener pairs.
off()
this
Removes all listeners to all events on the object. This includes implicitly attached events.
Fires an event of the specified type. You can optionally provide an data
object — the first argument of the listener function will contain its
properties. The event can optionally be propagated to event parents.
listens(<String>type)
Boolean
Returns true if a particular event type has any listeners attached to it.
once(…)
this
Behaves as on(…), except the listener will only get fired once and then removed.
Global switches are created for rare cases and generally make
Leaflet to not detect a particular browser feature even if it's
there. You need to set the switch as a global variable to true
before including Leaflet on the page, like this:
Forces Leaflet to not use touch events even if it detects them.
L_DISABLE_3D
Forces Leaflet to not use hardware-accelerated CSS 3D transforms for positioning (which may cause glitches in some rare environments) even if they're supported.
noConflict
This method restores the L global variable to the original value
it had before Leaflet inclusion, and returns the real Leaflet
namespace so you can put it elsewhere, like this:
<script src='libs/l.js'>
<!-- L points to some other library -->
<script src='leaflet.js'>
<!-- you include Leaflet, it replaces the L variable to Leaflet namespace -->
<script>
var Leaflet = L.noConflict();
// now L points to that other library again, and you can use Leaflet.Map etc.
</script>
version
A constant that represents the Leaflet version in use.
L.version; // contains "1.0.0" (or whatever version is currently in use)
map.getPaneormap.getPanesmethods. New panes can be created with themap.createPanemethod. Every map has the following default panes that differ only in zIndex.