当前所使用的 Leaflet版本为 1.6.0. 如果你使用的是版本不一致,请下载使用对应版本.
API的核心类 — 它用来在页面中创建并操作地图.
// 使用id为map的div容器初始化地图,同时指定地图的中心点和缩放级别
var map = L.map('map', {
center: [51.505, -0.09],
zoom: 13
});
创建示例 | 说明 |
---|---|
L.map(
|
将地图部署在给定ID的DIV容器中,并设置地图的选项。 |
L.map(
|
将地图部署在给定的div标签实例中,并设置地图的选项。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
preferCanvas |
Boolean |
false |
是否应该在一个 Canvas (画布)渲染器上呈现 Path (路径).默认情况下,所有路径都是在 SVG 呈现程序中呈现的。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
attributionControl |
Boolean |
true |
默认情况下,是否将 attribution 版权控件添加到地图中。 |
zoomControl |
Boolean |
true |
默认情况下,是否将 zoom 缩放控制 添加到地图中。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
closePopupOnClick |
Boolean |
true |
如果你不想让Popup弹窗在用户点击地图时关闭,那就把它设为false。 |
zoomSnap |
Number |
1 |
强制地图的缩放级别始终为此的倍数,特别是在 fitBounds() 缩放或缩小后。默认情况下,缩放级别将捕捉到最接近的整数;
较低的值(例如0.5 or 0.1)允许更大的粒度。数值0意味着缩放级别将不会被fitBounds放大或缩小。 可以设置小于1(例如0.5)的值允许更大的展示粒度。 |
zoomDelta |
Number |
1 |
控制当使用了 zoomIn() 、 zoomOut()
以及按+ -键或者使用zoom 缩放控件之后,地图的缩放级别的改变的级别值。 |
trackResize |
Boolean |
true |
地图是否自动处理浏览器窗口调整大小以更新自身。 |
boxZoom |
Boolean |
true |
按住Shift键的同时拖动鼠标,地图是否可以缩放到指定的矩形区域。 |
doubleClickZoom |
Boolean|String |
true |
地图是否可以通过双击放大,并通过双击同时按住shift缩小。如果设置为 'center',双击缩放将缩放到视图的中心,而不管鼠标在哪里。 |
dragging |
Boolean |
true |
地图是否可以通过鼠标/触摸拖动。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
crs |
CRS |
L.CRS.EPSG3857 |
该地图的坐标系。如果你不确定坐标系这是什么意思,请不要改变它。 |
center |
LatLng |
undefined |
初始化地图的中心点位置 |
zoom |
Number |
undefined |
初始化地图的缩放等级 |
minZoom |
Number |
* |
地图的最小缩放级别。 如果未指定,并且地图中至少有一个 GridLayer 或 TileLayer ,则将使用其最低的minZoom选项。 |
maxZoom |
Number |
* |
地图的最大缩放级别。 如果未指定,并且地图中至少有一个 GridLayer 或 TileLayer ,则将使用其最大的maxZoom选项。 |
layers |
Layer[] |
[] |
默认添加到地图上的图层组 |
maxBounds |
LatLngBounds |
null |
当这个选项被设置后,地图被限制在给定的地理边界内, 当用户平移将地图拖动到视图以外的范围时会出现弹回的效果, 并且也不允许缩小视图到给定范围以外的区域(这取决于地图的尺寸). 要动态设置此限制,请使用 setMaxBounds 方法。 |
renderer |
Renderer |
* |
在地图上绘制矢量图层的默认方法,使用 L.SVG 或 L.Canvas
默认情况下取决于浏览器支持。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
zoomAnimation |
Boolean |
true |
是否启用地图缩放动画。默认情况下,它在支持除Android之外的所有支持CSS3的浏览器中启用。 |
zoomAnimationThreshold |
Number |
4 |
如果缩放差异超过此值,则不会生成缩放。 |
fadeAnimation |
Boolean |
true |
是否启用了淡出动画。默认情况下,它在支持除Android之外的所有支持CSS3的浏览器中启用。 |
markerZoomAnimation |
Boolean |
true |
marker标记是否使用缩放动画进行缩放。默认情况下,它在支持除Android之外的所有支持CSS3的浏览器中启用。 |
transform3DLimit |
Number |
2^23 |
定义CSS翻译转换的最大尺寸.默认值不应该改变,除非web浏览器在做了一个大的panBy之后,在错误的位置放置了一个位置。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
inertia |
Boolean |
* |
如果启用,则平移地图将具有惯性效应,其中地图在拖动的同时建立动量并继续沿相同方向移动一段时间。在触摸设备上感觉特别好。默认情况下启用,除非在旧的Android设备上运行。 |
inertiaDeceleration |
Number |
3000 |
惯性运动减速的速度,以像素/秒为单位。 |
inertiaMaxSpeed |
Number |
Infinity |
惯性运动的最大速度,以像素/秒为单位。 |
easeLinearity |
Number |
0.2 |
|
worldCopyJump |
Boolean |
false |
启用此选项后,地图将跟踪当您平移到另一个“复制”的世界地图时,一些如标记和矢量图层等所有叠加元素仍然同步可见。 |
maxBoundsViscosity |
Number |
0.0 |
如果maxBounds设置,该选项将控制当拖动地图时边界的固定度。默认值0.0允许用户以正常速度拖动界限,较高的值将减慢地图拖动,如设置值1.0将使边界完全固定,防止用户拖动界限。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
keyboard |
Boolean |
true |
地图是否可以获得焦点,并且允许用户通过键盘和+/-来进行浏览地图。 |
keyboardPanDelta |
Number |
80 |
按箭头键时平移地图时,平移的像素数量。 |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
scrollWheelZoom |
Boolean|String |
true |
是否可以使用鼠标滚轮放大地图。如果设置为'center',它将缩放到视图的中心,而不管鼠标在哪里。 |
wheelDebounceTime |
Number |
40 |
限制鼠标滚轮的速度(以毫秒为单位)。默认情况下,用户无法通过鼠标滚轮比40 ms更多的缩放一次。 |
wheelPxPerZoomLevel |
Number |
60 |
多少滚动像素(由 L.DomEvent.getWheelDelta 报告)意味着一个完整缩放级别的更改。 较小的值将使滚轮变焦更快(反之亦然) |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
tap |
Boolean |
true |
是否启用移动设备以支持即时点击(在iOS / Android上修复200ms点击延迟)和触控(触发contextmenu事件)。 |
tapTolerance |
Number |
15 |
用户在触摸时,移动手指的像素数超过此值时被认为是有效的tap。 |
touchZoom |
Boolean|String |
* |
是否可以通过用两根手指触摸拖动来缩放地图。如果设置为'center',它将缩放到视图的中心,而不管触摸事件(手指)在哪里。 仅在具有触控功能的网络浏览器中有效,旧版Android除外。 |
bounceAtZoomLimits |
Boolean |
true |
如果您不希望在地图缩放超过最小/最大缩放范围时反弹,请将其设置为false。 |
事件名 | 数据 | 说明 |
---|---|---|
baselayerchange |
LayersControlEvent |
通过图层控件更改基本图层时触发。 |
overlayadd |
LayersControlEvent |
通过图层控件选择叠加层时触发。 |
overlayremove |
LayersControlEvent |
通过图层控件取消选择叠加层时触发。 |
layeradd |
LayerEvent |
将新图层添加到地图时触发。 |
layerremove |
LayerEvent |
从地图上删除某些图层时触发 |
事件名 | 数据 | 说明 |
---|---|---|
zoomlevelschange |
Event |
当地图上的缩放级别数由于添加或移除图层而更改时触发。 |
resize |
ResizeEvent |
调整地图大小时触发。 |
unload |
Event |
当使用 remove 方法销毁地图时触发。 |
viewreset |
Event |
当地图需要重绘其内容时触发(通常发生在地图缩放或加载时)。 对于创建自定义叠加层非常有用。 |
load |
Event |
地图初始化时触发(首次设置其中心和缩放比例时)。 |
zoomstart |
Event |
地图缩放即将更改时(例如在缩放动画之前)触发。 |
movestart |
Event |
当地图视图开始更改时触发(例如,用户开始拖动地图)。 |
zoom |
Event |
在缩放级别的任何更改(包括缩放和飞行动画)期间反复触发。 |
move |
Event |
在地图的任何移动过程中反复触发,包括平移和飞行动画。 |
zoomend |
Event |
更改任何动画后,地图更改时触发。 |
moveend |
Event |
地图中心停止更改时触发(例如,用户停止拖动地图)。 |
事件名 | 数据 | 说明 |
---|---|---|
popupopen |
PopupEvent |
在地图上打开弹出窗口时触发 |
popupclose |
PopupEvent |
当地图中的弹出窗口关闭时触发 |
autopanstart |
Event |
打开弹出窗口时地图开始自动平移时触发。 |
事件名 | 数据 | 说明 |
---|---|---|
tooltipopen |
TooltipEvent |
在地图上打开工具提示时触发。 |
tooltipclose |
TooltipEvent |
地图中的工具提示关闭时触发。 |
事件名 | 数据 | 说明 |
---|---|---|
locationerror |
ErrorEvent |
当获取地理位置(使用 locate 方法)失败时触发。 |
locationfound |
LocationEvent |
当获取地理位置(使用 locate 方法)成功时触发。 |
事件名 | 数据 | 说明 |
---|---|---|
click |
MouseEvent |
当用户点击地图时触发。 |
dblclick |
MouseEvent |
当用户双击地图时触发。 |
mousedown |
MouseEvent |
当用户在地图上按下鼠标按钮时触发。 |
mouseup |
MouseEvent |
当用户释放地图上的鼠标按钮时触发。 |
mouseover |
MouseEvent |
当鼠标进入地图时触发。 |
mouseout |
MouseEvent |
当鼠标离开地图时触发。 |
mousemove |
MouseEvent |
当鼠标在地图上移动时触发。 |
contextmenu |
MouseEvent |
当用户在地图上按下鼠标右键时触发,从而阻止默认浏览器上下文菜单显示,如果此事件上有侦听器。 当用户长按时,也会在移动设备上触发。 |
keypress |
KeyboardEvent |
当用户在聚焦地图时按下键盘上输入字符时触发。 |
keydown |
KeyboardEvent |
当地图聚焦时用户按下键盘上的键时触发。 与keypress事件不同,对于产生字符值的键和不产生字符值的键都会触发keydown事件。 |
keyup |
KeyboardEvent |
当地图聚焦时,用户从键盘上释放键时触发。 |
preclick |
MouseEvent |
在鼠标单击地图之前触发(当您希望在任何现有点击处理程序开始运行之前单击时发生某些事情时,此选项很有用)。 |
事件名 | 数据 | 说明 |
---|---|---|
zoomanim |
ZoomAnimEvent |
每个缩放动画至少触发一次。 对于连续缩放(如捏合缩放),在缩放过程中每帧触发一次。 |
方法名 | 返回值 | 说明 |
---|---|---|
getRenderer( |
Renderer |
返回应用于呈现给定 |
方法名 | 返回值 | 说明 |
---|---|---|
addControl( |
this |
添加控件到地图上 |
removeControl( |
this |
从地图上移除一个指定的控件 |
addLayer( |
this |
添加图层到地图上 |
removeLayer( |
this |
从地图上移除一个指定的图层 |
hasLayer( |
Boolean |
地图上是否存在指定的图层,如果给定的图层当前已被加到地图上,则返回true |
eachLayer(
|
this |
遍历地图的图层,选择指定上下文的迭代器函数。
|
openPopup( |
this |
打开指定的弹窗。(如果之前有打开其他的,会自动关闭,确保只有一个) |
openPopup(
|
this |
创建指定的内容和选项的弹出窗口,并在地图上的给定点打开它。 |
closePopup( |
this |
关闭之前打开的(或给定某个)Popup 弹窗。 |
openTooltip( |
this |
打开指定的Tooltip鼠标工具提示。 |
openTooltip(
|
this |
创建并打开具有指定内容和选项的Tooltip鼠标工具提示。 |
closeTooltip( |
this |
关闭之前打开的(或给定某个)Tooltip鼠标工具提示。 |
方法名 | 返回值 | 说明 |
---|---|---|
setView(
|
this |
设置地图地理视图,参数:中心点经纬度、zoom缩放级别、缩放平移选型。 |
setZoom(
|
this |
设置地图的zoom缩放级别。 |
zoomIn(
|
this |
放大地图级别 (delta为空时,默认值取自 |
zoomOut(
|
this |
缩小地图级别 (delta为空时,默认值取自 |
setZoomAround(
|
this |
缩放地图,同时保持地图上的指定地理位置不变(例如内部用于滚动缩放和双击缩放)。 |
setZoomAround(
|
this |
缩放地图,同时保持地图上相对于左上角的指定像素位置不变。 |
fitBounds(
|
this |
将地图的视图设置在给定的矩形地理范围内,地图会自动计算最大缩放级别和中心点。 |
fitWorld(
|
this |
设置一个地图视图,主要包含整个世界的最大缩放级别。 |
panTo(
|
this |
平移地图到给定的中心点。 |
panBy(
|
this |
通过给定的像素点来平移地图。 |
flyTo(
|
this |
执行平滑的飞行动画,移动缩放地图范围至指定的地理中心和级别。 |
flyToBounds(
|
this |
|
setMaxBounds( |
this |
限制地图的视图在给定的边界里面(参考 maxBounds 参数选项)。 |
setMinZoom( |
this |
设置地图最小缩放级别 (参考 minZoom 参数选项)。 |
setMaxZoom( |
this |
设置地图最大缩放级别 (参考 maxZoom 参数选项)。 |
panInsideBounds(
|
this |
将地图放置到位于给定范围内的最接近的视图(如果不在),并使用特定的options选项(如果有的话)控制动画。 |
panInside(
|
this |
平移地图的最小数量以使 |
invalidateSize(
|
this |
检查地图容器大小是否已更改,并更新地图,如果是这样 - 在动态更改地图大小后调用它,也可以默认动画化。如果options.pan是false,则不会进行平移。 如果options.debounceMoveend是true,它将延迟moveend事件,以便即使该方法被连续调用多次也不会发生。 |
invalidateSize( |
this |
检查地图容器大小是否已更改,并更新地图。当地图容器div大小有变化后,请调用。 |
stop() |
this |
停止当前运行panTo或flyTo动画,如果有的话。 |
方法名 | 返回值 | 说明 |
---|---|---|
locate(
|
this |
尝试使用Geolocation API定位用户,触发具有 |
stopLocate() |
this |
停止监视先前由map.locate({watch:true})初始化的位置,如果通过{setView:true}调用map.locate,则放弃重置地图视图。 |
方法名 | 返回值 | 说明 |
---|---|---|
addHandler(
|
this |
给定其名称和构造函数,将新的 |
remove() |
this |
销毁地图并清除所有相关的事件侦听器。 |
createPane(
|
HTMLElement |
如果给定名称不存在,则创建一个新的地图窗格,然后将其返回。 该窗格被创建为容器的子级,或者被创建为主地图窗格的子级(如果未设置)。 |
getPane( |
HTMLElement |
返回一个地图窗口 map pane,给它一个名称或者HTML的节点。 |
getPanes() |
Object |
返回一个普通对象,其中包含所有窗格的名称为键,并将窗格 panes 作为值。 |
getContainer() |
HTMLElement |
返回一个包含地图的html节点。 |
whenReady(
|
this |
当地图使用视图(中心和缩放)和至少一层初始化时,或者如果已经初始化,则立即运行给定的函数fn(如果已初始化)(可选地传递函数上下文)。 |
方法名 | 返回值 | 说明 |
---|---|---|
getCenter() |
LatLng |
返回地图视图的中心点经纬度 |
getZoom() |
Number |
返回地图此时的缩放级别 |
getBounds() |
LatLngBounds |
返回当前地图视图的矩形边界 |
getMinZoom() |
Number |
返回地图最小缩放级别(如果设置了地图或图层的minZoom参数),默认为0 |
getMaxZoom() |
Number |
返回地图最大缩放级别(如果设置了地图或图层的maxZoom参数) |
getBoundsZoom(
|
Number |
返回给定范围完全适合地图视图的最大缩放级别。如果inside(可选)设置为true,则该方法将返回地图视图适合整个给定边界的最小缩放级别。 |
getSize() |
Point |
返回地图容器的当前大小(以像素为单位)。 |
getPixelBounds() |
Bounds |
返回当前地图视图的像素坐标的边界(在自定义层和覆盖实现中有用)。 |
getPixelOrigin() |
Point |
返回当前地图视图左上角的像素坐标(在自定义层和覆盖实现中有用)。 |
getPixelWorldBounds( |
Bounds |
返回zoom缩放级别的世界边界的像素坐标。如果zoom省略,则使用地图的当前缩放级别。 |
方法名 | 返回值 | 说明 |
---|---|---|
getZoomScale(
|
Number |
返回要应用于从缩放级别从缩放到缩放的地图过渡的比例因子。 在内部使用以帮助缩放动画。 |
getScaleZoom(
|
Number |
返回地图最终到达的缩放级别,如果它处于fromZoom 级别,并且所有内容都按比例缩放scale。 |
project(
|
Point |
|
unproject(
|
LatLng |
逆向 |
layerPointToLatLng( |
LatLng |
给定相对于origin pixel的相应像素坐标,转换为相应的地理坐标(对于当前缩放级别)。 |
latLngToLayerPoint(
|
Point |
给定地理坐标,转换为相对于origin pixel的相应像素坐标。(在地图上进行位置叠加时比较有用) |
wrapLatLng( |
LatLng |
如果它们在CRS的边界之外,则返回一个 |
wrapLatLngBounds(
|
LatLngBounds |
返回 |
distance(
|
Number |
根据地图的参考系来返回两个地理位置之间的距离,默认为米。 |
containerPointToLayerPoint(
|
Point |
给定相对于地图container容器的像素坐标,返回相对于origin pixel的相应像素坐标。 |
layerPointToContainerPoint(
|
Point |
给定相对于origin pixel的像素坐标,返回相对于地图container容器的相应像素坐标。 |
containerPointToLatLng(
|
LatLng |
给定相对于地图container容器的像素坐标,返回对应的地理坐标(对于当前缩放级别)。 |
latLngToContainerPoint(
|
Point |
给定地理坐标,返回相对于地图container容器的相应像素坐标。 |
mouseEventToContainerPoint(
|
Point |
给定一个MouseEvent对象,返回相对于发生事件的地图容器的像素坐标(与地图左上角相关)。 |
mouseEventToLayerPoint(
|
Point |
给定一个MouseEvent对象,返回相对于事件发生的origin pixel的像素坐标。 |
mouseEventToLatLng(
|
LatLng |
给定一个MouseEvent对象,返回发生事件的地理坐标。 |
方法名 | 返回值 | 说明 |
---|---|---|
on(
|
this |
将侦听器函数(fn)添加到对象的特定事件类型。 您可以选择指定侦听器的上下文(此关键字将指向的对象)。 您还可以传递几种以空格分隔的类型(例如'click dblclick')。 |
on( |
this |
添加一组类型/侦听器对,例如 {click:onClick,mousemove:onMouseMove} |
off(
|
this |
删除以前添加的侦听器功能。 如果未指定功能,它将从对象中删除该特定事件的所有侦听器。 请注意,如果将自定义上下文传递给on,则必须将相同的上下文传递给off才能删除侦听器。 |
off( |
this |
删除一组类型/侦听器对。 |
off() |
this |
删除对象上所有事件的所有侦听器。 这包括隐式附加的事件。 |
fire(
|
this |
触发指定类型的事件。 您可以选择提供一个数据对象-侦听器函数的第一个参数将包含其属性。 可以选择将事件传播给事件父级。 |
listens( |
Boolean |
如果特定事件类型具有任何侦听器,则返回true。 |
once(…) |
this |
行为与 |
addEventParent(
|
this |
再父级添加一个事件-将接收传播事件的 |
removeEventParent(
|
this |
删除父级事件,因此它将停止接收传播的事件 |
addEventListener(…) |
this |
同 |
removeEventListener(…) |
this |
同 |
clearAllEventListeners(…) |
this |
同 |
addOneTimeEventListener(…) |
this |
同 |
fireEvent(…) |
this |
同 |
hasEventListeners(…) |
Boolean |
属性 | 类型 | 说明 |
---|---|---|
zoomControl |
Control.Zoom |
默认缩放控件(仅当创建地图时zoomControl 选项为true时可用)。
|
属性 | 类型 | 说明 |
---|---|---|
boxZoom |
Handler |
框(使用鼠标按住Shift键并拖动)缩handler。 |
doubleClickZoom |
Handler |
双击缩放handler。 |
dragging |
Handler |
地图拖动handler(通过鼠标和触摸)。 |
keyboard |
Handler |
键盘导航handler。 |
scrollWheelZoom |
Handler |
滚动轮缩放handler。 |
tap |
Handler |
移动触摸hacks(快速点击和触摸保持)handler。 |
touchZoom |
Handler |
触摸缩放handler。 |
Pane | 类型 | Z-index | 说明 |
---|---|---|---|
mapPane |
HTMLElement |
'auto' |
包含所有map pane的pane |
tilePane |
HTMLElement |
200 |
GridLayer 和TileLayer 的窗格。 |
overlayPane |
HTMLElement |
400 |
矢量(路径 ,如折线 和多边形 ),ImageOverlay 和VideoOverlay 的窗格。 |
shadowPane |
HTMLElement |
500 |
叠加阴影的panes窗格(例如Marker 阴影) |
markerPane |
HTMLElement |
600 |
Marker Icon 图标窗格 |
tooltipPane |
HTMLElement |
650 |
Tooltip 提示框的Pane |
popupPane |
HTMLElement |
700 |
Popup 弹出层的Pane |
Map
的某些地理位置方法采用了options参数。 这是一个普通的javascript对象,具有以下可选组件:Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
watch |
Boolean |
false |
如果为true,则使用W3C watchPosition方法开始连续观察位置变化(而不是检测一次)。 您稍后可以使用map.stopLocate()方法停止观察。 |
setView |
Boolean |
false |
如果为true,则根据检测精度自动将地图视图设置为用户位置,如果地理位置失败则将地图视图设置为世界视图。 |
maxZoom |
Number |
Infinity |
使用setView选项时,自动视图设置的最大缩放比例。 |
timeout |
Number |
10000 |
触发locationerror事件之前等待地理位置响应的毫秒数。 |
maximumAge |
Number |
0 |
检测到的位置的最大年龄。 如果自上次地理位置响应以来经过的时间少于此毫秒数,locate将返回缓存的位置。 |
enableHighAccuracy |
Boolean |
false |
启用高精度,请参阅W3C规范中的描述。 |
Map
方法带有options参数。 这是一个普通的javascript对象,具有以下可选组件:Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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. |
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参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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). |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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). |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
paddingTopLeft |
Point |
[0, 0] |
Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to. |
paddingBottomRight |
Point |
[0, 0] |
The same for the bottom right corner of the map. |
padding |
Point |
[0, 0] |
Equivalent of setting both top left and bottom right padding to the same value. |
maxZoom |
Number |
null |
The maximum possible zoom to use. |
Option参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
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). |
L.Marker is used to display clickable/draggable icons on the map. Extends Layer
.
L.marker([50.5, 30.5]).addTo(map);
Factory | Description |
---|---|
L.marker(
|
Instantiates a Marker object given a geographical point and optionally an options object. |
Option | Type | Default | Description |
---|---|---|---|
icon |
Icon |
* |
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.
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). |
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. |
autoPanPadding |
Point |
Point(50, 50) |
Distance (in pixels to the left/right and to the top/bottom) of the map edge to start panning the map. |
autoPanSpeed |
Number |
10 |
Number of pixels the map should pan by. |
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. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
move |
Event |
Fired when the marker is moved via setLatLng or by dragging. Old and new coordinates are included in event arguments as
oldLatLng , latlng . |
Event | Data | Description |
---|---|---|
dragstart |
Event |
Fired when the user starts dragging the marker. |
movestart |
Event |
Fired when the marker starts moving (because of dragging). |
drag |
Event |
Fired repeatedly while the user drags the marker. |
dragend |
DragEndEvent |
Fired when the user stops dragging the marker. |
moveend |
Event |
Fired when the marker stops moving (because of dragging). |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
addTo()
and
remove()
and popup methods like bindPopup() you can also use the following
methods:Method | Returns | Description |
---|---|---|
getLatLng() |
LatLng |
Returns the current geographical position of the marker. |
setLatLng( |
this |
Changes the marker position to the given point. |
setZIndexOffset( |
this |
Changes the zIndex offset of the marker. |
getIcon() |
Icon |
Returns the current icon used by the marker |
setIcon( |
this |
Changes the marker icon. |
setOpacity( |
this |
Changes the opacity of the marker. |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Handler
methods). Example:
marker.dragging.disable();
Property | Type | Description |
---|---|---|
dragging |
Handler |
Marker dragging handler (by both mouse and touch). Only valid when the marker is on the map (Otherwise set
marker.options.draggable ). |
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.
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);
Factory | Description |
---|---|
L.popup(
|
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. |
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. |
autoPanPaddingTopLeft |
Point |
null |
The margin between the popup and the top left corner of the map view after autopanning was performed. |
autoPanPaddingBottomRight |
Point |
null |
The margin between the popup and the bottom right corner of the map view after autopanning was performed. |
autoPanPadding |
Point |
Point(5, 5) |
Equivalent of setting both top left and bottom right autopan padding to the same value. |
keepInView |
Boolean |
false |
Set it to true if you want to prevent users from panning the popup
off of the screen while it is open. |
closeButton |
Boolean |
true |
Controls the presence of a close button in the popup. |
autoClose |
Boolean |
true |
Set it to false if you want to override the default behavior of
the popup closing when another popup is opened. |
closeOnEscapeKey |
Boolean |
true |
Set it to false if you want to override the default behavior of
the ESC key for closing of the popup. |
closeOnClick |
Boolean |
* |
Set it if you want to override the default behavior of the popup closing when user clicks
on the map. Defaults to the map's closePopupOnClick
option. |
className |
String |
'' |
A custom CSS class name to assign to the popup. |
Option | Type | Default | Description |
---|---|---|---|
offset |
Point |
Point(0, 7) |
The offset of the popup position. Useful to control the anchor of the popup when opening it on some overlays. |
pane |
String |
'popupPane' |
Map pane where the popup will be added. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
getLatLng() |
LatLng |
Returns the geographical point of popup. |
setLatLng( |
this |
Sets the geographical point where the popup will open. |
getContent() |
String|HTMLElement |
Returns the content of the popup. |
setContent( |
this |
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 |
getElement() |
String|HTMLElement |
Alias for getContent() |
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 |
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). |
openOn( |
this |
Adds the popup to the map and closes the previous one. The same as |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Used to display small texts on top of map layers.
marker.bindTooltip("my tooltip text").openTooltip();
Note about tooltip offset. Leaflet takes two options in consideration for computing tooltip offsetting:
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.tooltipAnchor
Icon option: this will only be considered for Marker. You
should adapt this value if you use a custom icon.Factory | Description |
---|---|
L.tooltip(
|
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. |
Option | Type | Default | Description |
---|---|---|---|
pane |
String |
'tooltipPane' |
Map pane where the tooltip will be added. |
offset |
Point |
Point(0, 0) |
Optional offset of the tooltip position. |
direction |
String |
'auto' |
Direction where to open the tooltip. Possible values are: right , left ,
top , bottom , center , auto .
auto will dynamically switch between right and left according to the
tooltip
position on the map. |
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. |
opacity |
Number |
0.9 |
Tooltip container opacity. |
Option | Type | Default | Description |
---|---|---|---|
className |
String |
'' |
A custom CSS class name to assign to the popup. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Used to load and display tile layers on the map. Note that most tile servers require attribution, which you can set
under Layer
. Extends GridLayer
.
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'}).addTo(map);
A string of the following form:
'http://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'
{s}
means one of the available subdomains (used sequentially to help with browser parallel requests
per domain limitation; subdomain values are specified in options; a
, b
or c
by default, can be omitted), {z}
— zoom level, {x}
and {y}
— tile
coordinates. {r}
can be used to add "@2x" to the URL to load retina tiles.
You can use custom keys in the template, which will be evaluated from TileLayer
options, like this:
L.tileLayer('http://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});
Factory | Description |
---|---|
L.tilelayer(
|
Instantiates a tile layer object given a URL template and optionally an options object. |
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.
|
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
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. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
loading |
Event |
Fired when the grid layer starts loading tiles. |
tileunload |
TileEvent |
Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart |
TileEvent |
Fired when a tile is requested and starts loading. |
tileerror |
TileErrorEvent |
Fired when there is an error loading a tile. |
tileload |
TileEvent |
Fired when a tile loads. |
load |
Event |
Fired when the grid layer loaded all visible tiles. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setUrl(
|
this |
Updates the layer's URL template and redraws it (unless |
createTile(
|
HTMLElement |
Called only internally, overrides GridLayer's |
TileLayer
might reimplement the
following method.Method | Returns | Description |
---|---|---|
getTileUrl( |
String |
Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
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. |
setOpacity( |
this |
Changes the opacity of the grid layer. |
setZIndex( |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
redraw() |
this |
Causes the layer to clear all the tiles and request them again. |
getTileSize() |
Point |
Normalizes the tileSize option into a point. Used by the
|
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Used to display WMS services as tile layers on the map.
Extends TileLayer
.
var nexrad = L.tileLayer.wms("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi", {
layers: 'nexrad-n0r-900913',
format: 'image/png',
transparent: true,
attribution: "Weather data © 2012 IEM Nexrad"
});
Factory | Description |
---|---|
L.tileLayer.wms(
|
Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object. |
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. |
version |
String |
'1.1.1' |
Version of the WMS service to use |
crs |
CRS |
null |
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.
|
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
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. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
loading |
Event |
Fired when the grid layer starts loading tiles. |
tileunload |
TileEvent |
Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart |
TileEvent |
Fired when a tile is requested and starts loading. |
tileerror |
TileErrorEvent |
Fired when there is an error loading a tile. |
tileload |
TileEvent |
Fired when a tile loads. |
load |
Event |
Fired when the grid layer loaded all visible tiles. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setParams(
|
this |
Merges an object with the new parameters and re-requests tiles on the current screen (unless
|
Method | Returns | Description |
---|---|---|
setUrl(
|
this |
Updates the layer's URL template and redraws it (unless |
createTile(
|
HTMLElement |
Called only internally, overrides GridLayer's |
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. |
setOpacity( |
this |
Changes the opacity of the grid layer. |
setZIndex( |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
redraw() |
this |
Causes the layer to clear all the tiles and request them again. |
getTileSize() |
Point |
Normalizes the tileSize option into a point. Used by the
|
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Used to load and display a single image over specific bounds of the map. Extends Layer
.
var imageUrl = 'http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
L.imageOverlay(imageUrl, imageBounds).addTo(map);
Factory | Description |
---|---|
L.imageOverlay(
|
Instantiates an image overlay object given the URL of the image and the geographical bounds it is tied to. |
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. |
zIndex |
Number |
1 |
The explicit zIndex of the overlay layer. |
className |
String |
'' |
A custom class name to assign to the image. Empty by default. |
Option | Type | Default | Description |
---|---|---|---|
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
load |
Event |
Fired when the ImageOverlay layer has loaded its image |
error |
Event |
Fired when the ImageOverlay layer fails to load its image |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setOpacity( |
this |
Sets the opacity of the overlay. |
bringToFront() |
this |
Brings the layer to the top of all overlays. |
bringToBack() |
this |
Brings the layer to the bottom of all overlays. |
setUrl( |
this |
Changes the URL of the image. |
setBounds(
|
this |
Update the bounds that this ImageOverlay covers |
setZIndex( |
this |
Changes the zIndex of the image overlay. |
getBounds() |
LatLngBounds |
Get the bounds that this ImageOverlay covers |
getElement() |
HTMLElement |
Returns the instance of |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Used to load and display a video player over specific bounds of the map. Extends ImageOverlay
.
A video overlay uses the <video>
HTML5 element.
var videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',
videoBounds = [[ 32, -130], [ 13, -100]];
L.videoOverlay(videoUrl, videoBounds ).addTo(map);
Factory | Description |
---|---|
L.videoOverlay(
|
Instantiates an image overlay object given the URL of the video (or array of URLs, or even a video element) and the geographical bounds it is tied to. |
Option | Type | Default | Description |
---|---|---|---|
autoplay |
Boolean |
true |
Whether the video starts playing automatically when loaded. |
loop |
Boolean |
true |
Whether the video will loop back to the beginning when played. |
keepAspectRatio |
Boolean |
true |
Whether the video will save aspect ratio after the projection. Relevant for supported browsers. Browser compatibility- https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit |
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. |
zIndex |
Number |
1 |
The explicit zIndex of the overlay layer. |
className |
String |
'' |
A custom class name to assign to the image. Empty by default. |
Option | Type | Default | Description |
---|---|---|---|
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
load |
Event |
Fired when the video has finished loading the first frame |
Event | Data | Description |
---|---|---|
error |
Event |
Fired when the ImageOverlay layer fails to load its image |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
getElement() |
HTMLVideoElement |
Returns the instance of |
Method | Returns | Description |
---|---|---|
setOpacity( |
this |
Sets the opacity of the overlay. |
bringToFront() |
this |
Brings the layer to the top of all overlays. |
bringToBack() |
this |
Brings the layer to the bottom of all overlays. |
setUrl( |
this |
Changes the URL of the image. |
setBounds(
|
this |
Update the bounds that this ImageOverlay covers |
setZIndex( |
this |
Changes the zIndex of the image overlay. |
getBounds() |
LatLngBounds |
Get the bounds that this ImageOverlay covers |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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.
var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
svgElement.setAttribute('viewBox', "0 0 200 200");
svgElement.innerHTML = '<rect width="200" height="200"/><rect x="75" y="23" width="50" height="50" style="fill:red"/><rect x="75" y="123" width="50" height="50" style="fill:#0013ff"/>';
var svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];
L.svgOverlay(svgElement, svgElementBounds).addTo(map);
Factory | Description |
---|---|
L.svgOverlay(
|
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. |
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. |
zIndex |
Number |
1 |
The explicit zIndex of the overlay layer. |
className |
String |
'' |
A custom class name to assign to the image. Empty by default. |
Option | Type | Default | Description |
---|---|---|---|
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
getElement() |
SVGElement |
Returns the instance of |
Method | Returns | Description |
---|---|---|
setOpacity( |
this |
Sets the opacity of the overlay. |
bringToFront() |
this |
Brings the layer to the top of all overlays. |
bringToBack() |
this |
Brings the layer to the bottom of all overlays. |
setUrl( |
this |
Changes the URL of the image. |
setBounds(
|
this |
Update the bounds that this ImageOverlay covers |
setZIndex( |
this |
Changes the zIndex of the image overlay. |
getBounds() |
LatLngBounds |
Get the bounds that this ImageOverlay covers |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
An abstract class that contains options and constants shared between vector
overlays (Polygon, Polyline, Circle). Do not use it directly. Extends Layer
.
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern. Doesn't
work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
A class for drawing polyline overlays on a map. Extends Path
.
// 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]]
];
Factory | Description |
---|---|
L.polyline(
|
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. |
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern.
Doesn't work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
getLatLngs() |
LatLng[] |
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs( |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
closestLayerPoint( |
Point |
Returns the point closest to |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng( |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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.
// 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]]
]
];
Factory | Description |
---|---|
L.polygon(
|
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern.
Doesn't work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
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( |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
closestLayerPoint( |
Point |
Returns the point closest to |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng( |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
A class for drawing rectangle overlays on a map. Extends Polygon
.
// define rectangle geographical bounds
var bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]];
// create an orange rectangle
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
// zoom the map to the rectangle bounds
map.fitBounds(bounds);
Factory | Description |
---|---|
L.rectangle(
|
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern.
Doesn't work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setBounds(
|
this |
Redraws the rectangle with the passed bounds. |
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( |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
closestLayerPoint( |
Point |
Returns the point closest to |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng( |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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).
L.circle([50.5, 30.5], {radius: 200}).addTo(map);
Factory | Description |
---|---|
L.circle(
|
Instantiates a circle object given a geographical point, and an options object which contains the circle radius. |
L.circle(
|
Obsolete way of instantiating a circle, for compatibility with 0.7.x code. Do not use in new applications or plugins. |
Option | Type | Default | Description |
---|---|---|---|
radius |
Number |
|
Radius of the circle, in meters. |
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern.
Doesn't work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setRadius( |
this |
Sets the radius of a circle. Units are in meters. |
getRadius() |
Number |
Returns the current radius of a circle. Units are in meters. |
getBounds() |
LatLngBounds |
Returns the |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
setLatLng( |
this |
Sets the position of a circle marker to a new location. |
getLatLng() |
LatLng |
Returns the current geographical position of the circle marker |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
A circle of a fixed size with radius specified in pixels. Extends Path
.
Factory | Description |
---|---|
L.circleMarker(
|
Instantiates a circle marker object given a geographical point, and an optional options object. |
Option | Type | Default | Description |
---|---|---|---|
radius |
Number |
10 |
Radius of the circle marker, in pixels |
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. |
color |
String |
'#3388ff' |
Stroke color |
weight |
Number |
3 |
Stroke width in pixels |
opacity |
Number |
1.0 |
Stroke opacity |
lineCap |
String |
'round' |
A string that defines shape to be used at the end of the stroke. |
lineJoin |
String |
'round' |
A string that defines shape to be used at the corners of the stroke. |
dashArray |
String |
null |
A string that defines the stroke dash pattern.
Doesn't work on Canvas -powered layers in some
old browsers. |
dashOffset |
String |
null |
A string that defines the distance into the dash
pattern to start the dash. Doesn't work on Canvas -powered
layers in some
old browsers. |
fill |
Boolean |
depends |
Whether to fill the path with color. Set it to false to disable filling on polygons or
circles. |
fillColor |
String |
* |
Fill color. Defaults to the value of the color option |
fillOpacity |
Number |
0.2 |
Fill opacity. |
fillRule |
String |
'evenodd' |
A string that defines how the inside of a shape is determined. |
bubblingMouseEvents |
Boolean |
true |
When true , a mouse event on this path will trigger the same event on the map
(unless L.DomEvent.stopPropagation is used). |
renderer |
Renderer |
|
Use this specific instance of Renderer for this path. Takes
precedence over the map's default renderer. |
className |
String |
null |
Custom class name set on an element. Only for SVG renderer. |
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. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
move |
Event |
Fired when the marker is moved via setLatLng . Old and
new coordinates are included in event arguments as oldLatLng , latlng . |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
setLatLng( |
this |
Sets the position of a circle marker to a new location. |
getLatLng() |
LatLng |
Returns the current geographical position of the circle marker |
setRadius( |
this |
Sets the radius of a circle marker. Units are in pixels. |
getRadius() |
Number |
Returns the current radius of the circle |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(
|
this |
Changes the appearance of a Path based on the options in the |
bringToFront() |
this |
Brings the layer to the top of all path layers. |
bringToBack() |
this |
Brings the layer to the bottom of all path layers. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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.
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 } );
Factory | Description |
---|---|
L.svg(
|
Creates a SVG renderer with the given 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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
update |
Event |
Fired when the renderer updates its bounds, center and zoom, for example when its map has moved |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Function | Returns | Description |
---|---|---|
create( |
SVGElement |
Returns a instance of SVGElement, corresponding to the class name passed. For example, using 'line' will return an instance of SVGLineElement. |
pointsToPath(
|
String |
Generates a SVG path string for multiple rings, with each ring turning into "M..L..L.." instructions |
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.
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 } );
Factory | Description |
---|---|
L.canvas(
|
Creates a Canvas renderer with the given 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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
update |
Event |
Fired when the renderer updates its bounds, center and zoom, for example when its map has moved |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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
.
L.layerGroup([marker1, marker2])
.addLayer(polyline)
.addTo(map);
Factory | Description |
---|---|
L.layerGroup(
|
Create a layer group, optionally given an initial set of layers and an options object. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
addLayer( |
this |
Adds the given layer to the group. |
removeLayer( |
this |
Removes the given layer from the group. |
removeLayer( |
this |
Removes the layer with the given internal ID from the group. |
hasLayer( |
Boolean |
Returns |
hasLayer( |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke( |
this |
Calls |
eachLayer(
|
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer( |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex( |
this |
Calls |
getLayerId( |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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
)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.layeradd
and layerremove
eventsL.featureGroup([marker1, marker2, polyline])
.bindPopup('Hello world!')
.on('click', function() { alert('Clicked on a member of the group!'); })
.addTo(map);
Factory | Description |
---|---|
L.featureGroup( |
Create a feature group, optionally given an initial set of layers. |
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
layeradd |
LayerEvent |
Fired when a layer is added to this FeatureGroup |
layerremove |
LayerEvent |
Fired when a layer is removed from this FeatureGroup |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
setStyle(
|
this |
Sets the given path options to each layer of the group that has a |
bringToFront() |
this |
Brings the layer group to the top of all other layers |
bringToBack() |
this |
Brings the layer group to the back of all other layers |
getBounds() |
LatLngBounds |
Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children). |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
addLayer( |
this |
Adds the given layer to the group. |
removeLayer( |
this |
Removes the given layer from the group. |
removeLayer( |
this |
Removes the layer with the given internal ID from the group. |
hasLayer( |
Boolean |
Returns |
hasLayer( |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke( |
this |
Calls |
eachLayer(
|
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer( |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex( |
this |
Calls |
getLayerId( |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse
GeoJSON data and display it on the map. Extends FeatureGroup
.
L.geoJSON(data, {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(map);
Factory | Description |
---|---|
L.geoJSON(
|
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.
|
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 :
|
style |
Function |
* |
A Function defining the Path options for styling
GeoJSON lines and polygons,
called internally when data is added.
The default value is to not override any defaults:
|
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:
|
filter |
Function |
* |
A Function that will be used to decide whether to include a feature or not.
The default is to include all features:
Note: dynamically changing the |
coordsToLatLng |
Function |
* |
A Function that will be used for converting GeoJSON coordinates to LatLng s.
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
layeradd |
LayerEvent |
Fired when a layer is added to this FeatureGroup |
layerremove |
LayerEvent |
Fired when a layer is removed from this FeatureGroup |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
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 |
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 |
getBounds() |
LatLngBounds |
Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children). |
Method | Returns | Description |
---|---|---|
toGeoJSON( |
Object |
|
addLayer( |
this |
Adds the given layer to the group. |
removeLayer( |
this |
Removes the given layer from the group. |
removeLayer( |
this |
Removes the layer with the given internal ID from the group. |
hasLayer( |
Boolean |
Returns |
hasLayer( |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke( |
this |
Calls |
eachLayer(
|
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer( |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex( |
this |
Calls |
getLayerId( |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Function | Returns | Description |
---|---|---|
geometryToLayer(
|
Layer |
Creates a Layer from a given GeoJSON feature. Can use a custom
pointToLayer and/or coordsToLatLng
functions if provided as options. |
coordsToLatLng( |
LatLng |
Creates a LatLng object from an array of 2 numbers (longitude,
latitude)
or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. |
coordsToLatLngs(
|
Array |
Creates a multidimensional array of LatLng s from a GeoJSON coordinates
array.
levelsDeep specifies the nesting level (0 is for an array of points, 1 for an array of arrays
of points, etc., 0 by default).
Can use a custom coordsToLatLng function. |
latLngToCoords(
|
Array |
Reverse of coordsToLatLng |
latLngsToCoords(
|
Array |
Reverse of coordsToLatLngs
closed 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 |
Normalize GeoJSON geometries/features into GeoJSON features. |
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.
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;
}
});
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;
}
});
Factory | Description |
---|---|
L.gridLayer(
|
Creates a new instance of GridLayer with the supplied 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. |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
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. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
loading |
Event |
Fired when the grid layer starts loading tiles. |
tileunload |
TileEvent |
Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart |
TileEvent |
Fired when a tile is requested and starts loading. |
tileerror |
TileErrorEvent |
Fired when there is an error loading a tile. |
tileload |
TileEvent |
Fired when a tile loads. |
load |
Event |
Fired when the grid layer loaded all visible tiles. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
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. |
setOpacity( |
this |
Changes the opacity of the grid layer. |
setZIndex( |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
redraw() |
this |
Causes the layer to clear all the tiles and request them again. |
getTileSize() |
Point |
Normalizes the tileSize option into a point. Used by the
|
GridLayer
shall reimplement the
following method.Method | Returns | Description |
---|---|---|
createTile(
|
HTMLElement |
Called only internally, must be overridden by classes extending |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Represents a geographical point with a certain latitude and longitude.
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:
map.panTo([50, 30]);
map.panTo({lon: 30, lat: 50});
map.panTo({lat: 50, lng: 30});
map.panTo(L.latLng(50, 30));
Note that LatLng
does not inherit from Leaflet's Class
object,
which means new classes can't inherit from it, and new methods
can't be added to it with the include
function.
Factory | Description |
---|---|
L.latLng(
|
Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude). |
L.latLng( |
Expects an array of the form [Number, Number] or [Number, Number, Number]
instead. |
L.latLng( |
Expects an plain object of the form {lat: Number, lng: Number} or
{lat: Number, lng: Number, alt: Number} instead. |
Method | Returns | Description |
---|---|---|
equals(
|
Boolean |
Returns |
toString() |
String |
Returns a string representation of the point (for debugging purposes). |
distanceTo( |
Number |
Returns the distance (in meters) to the given |
wrap() |
LatLng |
Returns a new |
toBounds( |
LatLngBounds |
Returns a new |
Property | Type | Description |
---|---|---|
lat |
Number |
Latitude in degrees |
lng |
Number |
Longitude in degrees |
alt |
Number |
Altitude in meters (optional) |
Represents a rectangular geographical area on a map.
var corner1 = L.latLng(40.712, -74.227),
corner2 = L.latLng(40.774, -74.125),
bounds = L.latLngBounds(corner1, corner2);
All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
map.fitBounds([
[40.712, -74.227],
[40.774, -74.125]
]);
Caution: if the area crosses the antimeridian (often confused with the International Date Line), you must specify
corners outside the [-180, 180] degrees longitude range.
Note that LatLngBounds
does not inherit from Leafet'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.
Factory | Description |
---|---|
L.latLngBounds(
|
Creates a LatLngBounds object by defining two diagonally opposite
corners of the rectangle. |
L.latLngBounds( |
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 . |
Method | Returns | Description |
---|---|---|
extend( |
this |
Extend the bounds to contain the given point |
extend(
|
this |
Extend the bounds to contain the given bounds |
pad( |
LatLngBounds |
Returns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds. |
getCenter() |
LatLng |
Returns the center point of the bounds. |
getSouthWest() |
LatLng |
Returns the south-west point of the bounds. |
getNorthEast() |
LatLng |
Returns the north-east point of the bounds. |
getNorthWest() |
LatLng |
Returns the north-west point of the bounds. |
getSouthEast() |
LatLng |
Returns the south-east point of the bounds. |
getWest() |
Number |
Returns the west longitude of the bounds |
getSouth() |
Number |
Returns the south latitude of the bounds |
getEast() |
Number |
Returns the east longitude of the bounds |
getNorth() |
Number |
Returns the north latitude of the bounds |
contains(
|
Boolean |
Returns |
contains( |
Boolean |
Returns |
intersects(
|
Boolean |
Returns |
overlaps( |
Boolean |
Returns |
toBBoxString() |
String |
Returns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data. |
equals(
|
Boolean |
Returns |
isValid() |
Boolean |
Returns |
Represents a point with x
and y
coordinates in pixels.
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:
map.panBy([200, 300]);
map.panBy(L.point(200, 300));
Note that Point
does not inherit from Leafet'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.
Factory | Description |
---|---|
L.point(
|
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( |
Expects an array of the form [x, y] instead. |
L.point( |
Expects a plain object of the form {x: Number, y: Number} instead. |
Method | Returns | Description |
---|---|---|
clone() |
Point |
Returns a copy of the current point. |
add( |
Point |
Returns the result of addition of the current and the given points. |
subtract( |
Point |
Returns the result of subtraction of the given point from the current. |
divideBy( |
Point |
Returns the result of division of the current point by the given number. |
multiplyBy( |
Point |
Returns the result of multiplication of the current point by the given number. |
scaleBy( |
Point |
Multiply each coordinate of the current point by each coordinate of
|
unscaleBy( |
Point |
Inverse of |
round() |
Point |
Returns a copy of the current point with rounded coordinates. |
floor() |
Point |
Returns a copy of the current point with floored coordinates (rounded down). |
ceil() |
Point |
Returns a copy of the current point with ceiled coordinates (rounded up). |
trunc() |
Point |
Returns a copy of the current point with truncated coordinates (rounded towards zero). |
distanceTo( |
Number |
Returns the cartesian distance between the current and the given points. |
equals( |
Boolean |
Returns |
contains( |
Boolean |
Returns |
toString() |
String |
Returns a string representation of the point for debugging purposes. |
Property | Type | Description |
---|---|---|
x |
Number |
The x coordinate of the point |
y |
Number |
The y coordinate of the point |
Represents a rectangular area in pixel coordinates.
var p1 = L.point(10, 10),
p2 = L.point(40, 60),
bounds = L.bounds(p1, p2);
All Leaflet methods that accept Bounds
objects also accept them in a simple
Array form (unless noted otherwise), so the bounds example above can be passed like this:
otherBounds.intersects([[10, 10], [40, 60]]);
Note that Bounds
does not inherit from Leafet'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.
Factory | Description |
---|---|
L.bounds(
|
Creates a Bounds object from two corners coordinate pairs. |
L.bounds( |
Creates a Bounds object from the given array of points. |
Method | Returns | Description |
---|---|---|
extend( |
this |
Extends the bounds to contain the given point. |
getCenter( |
Point |
Returns the center point of the bounds. |
getBottomLeft() |
Point |
Returns the bottom-left point of the bounds. |
getTopRight() |
Point |
Returns the top-right point of the bounds. |
getTopLeft() |
Point |
Returns the top-left point of the bounds (i.e. |
getBottomRight() |
Point |
Returns the bottom-right point of the bounds (i.e. |
getSize() |
Point |
Returns the size of the given bounds |
contains( |
Boolean |
Returns |
contains( |
Boolean |
Returns |
intersects( |
Boolean |
Returns |
overlaps( |
Boolean |
Returns |
Property | Type | Description |
---|---|---|
min |
Point |
The top left corner of the rectangle. |
max |
Point |
The bottom right corner of the rectangle. |
Represents an icon to provide when creating a marker.
var myIcon = L.icon({
iconUrl: 'my-icon.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
shadowUrl: 'my-icon-shadow.png',
shadowSize: [68, 95],
shadowAnchor: [22, 94]
});
L.marker([50.505, 30.57], {icon: myIcon}).addTo(map);
L.Icon.Default
extends L.Icon
and is
the blue icon Leaflet uses for markers by default.
Factory | Description |
---|---|
L.icon(
|
Creates an icon instance with the given options. |
Option | Type | Default | Description |
---|---|---|---|
iconUrl |
String |
null |
(required) The URL to the icon image (absolute or relative to your script path). |
iconRetinaUrl |
String |
null |
The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. |
iconSize |
Point |
null |
Size of the icon image in pixels. |
iconAnchor |
Point |
null |
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. |
popupAnchor |
Point |
[0, 0] |
The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor |
Point |
[0, 0] |
The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl |
String |
null |
The URL to the icon shadow image. If not specified, no shadow image will be created. |
shadowRetinaUrl |
String |
null |
|
shadowSize |
Point |
null |
Size of the shadow image in pixels. |
shadowAnchor |
Point |
null |
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. |
Method | Returns | Description |
---|---|---|
createIcon( |
HTMLElement |
Called internally when the icon has to be shown, returns a |
createShadow( |
HTMLElement |
As |
Icon
, represents the icon to
use in Marker
s 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. |
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.
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.
Factory | Description |
---|---|
L.divIcon(
|
Creates a DivIcon instance with the given options. |
Option | Type | Default | Description |
---|---|---|---|
html |
String|HTMLElement |
'' |
Custom HTML code to put inside the div element, empty by default. Alternatively,
an instance of HTMLElement . |
bgPos |
Point |
[0, 0] |
Optional relative position of the background, in pixels |
Option | Type | Default | Description |
---|---|---|---|
iconUrl |
String |
null |
(required) The URL to the icon image (absolute or relative to your script path). |
iconRetinaUrl |
String |
null |
The URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices. |
iconSize |
Point |
null |
Size of the icon image in pixels. |
iconAnchor |
Point |
null |
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. |
popupAnchor |
Point |
[0, 0] |
The coordinates of the point from which popups will "open", relative to the icon anchor. |
tooltipAnchor |
Point |
[0, 0] |
The coordinates of the point from which tooltips will "open", relative to the icon anchor. |
shadowUrl |
String |
null |
The URL to the icon shadow image. If not specified, no shadow image will be created. |
shadowRetinaUrl |
String |
null |
|
shadowSize |
Point |
null |
Size of the shadow image in pixels. |
shadowAnchor |
Point |
null |
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. |
Method | Returns | Description |
---|---|---|
createIcon( |
HTMLElement |
Called internally when the icon has to be shown, returns a |
createShadow( |
HTMLElement |
As |
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
.
Factory | Description |
---|---|
L.control.zoom(
|
Creates a zoom control |
Option | Type | Default | Description |
---|---|---|---|
zoomInText |
String |
'+' |
The text set on the 'zoom in' button. |
zoomInTitle |
String |
'Zoom in' |
The title set on the 'zoom in' button. |
zoomOutText |
String |
'− |
' The text set on the 'zoom out' button. |
zoomOutTitle |
String |
'Zoom out' |
The title set on the 'zoom out' button. |
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' |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition( |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo( |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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.
Factory | Description |
---|---|
L.control.attribution(
|
Creates an attribution control. |
Option | Type | Default | Description |
---|---|---|---|
prefix |
String |
'Leaflet' |
The HTML text shown before the attributions. Pass false to disable. |
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' |
Method | Returns | Description |
---|---|---|
setPrefix( |
this |
Sets the text before the attributions. |
addAttribution( |
this |
Adds an attribution text (e.g. |
removeAttribution( |
this |
Removes an attribution text. |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition( |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo( |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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
.
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:
{"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>": myLayer}
Factory | Description |
---|---|
L.control.layers(
|
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. |
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' |
Method | Returns | Description |
---|---|---|
addBaseLayer(
|
this |
Adds a base layer (radio button entry) with the given name to the control. |
addOverlay(
|
this |
Adds an overlay (checkbox entry) with the given name to the control. |
removeLayer( |
this |
Remove the given layer from the control. |
expand() |
this |
Expand the control container if collapsed. |
collapse() |
this |
Collapse the control container if expanded. |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition( |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo( |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft)
systems. Extends Control
.
L.control.scale().addTo(map);
Factory | Description |
---|---|
L.control.scale(
|
Creates an scale control with the given options. |
Option | Type | Default | Description |
---|---|---|---|
maxWidth |
Number |
100 |
Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500). |
metric |
Boolean |
True |
Whether to show the metric scale line (m/km). |
imperial |
Boolean |
True |
Whether to show the imperial scale line (mi/ft). |
updateWhenIdle |
Boolean |
false |
If true , the control is updated on moveend , otherwise
it's always up-to-date (updated on move ). |
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' |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition( |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo( |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
A namespace with static properties for browser/feature detection used by Leaflet internally.
if (L.Browser.ielt9) {
alert('Upgrade your browser, dude!');
}
Property | Type | Description |
---|---|---|
ie |
Boolean |
true for all Internet Explorer versions (not Edge). |
ielt9 |
Boolean |
true for Internet Explorer versions less than 9. |
edge |
Boolean |
true for the Edge web browser. |
webkit |
Boolean |
true for webkit-based browsers like Chrome and Safari (including mobile versions). |
android |
Boolean |
true for any browser running on an Android platform. |
android23 |
Boolean |
true for browsers running on Android 2 or Android 3. |
androidStock |
Boolean |
true for the Android stock browser (i.e. not Chrome) |
opera |
Boolean |
true for the Opera browser |
chrome |
Boolean |
true for the Chrome browser. |
gecko |
Boolean |
true for gecko-based browsers like Firefox. |
safari |
Boolean |
true for the Safari browser. |
opera12 |
Boolean |
true for the Opera browser supporting CSS transforms (version 12 or later). |
win |
Boolean |
true when the browser is running in a Windows platform |
ie3d |
Boolean |
true for all Internet Explorer versions supporting CSS transforms. |
webkit3d |
Boolean |
true for webkit-based browsers supporting CSS transforms. |
gecko3d |
Boolean |
true for gecko-based browsers supporting CSS transforms. |
any3d |
Boolean |
true for all browsers supporting CSS transforms. |
mobile |
Boolean |
true for all browsers running in a mobile device. |
mobileWebkit |
Boolean |
true for all webkit-based browsers in a mobile device. |
mobileWebkit3d |
Boolean |
true for all webkit-based browsers in a mobile device supporting CSS transforms. |
msPointer |
Boolean |
true for browsers implementing the Microsoft touch events model (notably IE10). |
pointer |
Boolean |
true for all browsers supporting pointer events. |
touch |
Boolean |
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%. |
passiveEvents |
Boolean |
true for browsers that support passive events. |
canvas |
Boolean |
true when the browser supports <canvas> . |
svg |
Boolean |
true when the browser supports SVG.
|
vml |
Boolean |
true if the browser supports VML. |
Various utility functions, used by Leaflet internally.
Function | Returns | Description |
---|---|---|
extend(
|
Object |
Merges the properties of the src object (or multiple objects) into dest object
and returns the latter. Has an L.extend shortcut. |
create(
|
Object |
Compatibility polyfill for Object.create |
bind( |
Function |
Returns a new function bound to the arguments passed, like Function.prototype.bind.
Has a L.bind() shortcut. |
stamp( |
Number |
Returns the unique ID of an object, assigning it one if it doesn't have it. |
throttle(
|
Function |
Returns a function which executes function fn with the given scope context
(so that the this keyword refers to context inside fn 's code).
The function
fn will be called no more than one time per given amount of time . The arguments
received by the bound function will be any arguments passed when binding the
function, followed by any arguments passed when invoking the bound function.
Has an L.throttle shortcut. |
wrapNum(
|
Number |
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 |
Returns the number num rounded to digits decimals, or to 6 decimals by default.
|
trim( |
String |
Compatibility polyfill for String.prototype.trim |
splitWords( |
String[] |
Trims and splits the string on whitespace and returns the array of parts. |
setOptions(
|
Object |
Merges the given properties to the options of the obj object, returning the
resulting options. See Class options . Has an L.setOptions shortcut. |
getParamString(
|
String |
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 |
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. |
isArray(obj) |
Boolean |
Compatibility polyfill for Array.isArray |
indexOf(
|
Number |
Compatibility polyfill for Array.prototype.indexOf |
requestAnimFrame(
|
Number |
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. |
cancelAnimFrame( |
undefined |
Cancels a previous requestAnimFrame . See also window.cancelAnimationFrame.
|
Property | Type | Description |
---|---|---|
lastId |
Number |
Last unique ID used by stamp() |
emptyImageUrl |
String |
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). |
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.
var transformation = L.transformation(2, 5, -1, 10),
p = L.point(1, 2),
p2 = transformation.transform(p), // L.point(7, 8)
p3 = transformation.untransform(p2); // L.point(1, 2)
Factory | Description |
---|---|
L.transformation(
|
Instantiates a Transformation object with the given coefficients. |
L.transformation( |
Expects an coefficients array of the form
[a: Number, b: Number, c: Number, d: Number] . |
Method | Returns | Description |
---|---|---|
transform(
|
Point |
Returns a transformed point, optionally multiplied by the given scale.
Only accepts actual |
untransform(
|
Point |
Returns the reverse transformation of the given point, optionally divided
by the given scale. Only accepts actual |
Various utility functions for polyline points processing, used by Leaflet internally to make polylines lightning-fast.
Function | Returns | Description |
---|---|---|
simplify(
|
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. |
pointToSegmentDistance(
|
Number |
Returns the distance between point p and segment p1 to p2 . |
closestPointOnSegment(
|
Number |
Returns the closest point from a point p on a segment p1 to p2 .
|
clipSegment(
|
Point[]|Boolean |
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( |
Boolean |
Returns true if latlngs is a flat array, false is nested. |
Various utility functions for polygon geometries.
Function | Returns | Description |
---|---|---|
clipPolygon(
|
Point[] |
Clips the polygon geometry defined by the given points by the given bounds (using the Sutherland-Hodgman
algorithm).
Used by Leaflet to only show polygon points that are on the screen or near, increasing
performance. Note that polygon points needs different algorithm for clipping
than polyline, so there's a separate method for it. |
Utility functions to work with the DOM events, used by Leaflet internally.
Function | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function (fn ) to a particular DOM event type of the
element el . You can optionally specify the context of the listener
(object the this keyword will point to). You can also pass several
space-separated types (e.g. 'click dblclick' ). |
on(
|
this |
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} |
off(
|
this |
Removes a previously added listener function.
Note that if you passed a custom context to on, you must pass the same
context to off in order to remove the listener. |
off(
|
this |
Removes a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} |
stopPropagation( |
this |
Stop the given event from propagation to parent elements. Used inside the listener functions:
|
disableScrollPropagation( |
this |
Adds stopPropagation to the element's 'mousewheel' events (plus
browser variants). |
disableClickPropagation( |
this |
Adds stopPropagation to the element's 'click' ,
'doubleclick' ,
'mousedown' and 'touchstart' events (plus browser variants). |
preventDefault( |
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( |
this |
Does stopPropagation and preventDefault at the same time. |
getMousePosition(
|
Point |
Gets normalized mouse position from a DOM event relative to the
container (border excluded) or to the whole page if not specified. |
getWheelDelta( |
Number |
Gets normalized wheel delta from a mousewheel DOM event, in vertical pixels scrolled (negative if scrolling down). Events from pointing devices without precise scrolling are mapped to a best guess of 60 pixels. |
addListener(…) |
this |
Alias to L.DomEvent.on |
removeListener(…) |
this |
Alias to L.DomEvent.off |
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.
Function | Returns | Description |
---|---|---|
get( |
HTMLElement |
Returns an element given its DOM id, or returns the element itself if it was passed directly. |
getStyle(
|
String |
Returns the value for a certain style attribute on an element, including computed values or values set through CSS. |
create(
|
HTMLElement |
Creates an HTML element with tagName , sets its class to className , and
optionally appends it to container element. |
remove( |
|
Removes el from its parent element |
empty( |
|
Removes all of el 's children elements from el |
toFront( |
|
Makes el the last child of its parent, so it renders in front of the other children. |
toBack( |
|
Makes el the first child of its parent, so it renders behind the other children. |
hasClass(
|
Boolean |
Returns true if the element's class attribute contains name . |
addClass(
|
|
Adds name to the element's class attribute. |
removeClass(
|
|
Removes name from the element's class attribute. |
setClass(
|
|
Sets the element's class. |
getClass( |
String |
Returns the element's class. |
setOpacity(
|
|
Set the opacity of an element (including old IE support).
opacity must be a number from 0 to 1 . |
testProp( |
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 . |
setTransform(
|
|
Resets the 3D CSS transform of el so it is translated by offset pixels
and optionally scaled by scale . Does not have an effect if the
browser doesn't support 3D CSS transforms. |
setPosition(
|
|
Sets the position of el to coordinates specified by position ,
using CSS translate or top/left positioning depending on the browser
(used by Leaflet internally to position its layers). |
getPosition( |
Point |
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. |
enableTextSelection() |
|
Cancels the effects of a previous L.DomUtil.disableTextSelection . |
disableImageDrag() |
|
As L.DomUtil.disableTextSelection , but
for dragstart DOM events, usually generated when the user drags an image. |
enableImageDrag() |
|
Cancels the effects of a previous L.DomUtil.disableImageDrag . |
preventOutline( |
|
Makes the outline
of the element el invisible. Used internally by Leaflet to prevent
focusable elements from displaying an outline when the user performs a
drag interaction on them. |
restoreOutline() |
|
Cancels the effects of a previous L.DomUtil.preventOutline . |
getSizedParentNode( |
HTMLElement |
Finds the closest parent node which size (width and height) is not null. |
getScale( |
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() .
|
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. |
Used internally for panning animations, utilizing CSS3 Transitions for modern browsers and a timer fallback for IE6-9.
var fx = new L.PosAnimation();
fx.run(el, [300, 500], 0.5);
Constructor | Description |
---|---|
L.PosAnimation() |
Creates a PosAnimation object. |
Event | Data | Description |
---|---|---|
start |
Event |
Fired when the animation starts |
step |
Event |
Fired continuously during the animation. |
end |
Event |
Fired when the animation ends. |
Method | Returns | Description |
---|---|---|
run(
|
|
Run an animation of a given element to a new position, optionally setting
duration in seconds ( |
stop() |
|
Stops the animation (if currently running). |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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
.
var draggable = new L.Draggable(elementToDrag);
draggable.enable();
Constructor | Description |
---|---|
L.Draggable(
|
Creates a Draggable object for moving el when you start
dragging the dragHandle element (equals el itself by default). |
Option | Type | Default | Description |
---|---|---|---|
clickTolerance |
Number |
3 |
The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag). |
Event | Data | Description |
---|---|---|
down |
Event |
Fired when a drag is about to start. |
dragstart |
Event |
Fired when a drag starts |
predrag |
Event |
Fired continuously during dragging before each corresponding update of the element's position. |
drag |
Event |
Fired continuously during dragging. |
dragend |
DragEndEvent |
Fired when the drag ends. |
Method | Returns | Description |
---|---|---|
enable() |
|
Enables the dragging ability |
disable() |
|
Disables the dragging ability |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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.
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");
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);
};
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
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
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:
var MyClass = L.Class.extend({
statics: {
FOO: 'bar',
BLA: 5
}
});
MyClass.FOO; // 'bar'
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, …);
Function | Returns | Description |
---|---|---|
extend( |
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 ). |
include( |
this |
Includes a mixin into the current class. |
mergeOptions( |
this |
Merges options into the defaults of the class. |
addInitHook( |
this |
Adds a constructor hook to the class. |
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).
map.on('click', function(e) {
alert(e.latlng);
} );
Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:
function onClick(e) { ... }
map.on('click', onClick);
map.off('click', onClick);
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent( |
this |
Adds an event parent - an |
removeEventParent( |
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
A set of methods from the Layer base class that all Leaflet layers use.
Inherits all methods, options and events from L.Evented
.
var layer = L.marker(latlng).addTo(map);
layer.addTo(map);
layer.remove();
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
add |
Event |
Fired after the layer is added to a map |
remove |
Event |
Fired after the layer is removed from a map |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
L.Layer
will inherit the following
methods:Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
L.Layer
and
(re-)implement the following methods.Method | Returns | Description |
---|---|---|
onAdd( |
this |
Should contain code that creates DOM elements for the layer, adds them to |
onRemove( |
this |
Should contain all clean up code that removes the layer's elements from the DOM and removes listeners
previously added in |
getEvents() |
Object |
This optional method should return an object like |
getAttribution() |
String |
This optional method should return a string containing HTML to be shown on the
|
beforeAdd( |
this |
Optional method. Called on |
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.
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent( |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
var layer = L.Polygon(latlngs).bindTooltip('Hi There!').addTo(map);
layer.openTooltip();
layer.closeTooltip();
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip( |
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent( |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Some Layer
s 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.
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the layer. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the layer. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the layer. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button pushed on the layer. |
mouseover |
MouseEvent |
Fired when the mouse enters the layer. |
mouseout |
MouseEvent |
Fired when the mouse leaves the layer. |
contextmenu |
MouseEvent |
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). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
L.Control is a base class for implementing map controls. Handles positioning. All other controls extend from this class.
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'
|
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition( |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo( |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
L.Control
and
(re-)implement the following methods.Method | Returns | Description |
---|---|---|
onAdd( |
HTMLElement |
Should return the container DOM element for the control and add listeners on relevant map events. Called
on |
onRemove( |
|
Optional method. Should contain all clean up code that removes the listeners previously added in |
Abstract class for map interaction handlers
Method | Returns | Description |
---|---|---|
enable() |
this |
Enables the handler |
disable() |
this |
Disables the handler |
enabled() |
Boolean |
Returns |
Handler
must implement the
two following methods:Method | Returns | Description |
---|---|---|
addHooks() |
|
Called when the handler is enabled, should add event hooks. |
removeHooks() |
|
Called when the handler is disabled, should remove the event hooks added previously. |
Function | Returns | Description |
---|---|---|
addTo(
|
this |
Adds a new Handler to the given map with the given name. |
An object with methods for projecting geographical coordinates of the world onto a flat surface (and back). See Map projection.
Method | Returns | Description |
---|---|---|
project( |
Point |
Projects geographical coordinates into a 2D point.
Only accepts actual |
unproject( |
LatLng |
The inverse of |
Property | Type | Description |
---|---|---|
bounds |
Bounds |
The bounds (specified in CRS units) where the projection is valid |
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. |
Method | Returns | Description |
---|---|---|
latLngToPoint(
|
Point |
Projects geographical coordinates into pixel coordinates for a given zoom. |
pointToLatLng(
|
LatLng |
The inverse of |
project( |
Point |
Projects geographical coordinates into coordinates in units accepted for this CRS (e.g. meters for EPSG:3857, for passing it to WMS services). |
unproject( |
LatLng |
Given a projected coordinate returns the corresponding LatLng.
The inverse of |
scale( |
Number |
Returns the scale used when transforming projected coordinates into
pixel coordinates for a particular zoom. For example, it returns
|
zoom( |
Number |
Inverse of |
getProjectedBounds( |
Bounds |
Returns the projection's bounds scaled and transformed for the provided |
distance(
|
Number |
Returns the distance between two geographical coordinates. |
wrapLatLng( |
LatLng |
Returns a |
wrapLatLngBounds(
|
LatLngBounds |
Returns a |
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) |
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 TileLayer s 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 Leafet'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. |
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 Path
s - 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.
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. |
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
update |
Event |
Fired when the renderer updates its bounds, center and zoom, for example when its map has moved |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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:
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
originalEvent |
DOMEvent |
The original DOM KeyboardEvent that triggered this Leaflet event. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
latlng |
LatLng |
The geographical point where the mouse event occured. |
layerPoint |
Point |
Pixel coordinates of the point where the mouse event occured relative to the map layer. |
containerPoint |
Point |
Pixel coordinates of the point where the mouse event occured relative to the map сontainer. |
originalEvent |
DOMEvent |
The original DOM MouseEvent or DOM TouchEvent that
triggered this Leaflet event. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
latlng |
LatLng |
Detected geographical location of the user. |
bounds |
LatLngBounds |
Geographical bounds of the area user is located in (with respect to the accuracy of location). |
accuracy |
Number |
Accuracy of location in meters. |
altitude |
Number |
Height of the position above the WGS84 ellipsoid in meters. |
altitudeAccuracy |
Number |
Accuracy of altitude in meters. |
heading |
Number |
The direction of travel in degrees counting clockwise from true North. |
speed |
Number |
Current velocity in meters per second. |
timestamp |
Number |
The time when the position was acquired. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
message |
String |
Error message. |
code |
Number |
Error code (if applicable). |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
layer |
Layer |
The layer that was added or removed. |
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. |
Property | Type | Description |
---|---|---|
layer |
Layer |
The layer that was added or removed. |
name |
String |
The name of the layer that was added or removed. |
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. |
Property | Type | Description |
---|---|---|
tile |
HTMLElement |
The tile element (image). |
coords |
Point |
Point object with the tile's x , y , and z (zoom level)
coordinates. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
tile |
HTMLElement |
The tile element (image). |
coords |
Point |
Point object with the tile's x , y , and z (zoom level)
coordinates. |
error |
* |
Error passed to the tile's done() callback. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
oldSize |
Point |
The old size before resize event. |
newSize |
Point |
The new size after the resize event. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
layer |
Layer |
The layer for the GeoJSON feature that is being added to the map. |
properties |
Object |
GeoJSON properties of the feature. |
geometryType |
String |
GeoJSON geometry type of the feature. |
id |
String |
GeoJSON ID of the feature (if present). |
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. |
Property | Type | Description |
---|---|---|
popup |
Popup |
The popup that was opened or closed. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
tooltip |
Tooltip |
The tooltip that was opened or closed. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
distance |
Number |
The distance in pixels the draggable element was moved by. |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Property | Type | Description |
---|---|---|
center |
LatLng |
The current center of the map |
zoom |
Number |
The current zoom level of the map |
noUpdate |
Boolean |
Whether layers should update their contents due to this event |
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. |
layer |
Object |
Deprecated. The same as propagatedFrom . |
Base model for L.Popup and L.Tooltip. Inherit from it for custom popup like plugins.
Option | Type | Default | Description |
---|---|---|---|
offset |
Point |
Point(0, 7) |
The offset of the popup position. Useful to control the anchor of the popup when opening it on some overlays. |
className |
String |
'' |
A custom CSS class name to assign to the popup. |
pane |
String |
'popupPane' |
Map pane where the popup will be added. |
Option | Type | Default | Description |
---|---|---|---|
attribution |
String |
null |
String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers. |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup bound to this layer is opened |
popupclose |
PopupEvent |
Fired when a popup bound to this layer is closed |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip bound to this layer is opened. |
tooltipclose |
TooltipEvent |
Fired when a tooltip bound to this layer is closed. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map or layer group. |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
getAttribution() |
String |
Used by the |
Method | Returns | Description |
---|---|---|
bindPopup(
|
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the specified |
closePopup() |
this |
Closes the popup bound to this layer if it is open. |
togglePopup() |
this |
Opens or closes the popup bound to this layer depending on its current state. |
isPopupOpen() |
boolean |
Returns |
setPopupContent(
|
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(
|
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(
|
this |
Opens the bound tooltip at the specified |
closeTooltip() |
this |
Closes the tooltip bound to this layer if it is open. |
toggleTooltip() |
this |
Opens or closes the tooltip bound to this layer depending on its current state. |
isTooltipOpen() |
boolean |
Returns |
setTooltipContent(
|
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(
|
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off(
|
this |
Removes a previously added listener function. If no function is specified, it will remove all the
listeners of that particular event from the object. Note that if you passed a custom context to
|
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. This includes implicitly attached events. |
fire(
|
this |
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( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(
|
this |
Adds an event parent - an |
removeEventParent(
|
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
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:
<script>L_NO_TOUCH = true;</script>
<script src="leaflet.js"></script>
Switch | Description |
---|---|
L_NO_TOUCH |
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. |
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>
A constant that represents the Leaflet version in use.
L.version; // contains "1.0.0" (or whatever version is currently in use)
map.getPane
或map.getPanes
方法访问窗格。 可以使用map.createPane
方法创建新窗格。 每个地图都有以下默认窗格,它们的唯一区别仅在于zIndex。