This reference reflects Leaflet 1.0.0.
The central class of the API — it is used to create a map on a page and manipulate it.
// initialize the map on the "map" div with a given center and zoom
var map = L.map('map', {
center: [51.505, -0.09],
zoom: 13
});
Factory | Description |
---|---|
L.map(<String>id,<Map options>options?) |
Instantiates a map object given the DOM ID of a <div> element
and optionally an object literal with Map options . |
L.map(<HTMLElement>el,<Map options>options?) |
Instantiates a map object given an instance of a <div> HTML element
and optionally an object literal with Map options . |
Option | Type | Default | Description |
---|---|---|---|
preferCanvas |
Boolean |
false |
Whether Path s should be rendered on a Canvas renderer.
By default, all Path s are rendered in a SVG renderer. |
Option | Type | Default | Description |
---|---|---|---|
attributionControl |
Boolean |
true |
Whether a attribution control is added to the map by default. |
zoomControl |
Boolean |
true |
Whether a zoom control is added to the map by default. |
Option | Type | Default | Description |
---|---|---|---|
closePopupOnClick |
Boolean
| true |
Set it to false if you don't want popups to close when user clicks the map. |
zoomSnap |
Number |
1 |
Forces the map's zoom level to always be a multiple of this, particularly
right after a fitBounds() or a pinch-zoom.
By default, the zoom level snaps to the nearest integer; lower values
(e.g. 0.5 or 0.1 ) allow for greater granularity. A value of 0
means the zoom level will not be snapped after fitBounds or a pinch-zoom. |
zoomDelta |
Number |
1 |
Controls how much the map's zoom level will change after a
zoomIn() , zoomOut() , pressing +
or - on the keyboard, or using the zoom controls.
Values smaller than 1 (e.g. 0.5 ) allow for greater granularity. |
trackResize |
Boolean |
true |
Whether the map automatically handles browser window resize to update itself. |
boxZoom |
Boolean |
true |
Whether the map can be zoomed to a rectangular area specified by dragging the mouse while pressing the shift key. |
doubleClickZoom |
Boolean|String |
true |
Whether the map can be zoomed in by double clicking on it and
zoomed out by double clicking while holding shift. If passed
'center' , double-click zoom will zoom to the center of the
view regardless of where the mouse was. |
dragging |
Boolean |
true |
Whether the map be draggable with mouse/touch or not. |
Option | Type | Default | Description |
---|---|---|---|
crs |
CRS |
L.CRS.EPSG3857 |
The Coordinate Reference System to use. Don't change this if you're not sure what it means. |
center |
LatLng |
undefined |
Initial geographic center of the map |
zoom |
Number |
undefined |
Initial map zoom level |
minZoom |
Number |
undefined |
Minimum zoom level of the map. Overrides any minZoom option set on map layers. |
maxZoom |
Number |
undefined |
Maximum zoom level of the map. Overrides any maxZoom option set on map layers. |
layers |
Layer[] |
[] |
Array of layers that will be added to the map initially |
maxBounds |
LatLngBounds |
null |
When this option is set, the map restricts the view to the given
geographical bounds, bouncing the user back when he tries to pan
outside the view. To set the restriction dynamically, use
setMaxBounds method. |
renderer |
Renderer |
* |
The default method for drawing vector layers on the map. L.SVG
or L.Canvas by default depending on browser support. |
Option | Type | Default | Description |
---|---|---|---|
fadeAnimation |
Boolean |
true |
Whether the tile fade animation is enabled. By default it's enabled in all browsers that support CSS3 Transitions except Android. |
markerZoomAnimation |
Boolean |
true |
Whether markers animate their zoom with the zoom animation, if disabled they will disappear for the length of the animation. By default it's enabled in all browsers that support CSS3 Transitions except Android. |
transform3DLimit |
Number |
2^23 |
Defines the maximum size of a CSS translation transform. The default
value should not be changed unless a web browser positions layers in
the wrong place after doing a large panBy . |
zoomAnimation |
Boolean |
true |
Whether the map zoom animation is enabled. By default it's enabled in all browsers that support CSS3 Transitions except Android. |
zoomAnimationThreshold |
Number |
4 |
Won't animate zoom if the zoom difference exceeds this value. |
Option | Type | Default | Description |
---|---|---|---|
inertia |
Boolean |
* |
If enabled, panning of the map will have an inertia effect where the map builds momentum while dragging and continues moving in the same direction for some time. Feels especially nice on touch devices. Enabled by default unless running on old Android devices. |
inertiaDeceleration |
Number |
3000 |
The rate with which the inertial movement slows down, in pixels/second². |
inertiaMaxSpeed |
Number |
Infinity |
Max speed of the inertial movement, in pixels/second. |
easeLinearity |
Number |
0.2 |
|
worldCopyJump |
Boolean |
false |
With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible. |
maxBoundsViscosity |
Number |
0.0 |
If maxBounds is set, this option will control how solid the bounds
are when dragging the map around. The default value of 0.0 allows the
user to drag outside the bounds at normal speed, higher values will
slow down map dragging outside bounds, and 1.0 makes the bounds fully
solid, preventing the user from dragging outside the bounds. |
Option | Type | Default | Description |
---|---|---|---|
keyboard |
Boolean |
true |
Makes the map focusable and allows users to navigate the map with keyboard
arrows and + /- keys. |
keyboardPanDelta |
Number |
80 |
Amount of pixels to pan when pressing an arrow key. |
Option | Type | Default | Description |
---|---|---|---|
scrollWheelZoom |
Boolean|String |
true |
Whether the map can be zoomed by using the mouse wheel. If passed 'center' ,
it will zoom to the center of the view regardless of where the mouse was. |
wheelDebounceTime |
Number |
40 |
Limits the rate at which a wheel can fire (in milliseconds). By default user can't zoom via wheel more often than once per 40 ms. |
wheelPxPerZoomLevel |
Number |
60 |
How many scroll pixels (as reported by L.DomEvent.getWheelDelta) mean a change of one full zoom level. Smaller values will make wheel-zooming faster (and vice versa). |
Option | Type | Default | Description |
---|---|---|---|
tap |
Boolean |
true |
Enables mobile hacks for supporting instant taps (fixing 200ms click
delay on iOS/Android) and touch holds (fired as contextmenu events). |
tapTolerance |
Number |
15 |
The max number of pixels a user can shift his finger during touch for it to be considered a valid tap. |
touchZoom |
Boolean|String |
* |
Whether the map can be zoomed by touch-dragging with two fingers. If
passed 'center' , it will zoom to the center of the view regardless of
where the touch events (fingers) were. Enabled for touch-capable web
browsers except for old Androids. |
bounceAtZoomLimits |
Boolean |
true |
Set it to false if you don't want the map to zoom beyond min/max zoom and then bounce back when pinch-zooming. |
Event | Data | Description |
---|---|---|
baselayerchange |
LayersControlEvent |
Fired when the base layer is changed through the layer control. |
overlayadd |
LayersControlEvent |
Fired when an overlay is selected through the layer control. |
overlayremove |
LayersControlEvent |
Fired when an overlay is deselected through the layer control. |
layeradd |
LayerEvent |
Fired when a new layer is added to the map. |
layerremove |
LayerEvent |
Fired when some layer is removed from the map |
Event | Data | Description |
---|---|---|
zoomlevelschange |
Event |
Fired when the number of zoomlevels on the map is changed due to adding or removing a layer. |
resize |
ResizeEvent |
Fired when the map is resized. |
unload |
Event |
Fired when the map is destroyed with remove method. |
viewreset |
Event |
Fired when the map needs to redraw its content (this usually happens on map zoom or load). Very useful for creating custom overlays. |
load |
Event |
Fired when the map is initialized (when its center and zoom are set for the first time). |
zoomstart |
Event |
Fired when the map zoom is about to change (e.g. before zoom animation). |
movestart |
Event |
Fired when the view of the map starts changing (e.g. user starts dragging the map). |
zoom |
Event |
Fired repeatedly during any change in zoom level, including zoom and fly animations. |
move |
Event |
Fired repeatedly during any movement of the map, including pan and fly animations. |
zoomend |
Event |
Fired when the map has changed, after any animations. |
moveend |
Event |
Fired when the center of the map stops changing (e.g. user stopped dragging the map). |
Event | Data | Description |
---|---|---|
popupopen |
PopupEvent |
Fired when a popup is opened in the map |
popupclose |
PopupEvent |
Fired when a popup in the map is closed |
autopanstart |
Event |
Fired when the map starts autopanning when opening a popup. |
Event | Data | Description |
---|---|---|
tooltipopen |
TooltipEvent |
Fired when a tooltip is opened in the map. |
tooltipclose |
TooltipEvent |
Fired when a tooltip in the map is closed. |
Event | Data | Description |
---|---|---|
click |
MouseEvent |
Fired when the user clicks (or taps) the map. |
dblclick |
MouseEvent |
Fired when the user double-clicks (or double-taps) the map. |
mousedown |
MouseEvent |
Fired when the user pushes the mouse button on the map. |
mouseup |
MouseEvent |
Fired when the user releases the mouse button on the map. |
mouseover |
MouseEvent |
Fired when the mouse enters the map. |
mouseout |
MouseEvent |
Fired when the mouse leaves the map. |
mousemove |
MouseEvent |
Fired while the mouse moves over the map. |
contextmenu |
MouseEvent |
Fired when the user pushes the right mouse button on the map, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). |
keypress |
KeyboardEvent |
Fired when the user presses a key from the keyboard while the map is focused. |
preclick |
MouseEvent |
Fired before mouse click on the map (sometimes useful when you want something to happen on click before any existing click handlers start running). |
Event | Data | Description |
---|---|---|
zoomanim |
ZoomAnimEvent |
Fired on every frame of a zoom animation |
Event | Data | Description |
---|---|---|
locationerror |
ErrorEvent |
Fired when geolocation (using the locate method) failed. |
locationfound |
LocationEvent |
Fired when geolocation (using the locate method)
went successfully. |
Method | Returns | Description |
---|---|---|
getRenderer(<Path>layer) |
Renderer |
Returns the instance of |
Method | Returns | Description |
---|---|---|
addControl(<Control>control) |
this |
Adds the given control to the map |
removeControl(<Control>control) |
this |
Removes the given control from the map |
addLayer(<Layer>layer) |
this |
Adds the given layer to the map |
removeLayer(<Layer>layer) |
this |
Removes the given layer from the map. |
hasLayer(<Layer>layer) |
Boolean |
Returns |
eachLayer(<Function>fn,<Object>context?) |
this |
Iterates over the layers of the map, optionally specifying context of the iterator function.
|
openPopup(<Popup>popup) |
this |
Opens the specified popup while closing the previously opened (to make sure only one is opened at one time for usability). |
openPopup(<String|HTMLElement>content,<LatLng>latlng,<Popup options>options?) |
this |
Creates a popup with the specified content and options and opens it in the given point on a map. |
closePopup(<Popup>popup?) |
this |
Closes the popup previously opened with openPopup (or the given one). |
openTooltip(<Tooltip>tooltip) |
this |
Opens the specified tooltip. |
openTooltip(<String|HTMLElement>content,<LatLng>latlng,<Tooltip options>options?) |
this |
Creates a tooltip with the specified content and options and open it. |
closeTooltip(<Tooltip>tooltip?) |
this |
Closes the tooltip given as parameter. |
Method | Returns | Description |
---|---|---|
setView(<LatLng>center,<Number>zoom,<Zoom/pan options>options?) |
this |
Sets the view of the map (geographical center and zoom) with the given animation options. |
setZoom(<Number>zoom,<Zoom/pan options>options) |
this |
Sets the zoom of the map. |
zoomIn(<Number>delta?,<Zoom options>options?) |
this |
Increases the zoom of the map by |
zoomOut(<Number>delta?,<Zoom options>options?) |
this |
Decreases the zoom of the map by |
setZoomAround(<LatLng>latlng,<Number>zoom,<Zoom options>options) |
this |
Zooms the map while keeping a specified geographical point on the map stationary (e.g. used internally for scroll zoom and double-click zoom). |
setZoomAround(<Point>offset,<Number>zoom,<Zoom options>options) |
this |
Zooms the map while keeping a specified pixel on the map (relative to the top-left corner) stationary. |
fitBounds(<LatLngBounds>bounds,<fitBounds options>options) |
this |
Sets a map view that contains the given geographical bounds with the maximum zoom level possible. |
fitWorld(<fitBounds options>options?) |
this |
Sets a map view that mostly contains the whole world with the maximum zoom level possible. |
panTo(<LatLng>latlng,<Pan options>options?) |
this |
Pans the map to a given center. |
panBy(<Point>offset) |
this |
Pans the map by a given number of pixels (animated). |
setMaxBounds(<Bounds>bounds) |
this |
Restricts the map view to the given bounds (see the maxBounds option). |
setMinZoom(<Number>zoom) |
this |
Sets the lower limit for the available zoom levels (see the minZoom option). |
setMaxZoom(<Number>zoom) |
this |
Sets the upper limit for the available zoom levels (see the maxZoom option). |
panInsideBounds(<LatLngBounds>bounds,<Pan options>options?) |
this |
Pans the map to the closest view that would lie inside the given bounds (if it's not already), controlling the animation using the options specific, if any. |
invalidateSize(<Zoom/Pan options>options) |
this |
Checks if the map container size changed and updates the map if so —
call it after you've changed the map size dynamically, also animating
pan by default. If |
invalidateSize(<Boolean>animate) |
this |
Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default. |
stop() |
this |
Stops the currently running |
flyTo(<LatLng>latlng,<Number>zoom?,<Zoom/pan options>options?) |
this |
Sets the view of the map (geographical center and zoom) performing a smooth pan-zoom animation. |
flyToBounds(<LatLngBounds>bounds,<fitBounds options>options?) |
this |
Sets the view of the map with a smooth animation like |
Method | Returns | Description |
---|---|---|
addHandler(<String>name,<Function>HandlerClass) |
this |
Adds a new |
remove() |
this |
Destroys the map and clears all related event listeners. |
createPane(<String>name,<HTMLElement>container?) |
HTMLElement |
Creates a new map pane with the given name if it doesn't exist already,
then returns it. The pane is created as a children of |
getPane(<String|HTMLElement>pane) |
HTMLElement |
Returns a map pane, given its name or its HTML element (its identity). |
getPanes() |
Object |
Returns a plain object containing the names of all panes as keys and the panes as values. |
getContainer() |
HTMLElement |
Returns the HTML element that contains the map. |
whenReady(<Function>fn,<Object>context?) |
this |
Runs the given function |
Method | Returns | Description |
---|---|---|
getCenter() |
LatLng |
Returns the geographical center of the map view |
getZoom() |
Number |
Returns the current zoom level of the map view |
getBounds() |
LatLngBounds |
Returns the geographical bounds visible in the current map view |
getMinZoom() |
Number |
Returns the minimum zoom level of the map (if set in the |
getMaxZoom() |
Number |
Returns the maximum zoom level of the map (if set in the |
getBoundsZoom(<LatLngBounds>bounds,<Boolean>inside?) |
Number |
Returns the maximum zoom level on which the given bounds fit to the map
view in its entirety. If |
getSize() |
Point |
Returns the current size of the map container (in pixels). |
getPixelBounds() |
Bounds |
Returns the bounds of the current map view in projected pixel coordinates (sometimes useful in layer and overlay implementations). |
getPixelOrigin() |
Point |
Returns the projected pixel coordinates of the top left point of the map layer (useful in custom layer and overlay implementations). |
getPixelWorldBounds(<Number>zoom?) |
Bounds |
Returns the world's bounds in pixel coordinates for zoom level |
Method | Returns | Description |
---|---|---|
getZoomScale(<Number>toZoom,<Number>fromZoom) |
Number |
Returns the scale factor to be applied to a map transition from zoom level
|
getScaleZoom(<Number>scale,<Number>fromZoom) |
Number |
Returns the zoom level that the map would end up at, if it is at |
project(<LatLng>latlng,<Number>zoom) |
Point |
Projects a geographical coordinate |
unproject(<Point>point,<Number>zoom) |
LatLng |
Inverse of |
layerPointToLatLng(<Point>point) |
LatLng |
Given a pixel coordinate relative to the origin pixel, returns the corresponding geographical coordinate (for the current zoom level). |
latLngToLayerPoint(<LatLng>latlng) |
Point |
Given a geographical coordinate, returns the corresponding pixel coordinate relative to the origin pixel. |
wrapLatLng(<LatLng>latlng) |
LatLng |
Returns a |
distance(<LatLng>latlng1,<LatLng>latlng2) |
Number |
Returns the distance between two geographical coordinates according to the map's CRS. By default this measures distance in meters. |
containerPointToLayerPoint(<Point>point) |
Point |
Given a pixel coordinate relative to the map container, returns the corresponding pixel coordinate relative to the origin pixel. |
layerPointToContainerPoint(<Point>point) |
Point |
Given a pixel coordinate relative to the origin pixel, returns the corresponding pixel coordinate relative to the map container. |
containerPointToLatLng(<Point>point) |
Point |
Given a pixel coordinate relative to the map container, returns the corresponding geographical coordinate (for the current zoom level). |
latLngToContainerPoint(<LatLng>latlng) |
Point |
Given a geographical coordinate, returns the corresponding pixel coordinate relative to the map container. |
mouseEventToContainerPoint(<MouseEvent>ev) |
Point |
Given a MouseEvent object, returns the pixel coordinate relative to the map container where the event took place. |
mouseEventToLayerPoint(<MouseEvent>ev) |
Point |
Given a MouseEvent object, returns the pixel coordinate relative to the origin pixel where the event took place. |
mouseEventToLatLng(<MouseEvent>ev) |
LatLng |
Given a MouseEvent object, returns geographical coordinate where the event took place. |
Method | Returns | Description |
---|---|---|
locate(<Locate options>options?) |
this |
Tries to locate the user using the Geolocation API, firing a |
stopLocate() |
this |
Stops watching location previously initiated by |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
Property | Type | Description |
---|---|---|
boxZoom |
Handler |
Box (shift-drag with mouse) zoom handler. |
doubleClickZoom |
Handler |
Double click zoom handler. |
dragging |
Handler |
Map dragging handler (by both mouse and touch). |
keyboard |
Handler |
Keyboard navigation handler. |
scrollWheelZoom |
Handler |
Scroll wheel zoom handler. |
tap |
Handler |
Mobile touch hacks (quick tap and touch hold) handler. |
touchZoom |
Handler |
Touch zoom handler. |
Pane | Type | Z-index | Description |
---|---|---|---|
mapPane |
HTMLElement |
'auto' |
Pane that contains all other map panes |
tilePane |
HTMLElement |
200 |
Pane for GridLayer s and TileLayer s |
overlayPane |
HTMLElement |
400 |
Pane for vector overlays (Path s), like Polyline s and Polygon s |
shadowPane |
HTMLElement |
500 |
Pane for overlay shadows (e.g. Marker shadows) |
markerPane |
HTMLElement |
600 |
Pane for Icon s of Marker s |
tooltipPane |
HTMLElement |
650 |
Pane for tooltip. |
popupPane |
HTMLElement |
700 |
Pane for Popup s. |
Map
take in an options
parameter. This
is a plain javascript object with the following optional components:Option | Type | Default | Description |
---|---|---|---|
watch |
Boolean |
false |
If true , starts continous watching of location changes (instead of detecting it
once) using W3C watchPosition method. You can later stop watching using
map.stopLocate() method. |
setView |
Boolean |
false |
If true , automatically sets the map view to the user location with respect to
detection accuracy, or to world view if geolocation failed. |
maxZoom |
Number |
Infinity |
The maximum zoom for automatic view setting when using setView option. |
timeout |
Number |
10000 |
Number of milliseconds to wait for a response from geolocation before firing a
locationerror event. |
maximumAge |
Number |
0 |
Maximum age of detected location. If less than this amount of milliseconds
passed since last geolocation response, locate will return a cached location. |
enableHighAccuracy |
Boolean |
false |
Enables high accuracy, see description in the W3C spec. |
Map
methods which modify the zoom level take in an options
parameter. This is a plain javascript object with the following optional
components:Option | Type | Default | Description |
---|---|---|---|
animate |
Boolean |
|
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true , the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation. |
Map
methods which modify the center of the map take in an options
parameter. This is a plain javascript object with the following optional
components:Option | Type | Default | Description |
---|---|---|---|
animate |
Boolean |
|
If true , panning will always be animated if possible. If false , it will
not animate panning, either resetting the map view if panning more than a
screen away, or just setting a new offset for the map pane (except for panBy
which always does the latter). |
duration |
Number |
0.25 |
Duration of animated panning, in seconds. |
easeLinearity |
Number |
0.25 |
The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, the less the more bowed the curve. |
noMoveStart |
Boolean |
false |
If true , panning won't fire movestart event on start (used internally for
panning inertia). |
Option | Type | Default | Description |
---|---|---|---|
animate |
Boolean |
|
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true , the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation. |
Option | Type | Default | Description |
---|---|---|---|
duration |
Number |
0.25 |
Duration of animated panning, in seconds. |
easeLinearity |
Number |
0.25 |
The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, the less the more bowed the curve. |
noMoveStart |
Boolean |
false |
If true , panning won't fire movestart event on start (used internally for
panning inertia). |
Option | Type | Default | Description |
---|---|---|---|
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 | Type | Default | Description |
---|---|---|---|
animate |
Boolean |
|
If not specified, zoom animation will happen if the zoom origin is inside the
current view. If true , the map will attempt animating zoom disregarding where
zoom origin is. Setting false will make it always reset the view completely
without animation. |
Option | Type | Default | Description |
---|---|---|---|
duration |
Number |
0.25 |
Duration of animated panning, in seconds. |
easeLinearity |
Number |
0.25 |
The curvature factor of panning animation easing (third parameter of the Cubic Bezier curve). 1.0 means linear animation, the less 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(<LatLng>latlng,<Marker options>options?) |
Instantiates a Marker object given a geographical point and optionally an options object. |
Option | Type | Default | Description |
---|---|---|---|
icon |
Icon |
* |
Icon class to use for rendering the marker. See Icon documentation for details on how to customize the marker icon. If not specified, a new L.Icon.Default is used. |
draggable |
Boolean |
false |
Whether the marker is draggable with mouse/touch or not. |
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. |
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. |
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. |
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(<LatLng>latlng) |
this |
Changes the marker position to the given point. |
setZIndexOffset(<Number>offset) |
this |
Changes the zIndex offset of the marker. |
setIcon(<Icon>icon) |
this |
Changes the marker icon. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the marker. |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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). |
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(<Popup options>options?,<Layer>source?) |
Instantiates a Popup object given an optional options object that describes its appearance and location and an optional source object that is used to tag the popup with a reference to the Layer to which it refers. |
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. |
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. |
autoClose |
Boolean |
true |
Set it to false if you want to override the default behavior of
the popup closing when another popup is opened. |
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. |
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(<LatLng>latlng) |
this |
Sets the geographical point where the popup will open. |
getContent() |
String|HTMLElement |
Returns the content of the popup. |
setContent(<String|HTMLElement|Function>htmlContent) |
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(<Map>map) |
this |
Adds the popup to the map and closes the previous one. The same as |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 offseting:
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(<Tooltip options>options?,<Layer>source?) |
Instantiates a Tooltip object given an optional options object that describes its appearance and location and an optional source object that is used to tag the tooltip with a reference to the Layer to which it refers. |
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 dynamicaly 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. |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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. Extends GridLayer
.
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar'}).addTo(map);
A string of the following form:
'http://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'
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(<String>urlTemplate,<TileLayer options>options?) |
Instantiates a tile layer object given a URL template and optionally an options object. |
Option | Type | Default | Description |
---|---|---|---|
minZoom |
Number |
0 |
Minimum zoom number. |
maxZoom |
Number |
18 |
Maximum zoom number. |
maxNativeZoom |
Number |
null |
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. |
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 |
false |
If true, all tiles will have their crossOrigin attribute set to ''. This is needed if you want to access tile pixel data. |
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 |
If false , new tiles are loaded during panning, otherwise only after it (for better performance). true by default on mobile browsers, otherwise false . |
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. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
If set, tiles will only be loaded inside the set LatLngBounds . |
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. |
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. |
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(<String>url,<Boolean>noRedraw?) |
this |
Updates the layer's URL template and redraws it (unless |
createTile(<Object>coords,<Function>done?) |
HTMLElement |
Called only internally, overrides GridLayer's |
TileLayer
might reimplement the following method.Method | Returns | Description |
---|---|---|
getTileUrl(<Object>coords) |
String |
Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
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. |
getAttribution() |
String |
Used by the |
getContainer() |
HTMLElement |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the grid layer. |
setZIndex(<Number>zIndex) |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<String>baseUrl,<TileLayer.WMS options>options) |
Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS parameters/options object. |
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 |
Minimum zoom number. |
maxZoom |
Number |
18 |
Maximum zoom number. |
maxNativeZoom |
Number |
null |
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. |
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 |
false |
If true, all tiles will have their crossOrigin attribute set to ''. This is needed if you want to access tile pixel data. |
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 |
If false , new tiles are loaded during panning, otherwise only after it (for better performance). true by default on mobile browsers, otherwise false . |
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. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
If set, tiles will only be loaded inside the set LatLngBounds . |
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. |
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. |
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(<Object>params,<Boolean>noRedraw?) |
this |
Merges an object with the new parameters and re-requests tiles on the current screen (unless |
Method | Returns | Description |
---|---|---|
setUrl(<String>url,<Boolean>noRedraw?) |
this |
Updates the layer's URL template and redraws it (unless |
createTile(<Object>coords,<Function>done?) |
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. |
getAttribution() |
String |
Used by the |
getContainer() |
HTMLElement |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the grid layer. |
setZIndex(<Number>zIndex) |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
CmWorld 2D Map API를 사용하여 오픈 지도 또는 사용자가 생성한 Raster Tile 지도를 서비스하거나, 사용자가 생성한 벡터 타일 지도를 서비스합니다. 상속: L.TileLayer
// 레어어 서버 URL 입니다.
var url = 'emap/{z}/{x}/{x}_{y}.png';
// layer 를 초기화 합니다.
var tilelayer = new L.tileLayer.CmWorld(url,{ //지도 데이터 정의 후 지도 영역에 타일 레이어 추가. 지도 타일링 파일이 있는 웹서버 URL
crs: L.TileLayer.CmWorld.GetOSMCRS(),// 벡터레이어 좌표계 설정. 배경지도가 Open Street Map이기 때문에 OSM 좌표계(EPSG:3857)로 설정
maxNativeZoom: 12, //타일링 데이터의 최종 레벨. 최소 레벨에서 최대 레벨까지 지도에 표시될때 12레벨부터 21레벨까지는 12레벨의 타일을 사용함.
minZoom: 6, //벡터 레이어가 지도에 표시될 최소 레벨
maxZoom: 21, //벡터 레이어가 지도에 표시될 최대 레벨.
tileSize: 256 //벡터 타일 크기
}).addTo(mymap);
'http://localhost:8080/emap/{z}/{x}/{y}{r}.png' 또는 '/emap/{z}/{x}/{y}.png'
Factory | Description |
---|---|
L.tileLayer.CmWorld(<String>urlTemplate,<CmWorld TileLayer options>options?) |
Instantiates a tile layer object given a URL template and optionally an options object. |
Option | Type | Default | Description |
---|---|---|---|
minZoom |
Number |
0 |
Minimum zoom number. |
maxZoom |
Number |
18 |
Maximum zoom number. |
maxNativeZoom |
Number |
null |
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. |
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 |
false |
If true, all tiles will have their crossOrigin attribute set to ''. This is needed if you want to access tile pixel data. |
tileSize |
Number |
256 |
타일 이미지의 해상도를 설정합니다. 기본은 256 픽셀이며, 512 등으로 설정할 수 있습니다. |
crs |
L.Proj.CRS |
L.CRS.EPSG3395 |
CmWorld TileLayer의 좌표계를 설정합니다. 좌표계가 설정되지 않으면 기본 좌표계인 World Mercator(EPSG 3395)로 설정됩니다. |
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 |
If false , new tiles are loaded during panning, otherwise only after it (for better performance). true by default on mobile browsers, otherwise false . |
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. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
If set, tiles will only be loaded inside the set LatLngBounds . |
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. |
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. |
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(<String>url,<Boolean>noRedraw?) |
this |
Updates the layer's URL template and redraws it (unless |
createTile(<Object>coords,<Function>done?) |
HTMLElement |
Called only internally, overrides GridLayer's |
GetOSMCRS() |
L.Proj.CRS |
Open Street Map(OSM) 좌표계를 구함. 좌표계(EPSG: 3857. WGS84 Web Mercator)와 지도 범위 |
GetUTMKCRS() |
L.Proj.CRS |
UTM-K 좌표계를 구함. 국토지리정보원의 '바로 e맵'에서 사용하는 좌표계. |
CmWorld TileLayer
might reimplement the following method.Method | Returns | Description |
---|---|---|
getTileUrl(<Object>coords) |
String |
Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
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. |
getAttribution() |
String |
Used by the |
getContainer() |
HTMLElement |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the grid layer. |
setZIndex(<Number>zIndex) |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
사용자가 생성한 벡터 타일 지도를 서비스합니다. CmWorld는 CMV 파일 포맷으로 벡터데이터를 서비스합니다. 상속: L.Layer
// cmv 파일 경로 입니다.
var url = 'vector/{z}/{x}/{x}_{y}.cmv';
// layer 를 초기화 합니다.
cmvlayer = new L.cmvLayer(url,{ //지도 데이터 정의 후 지도 영역에 타일 레이어 추가. 지도 타일링 파일이 있는 웹서버 URL
crs: L.TileLayer.CmWorld.GetOSMCRS(),// 벡터레이어 좌표계 설정. 배경지도가 Open Street Map이기 때문에 OSM 좌표계(EPSG:3857)로 설정
maxNativeZoom: 12, //타일링 데이터의 최종 레벨. 최소 레벨에서 최대 레벨까지 지도에 표시될때 12레벨부터 21레벨까지는 12레벨의 타일을 사용함.
minZoom: 6, //벡터 레이어가 지도에 표시될 최소 레벨
maxZoom: 21, //벡터 레이어가 지도에 표시될 최대 레벨.
tileSize: 256, //벡터 타일 크기
taskinterval : 16
}).addTo(mymap);
'http://localhost:8080/vector/{z}/{x}/{y}{r}.cmv' 또는 '/vector/{z}/{x}/{y}.cmv'
Factory | Description |
---|---|
L.cmvLayer(<String>urlTemplate,<CMV Layer options>options?) |
Instantiates a tile layer object given a URL template and optionally an options object. |
Option | Type | Default | Description |
---|---|---|---|
minZoom |
Number |
0 |
Minimum zoom number. |
maxZoom |
Number |
18 |
Maximum zoom number. |
maxNativeZoom |
Number |
null |
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. |
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 ) |
LayerInfos |
VectorLayerInfo |
[] |
CMV Layer를 구성하는 sub Layer 목록 레이어명, 레이어 스타일, 관련된 테이블 정보, 보이기 레벨 등의 벡터 레이어 정보로 구성되어 있음. |
LayerNames |
String[] |
[] |
CMV Layer를 구성하는 sub Layer 이름 목록 |
taskinterval |
Number |
10 |
벡터 타일을 서버에서 다운로드 받거나 화면에 드로잉할 때 멀티 쓰레드의 인터벌 시간 설정값. |
tileSize |
Number |
256 |
타일 이미지의 해상도를 설정합니다. 기본은 256 픽셀이며, 512 등으로 설정할 수 있습니다. |
crs |
L.Proj.CRS |
L.CRS.EPSG3395 |
CmWorld TileLayer의 좌표계를 설정합니다. 좌표계가 설정되지 않으면 기본 좌표계인 World Mercator(EPSG 3395)로 설정됩니다. |
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 |
If false , new tiles are loaded during panning, otherwise only after it (for better performance). true by default on mobile browsers, otherwise false . |
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. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
If set, tiles will only be loaded inside the set LatLngBounds . |
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. |
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. |
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(<String>url,<Boolean>noRedraw?) |
this |
Updates the layer's URL template and redraws it (unless |
createTile(<Object>coords,<Function>done?) |
HTMLElement |
Called only internally, overrides GridLayer's |
canvas() |
<canvas> |
CmWorld는 벡터데이터를 HTML5에서 지원하는 CANVAS에 각각의 객체를 스타일에 맞춰 드로잉한 후 지도창에 Document 객체로 추가합니다. 벡터데이터가 드로잉된 CANVAS Element를 리턴합니다. |
getTileSize() |
Number |
벡터 레이어의 타일 크기를 리턴합니다. 기본값은 256입니다. |
absPath() |
String |
벡터 레이어의 서버 URL 주소를 구합니다. |
refresh() |
|
벡터 레이어를 지도창에 다시 그립니다. |
addLayerInfo(<Number>layerIndex,<VectorLayerInfo>layerinfo) |
|
CMV Layer에 벡터레이어 정보를 추가합니다. |
CmWorld TileLayer
might reimplement the following method.Method | Returns | Description |
---|---|---|
getTileUrl(<Object>coords) |
String |
Called only internally, returns the URL for a tile given its coordinates.
Classes extending |
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. |
getAttribution() |
String |
Used by the |
getContainer() |
HTMLElement |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the grid layer. |
setZIndex(<Number>zIndex) |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
벡터레이어 정보. 레이어명, 레이어 스타일등의 속성 정보로 구성되어 있습니다.
cmvLayer에 addLayerInfo() 함수의 인수값으로 주로 사용됩니다.
//벡터 레이어 정보 정의
var layerinfo = new VectorLayerInfo("레이어명", thematicStyle, thematicKey, bVisible, selectable, labelVisible, tableName, minLevel, maxLevel);
//레이어 상세 스타일을 Renderer 정보를 입력합니다.
var renderItem = new RendererItem(style);
layerinfo.Renderer = new SimpleRenderer();
layerinfo.Renderer.AddRenderItem(renderItem);
//addLayerInfo에 레이어 번호와 생성된 벡터레이어 정보를 인수로 입력합니다.
cmvlayer.addLayerInfo(0, layerinfo);
Property | Type | Description |
---|---|---|
Name
| String |
벡터 레이어명 |
Visible
| Boolean |
벡터레이어 보이기 여부 |
ThematicStyle
| String |
벡터레이어 주제도 생성시 스타일 설정. [주제도 종류] "none": 해당 레이어는 같은 종류의 스타일을 적용, "range": 범위로 주제도 생성, "unique": 속성값으로 주제도 생성. |
ThematicKey
| String |
주제도 생성할 속성 항목 |
Selectable
| Boolean |
벡터 레이어 객체를 선택 가능한지의 여부 설정 |
LabelVisible
| Boolean |
벡터 레이어 라벨 보이기 여부 |
TableName
| String |
업무 시스템에서 데이터베이스와 연결되어 있으면, 레이어 객체가 참조할 테이블명을 연결할 수 있습니다. 주로 공간객체의 속성정보를 DBMS에 입력하고 선택된 객체의 상세 속성정보를 보이거나, 정보 조회할 때 사용됩니다. |
MinLevel |
Number |
The minimum zoom level that tiles will be loaded at. By default the entire map. |
MaxLevel |
Number |
The maximum zoom level that tiles will be loaded at. |
Renderer |
SimpleRenderer or ValueRangeRender or UniqueValueRenderer |
벡터 레이어 드로잉할 때 객체들이 같은 스타일로 그려집니다. |
//Renderer에 포함될 범례
var item = new LegendItem();
item.image = "image/icon.png";
item.thematictype = "none";
Property | Type | Description |
---|---|---|
image
| Image |
포인트 레이어의 이미지 심볼 URL. |
thematictype
| String |
벡터레이어 주제도 생성시 스타일 설정. [주제도 종류] "none": 해당 레이어는 같은 종류의 스타일을 적용, "range": 범위로 주제도 생성, "unique": 속성값으로 주제도 생성. |
minvalue
| Number |
범위의 최소값 |
maxvalue
| Number |
범위의 최대값 |
벡터레이어를 지도에 그리기 위한 스타일 설정 및 주제도 생성 시 설정될 스타일과 범위값을 정의합니다.
Render의 종류에는 SimpleRenderer, ValueRangeRender, UniqueValueRenderer가 있습니다.
// 벡터 레이어 스타일 정의하고 VectorLayerInfo에 Renderer를 인수로 설정
var renderer = new SimpleRenderer();
var layerinfo = new VectorLayerInfo("레이어명");
layerinfo.Renderer = renderer;
layer.addLayerInfo(0, layerinfo);
Factory | Description |
---|---|
SimpleRender() |
한가지 스타일로 벡터레이어를 드로잉합니다. |
ValueRangeRender() |
범위값으로 벡터레이어를 드로잉합니다. 하나 이상의 범위가 존재하면 범위의 개수 만큼 LegendItem을 AddRenderItem() 힘수를 생성하여 항목을 추가합니다. |
UniqueValueRenderer() |
속성값별로 벡터레이어를 드로잉합니다. 각각의 속성값에 스타일을 설정하여 벡터 레이어를 지도에 표시합니다. 하나 이상의 값이 존재하면 범위의 개수 만큼 LegendItem을 AddRenderItem() 힘수를 생성하여 항목을 추가합니다. |
Option | Type | Default | Description |
---|---|---|---|
renderItem |
Array |
[] |
벡터 레이어를 지도에 표시하기 위한 스타일 및 보기 범위 등의 레이어 정보 설정. LegendItem 목록 |
Method | Returns | Description |
---|---|---|
AddRenderItem(<LegendItem> item) |
|
renderItem 배열에 item을 추가합니다. |
GetRenderItem(<String> key) |
LegendItem |
renderItem 배열에서 key에 해당하는 item을 구합니다. |
GetLegendImage() |
Array |
벡터 레이어 범례 목록인 renderItem을 리턴합니다. |
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(<String>imageUrl,<LatLngBounds>bounds,<ImageOverlay options>options?) |
Instantiates an image overlay object given the URL of the image and the geographical bounds it is tied to. |
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. |
attribution |
String |
null |
An optional string containing HTML to be shown on the Attribution control |
crossOrigin |
Boolean |
false |
If true, the image will have its crossOrigin attribute set to ''. This is needed if you want to access image pixel data. |
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. |
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. |
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(<Number>opacity) |
this |
Sets the opacity of the overlay. |
bringToFront() |
this |
Brings the layer to the top of all overlays. |
bringToBack() |
this |
Brings the layer to the bottom of all overlays. |
setUrl(<String>url) |
this |
Changes the URL of the image. |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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. |
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. |
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. |
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(<Path options>style) |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<LatLng[]>latlngs,<Polyline options>options?) |
Instantiates a polyline object given an array of geographical points and
optionally an options object. You can create a Polyline object with
multiple separate lines (MultiPolyline ) by passing an array of arrays
of geographic points. |
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. |
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. |
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. |
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 |
Returns a |
getLatLngs() |
LatLng[] |
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs(<LatLng[]>latlngs) |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng(<LatLng>latlng) |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(<Path options>style) |
this |
Changes the appearance of a Path based on the options in the |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<LatLng[]>latlngs,<Polyline options>options?) |
Option | Type | Default | Description |
---|---|---|---|
smoothFactor |
Number |
1.0 |
How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation. |
noClip |
Boolean |
false |
Disable polyline clipping. |
Option | Type | Default | Description |
---|---|---|---|
stroke |
Boolean |
true |
Whether to draw stroke along the path. Set it to false to disable borders on polygons or circles. |
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. |
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. |
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. |
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 |
Returns a |
Method | Returns | Description |
---|---|---|
getLatLngs() |
LatLng[] |
Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. |
setLatLngs(<LatLng[]>latlngs) |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng(<LatLng>latlng) |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(<Path options>style) |
this |
Changes the appearance of a Path based on the options in the |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<LatLngBounds>latLngBounds,<Polyline options>options?) |
Option | Type | Default | Description |
---|---|---|---|
smoothFactor |
Number |
1.0 |
How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation. |
noClip |
Boolean |
false |
Disable polyline clipping. |
Option | Type | Default | Description |
---|---|---|---|
stroke |
Boolean |
true |
Whether to draw stroke along the path. Set it to false to disable borders on polygons or circles. |
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. |
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. |
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. |
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(<LatLngBounds>latLngBounds) |
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(<LatLng[]>latlngs) |
this |
Replaces all the points in the polyline with the given array of geographical points. |
isEmpty() |
Boolean |
Returns |
getCenter() |
LatLng |
Returns the center (centroid) of the polyline. |
getBounds() |
LatLngBounds |
Returns the |
addLatLng(<LatLng>latlng) |
this |
Adds a given point to the polyline. By default, adds to the first ring of
the polyline in case of a multi-polyline, but can be overridden by passing
a specific ring as a LatLng array (that you can earlier access with |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(<Path options>style) |
this |
Changes the appearance of a Path based on the options in the |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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], 200).addTo(map);
Factory | Description |
---|---|
L.circle(<LatLng>latlng,<Circle options>options?) |
Instantiates a circle object given a geographical point, and an options object which contains the circle radius. |
L.circle(<LatLng>latlng,<Number>radius,<Circle options>options?) |
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. |
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. |
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. |
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(<Number>radius) |
this |
Sets the radius of a circle. Units are in meters. |
getRadius() |
Number |
Returns the current radius of a circle. Units are in meters. |
getBounds() |
LatLngBounds |
Returns the |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(<Path options>style) |
this |
Changes the appearance of a Path based on the options in the |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<LatLng>latlng,<CircleMarker options>options?) |
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. |
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. |
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. |
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 |
Returns a |
setLatLng(<LatLng>latLng) |
this |
Sets the position of a circle marker to a new location. |
getLatLng() |
LatLng |
Returns the current geographical position of the circle marker |
setRadius(<Number>radius) |
this |
Sets the radius of a circle marker. Units are in pixels. |
getRadius() |
Number |
Returns the current radius of the circle |
Method | Returns | Description |
---|---|---|
redraw() |
this |
Redraws the layer. Sometimes useful after you changed the coordinates that the path uses. |
setStyle(<Path options>style) |
this |
Changes the appearance of a Path based on the options in the |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
Although SVG is not available on IE7 and IE8, these browsers support VML, and the SVG renderer will fall back to VML in this case. 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(<Renderer options>options?) |
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 |
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. |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<String>name) |
SVGElement |
Returns a instance of SVGElement, corresponding to the class name passed. For example, using 'line' will return an instance of SVGLineElement. |
pointsToPath(<Point[]>rings,<Boolean>closed) |
String |
Generates a SVG path string for multiple rings, with each ring turning into "M..L..L.." instructions |
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(<Renderer options>options?) |
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 |
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. |
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 |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<Layer[]>layers) |
Create a layer 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. |
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 |
Returns a |
addLayer(<Layer>layer) |
this |
Adds the given layer to the group. |
removeLayer(<Layer>layer) |
this |
Removes the given layer from the group. |
removeLayer(<Number>id) |
this |
Removes the layer with the given internal ID from the group. |
hasLayer(<Layer>layer) |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke(<String>methodName, …) |
this |
Calls |
eachLayer(<Function>fn,<Object>context?) |
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(<Number>id) |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex(<Number>zIndex) |
this |
Calls |
getLayerId(<Layer>layer) |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<Layer[]>layers) |
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. |
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(<Path options>style) |
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 top 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 |
Returns a |
addLayer(<Layer>layer) |
this |
Adds the given layer to the group. |
removeLayer(<Layer>layer) |
this |
Removes the given layer from the group. |
removeLayer(<Number>id) |
this |
Removes the layer with the given internal ID from the group. |
hasLayer(<Layer>layer) |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke(<String>methodName, …) |
this |
Calls |
eachLayer(<Function>fn,<Object>context?) |
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(<Number>id) |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex(<Number>zIndex) |
this |
Calls |
getLayerId(<Layer>layer) |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<Object>geojson?,<GeoJSON options>options?) |
Creates a GeoJSON layer. Optionally accepts an object in
GeoJSON format to display on the map
(you can alternatively add it later with addData method) and an options object. |
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 show a feature or not.
The default is to show all features:
|
coordsToLatLng |
Function |
* |
A Function that will be used for converting GeoJSON coordinates to LatLng s.
The default is the coordsToLatLng static method. |
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. |
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(<Path options>style) |
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 top 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 |
Returns a |
addLayer(<Layer>layer) |
this |
Adds the given layer to the group. |
removeLayer(<Layer>layer) |
this |
Removes the given layer from the group. |
removeLayer(<Number>id) |
this |
Removes the layer with the given internal ID from the group. |
hasLayer(<Layer>layer) |
Boolean |
Returns |
clearLayers() |
this |
Removes all the layers from the group. |
invoke(<String>methodName, …) |
this |
Calls |
eachLayer(<Function>fn,<Object>context?) |
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
|
getLayer(<Number>id) |
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex(<Number>zIndex) |
this |
Calls |
getLayerId(<Layer>layer) |
Number |
Returns the internal ID for a layer |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
---|---|---|
addData(data) |
Layer |
Adds a GeoJSON object to the layer. |
resetStyle(layer) |
Layer |
Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events. |
setStyle(style) |
Layer |
Changes styles of GeoJSON vector layers with the given style function. |
geometryToLayer(<Object>featureData,<GeoJSON options>options?) |
Layer |
Creates a Layer from a given GeoJSON feature. Can use a custom
pointToLayer and/or coordsToLatLng
functions if provided as options. |
coordsToLatLng(<Array>coords) |
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>coords,<Number>levelsDeep?,<Function>coordsToLatLng?) |
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(<LatLng>latlng) |
Array |
Reverse of coordsToLatLng |
latLngsToCoords(<Array>latlngs,<Number>levelsDeep?,<Boolean>closed?) |
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>geojson) |
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(<GridLayer options>options?) |
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 |
If false , new tiles are loaded during panning, otherwise only after it (for better performance). true by default on mobile browsers, otherwise false . |
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. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox". |
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 that tiles will be loaded at. By default the entire map. |
maxZoom |
Number |
undefined |
The maximum zoom level that tiles will be loaded at. |
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. |
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. |
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. |
getAttribution() |
String |
Used by the |
getContainer() |
HTMLElement |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(<Number>opacity) |
this |
Changes the opacity of the grid layer. |
setZIndex(<Number>zIndex) |
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns |
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(<Object>coords,<Function>done?) |
HTMLElement |
Called only internally, must be overriden by classes extending |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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));
Factory | Description |
---|---|
L.latLng(<Number>latitude,<Number>longitude,<Number>altitude?) |
Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude). |
L.latLng(<Array>coords) |
Expects an array of the form [Number, Number] or [Number, Number, Number] instead. |
L.latLng(<Object>coords) |
Expects an plain object of the form {lat: Number, lng: Number} or {lat: Number, lng: Number, alt: Number} instead. |
Method | Returns | Description |
---|---|---|
equals(<LatLng>otherLatLng,<Number>maxMargin?) |
Boolean |
Returns |
toString() |
String |
Returns a string representation of the point (for debugging purposes). |
distanceTo(<LatLng>otherLatLng) |
Number |
Returns the distance (in meters) to the given |
wrap() |
LatLng |
Returns a new |
toBounds(<Number>sizeInMeters) |
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 southWest = L.latLng(40.712, -74.227),
northEast = L.latLng(40.774, -74.125),
bounds = L.latLngBounds(southWest, northEast);
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]
]);
Factory | Description |
---|---|
L.latLngBounds(<LatLng>southWest,<LatLng>northEast) |
Creates a LatLngBounds object by defining south-west and north-east corners of the rectangle. |
L.latLngBounds(<LatLng[]>latlngs) |
Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds . |
Method | Returns | Description |
---|---|---|
extend(<LatLng>latlng) |
this |
Extend the bounds to contain the given point |
extend(<LatLngBounds>otherBounds) |
this |
Extend the bounds to contain the given bounds |
pad(<Number>bufferRatio) |
LatLngBounds |
Returns bigger bounds created by extending the current bounds by a given percentage in each direction. |
getCenter() |
LatLng |
Returns the center point of the bounds. |
getSouthWest() |
LatLng |
Returns the south-west point of the bounds. |
getNorthEast() |
LatLng |
Returns the north-east point of the bounds. |
getNorthWest() |
LatLng |
Returns the north-west point of the bounds. |
getSouthEast() |
LatLng |
Returns the south-east point of the bounds. |
getWest() |
Number |
Returns the west longitude of the bounds |
getSouth() |
Number |
Returns the south latitude of the bounds |
getEast() |
Number |
Returns the east longitude of the bounds |
getNorth() |
Number |
Returns the north latitude of the bounds |
contains(<LatLngBounds>otherBounds) |
Boolean |
Returns |
contains(<LatLng>latlng) |
Boolean |
Returns |
intersects(<LatLngBounds>otherBounds) |
Boolean |
Returns |
overlaps(<Bounds>otherBounds) |
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(<LatLngBounds>otherBounds) |
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));
Factory | Description |
---|---|
L.point(<Number>x,<Number>y,<Boolean>round?) |
Creates a Point object with the given x and y coordinates. If optional round is set to true, rounds the x and y values. |
L.point(<Number[]>coords) |
Expects an array of the form [x, y] instead. |
L.point(<Object>coords) |
Expects a plain object of the form {x: Number, y: Number} instead. |
Method | Returns | Description |
---|---|---|
clone() |
Point |
Returns a copy of the current point. |
add(<Point>otherPoint) |
Point |
Returns the result of addition of the current and the given points. |
subtract(<Point>otherPoint) |
Point |
Returns the result of subtraction of the given point from the current. |
divideBy(<Number>num) |
Point |
Returns the result of division of the current point by the given number. |
multiplyBy(<Number>num) |
Point |
Returns the result of multiplication of the current point by the given number. |
scaleBy(<Point>scale) |
Point |
Multiply each coordinate of the current point by each coordinate of
|
unscaleBy(<Point>scale) |
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). |
distanceTo(<Point>otherPoint) |
Number |
Returns the cartesian distance between the current and the given points. |
equals(<Point>otherPoint) |
Boolean |
Returns |
contains(<Point>otherPoint) |
Boolean |
Returns |
toString() |
String |
Returns a string representation of the point for debugging purposes. |
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]]);
Factory | Description |
---|---|
L.bounds(<Point>topLeft,<Point>bottomRight) |
Creates a Bounds object from two coordinates (usually top-left and bottom-right corners). |
L.bounds(<Point[]>points) |
Creates a Bounds object from the points it contains |
Method | Returns | Description |
---|---|---|
extend(<Point>point) |
this |
Extends the bounds to contain the given point. |
getCenter(<Boolean>round?) |
Point |
Returns the center point of the bounds. |
getBottomLeft() |
Point |
Returns the bottom-left point of the bounds. |
getTopRight() |
Point |
Returns the top-right point of the bounds. |
getSize() |
Point |
Returns the size of the given bounds |
contains(<Bounds>otherBounds) |
Boolean |
Returns |
contains(<Point>point) |
Boolean |
Returns |
intersects(<Bounds>otherBounds) |
Boolean |
Returns |
overlaps(<Bounds>otherBounds) |
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(<Icon options>options) |
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 |
null |
The coordinates of the point from which popups 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. |
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. |
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 |
---|---|---|
createIcon(<HTMLElement>oldIcon?) |
HTMLElement |
Called internally when the icon has to be shown, returns a |
createShadow(<HTMLElement>oldIcon?) |
HTMLElement |
As |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 |
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 change the default icon, just change the properties of L.Icon.Default.prototype.options
(which is a set of Icon options
).Option | Type | Default | Description |
---|---|---|---|
imagePath |
String |
|
L.Icon.Default will try to auto-detect the absolute 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 absolute 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(<DivIcon options>options) |
Creates a DivIcon instance with the given options. |
Option | Type | Default | Description |
---|---|---|---|
html |
String |
'' |
Custom HTML code to put inside the div element, empty by default. |
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 |
null |
The coordinates of the point from which popups 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. |
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. |
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 |
---|---|---|
createIcon(<HTMLElement>oldIcon?) |
HTMLElement |
Called internally when the icon has to be shown, returns a |
createShadow(<HTMLElement>oldIcon?) |
HTMLElement |
As |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 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(<Control.Zoom options>options) |
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(<string>position) |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo(<Map>map) |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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(<Control.Attribution options>options) |
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(<String>prefix) |
this |
Sets the text before the attributions. |
addAttribution(<String>text) |
this |
Adds an attribution text (e.g. |
removeAttribution(<String>text) |
this |
Removes an attribution text. |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition(<string>position) |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo(<Map>map) |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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(<Object>baselayers?,<Object>overlays?,<Control.Layers options>options?) |
Creates an attribution 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. |
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(<Layer>layer,<String>name) |
this |
Adds a base layer (radio button entry) with the given name to the control. |
addOverlay(<Layer>layer,<String>name) |
this |
Adds an overlay (checkbox entry) with the given name to the control. |
removeLayer(<Layer>layer) |
this |
Remove the given layer from the control. |
expand() |
this |
Expand the control container if collapsed. |
collapse() |
this |
Collapse the control container if expanded. |
Method | Returns | Description |
---|---|---|
getPosition() |
string |
Returns the position of the control. |
setPosition(<string>position) |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo(<Map>map) |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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(<Control.Scale options>options?) |
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(<string>position) |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo(<Map>map) |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
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). |
gecko |
Boolean |
true for gecko-based browsers like Firefox. |
android |
Boolean |
true for any browser running on an Android platform. |
android23 |
Boolean |
true for browsers running on Android 2 or Android 3. |
chrome |
Boolean |
true for the Chrome browser. |
safari |
Boolean |
true for the Safari browser. |
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. |
opera12 |
Boolean |
true for the Opera browser supporting CSS transforms (version 12 or later). |
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. |
mobileOpera |
Boolean |
true for the Opera browser in a mobile device. |
mobileGecko |
Boolean |
true for gecko-based browsers running in a mobile device. |
touch |
Boolean |
true for all browsers supporting touch events. |
msPointer |
Boolean |
true for browsers implementing the Microsoft touch events model (notably IE10). |
pointer |
Boolean |
true for all browsers supporting pointer events. |
retina |
Boolean |
true for browsers on a high-resolution "retina" screen. |
canvas |
Boolean |
true when the browser supports <canvas> . |
vml |
Boolean |
true if the browser supports VML. |
svg |
Boolean |
true when the browser supports SVG. |
Various utility functions, used by Leaflet internally.
Function | Returns | Description |
---|---|---|
extend(<Object>dest,<Object>src?) |
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>proto,<Object>properties?) |
Object |
Compatibility polyfill for Object.create |
bind(<Function>fn, …) |
Function |
Returns a new function bound to the arguments passed, like Function.prototype.bind.
Has a L.bind() shortcut. |
stamp(<Object>obj) |
Number |
Returns the unique ID of an object, assiging it one if it doesn't have it. |
throttle(<Function>fn,<Number>time,<Object>context) |
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.bind shortcut. |
wrapNum(<Number>num,<Number[]>range,<Boolean>includeMax?) |
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>num,<Number>digits?) |
Number |
Returns the number num rounded to digits decimals, or to 5 decimals by default. |
trim(<String>str) |
String |
Compatibility polyfill for String.prototype.trim |
splitWords(<String>str) |
String[] |
Trims and splits the string on whitespace and returns the array of parts. |
setOptions(<Object>obj,<Object>options) |
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(<Object>obj,<String>existingUrl?,<Boolean>uppercase?) |
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>str,<Object>data) |
String |
Simple templating facility, accepts a template string of the form 'Hello {a}, {b}'
and a data object like {a: 'foo', b: 'bar'} , returns evaluated string
('Hello foo, bar') . You can also specify functions instead of strings for
data values — they will be evaluated passing data as an argument. |
isArray(obj) |
Boolean |
Compatibility polyfill for Array.isArray |
indexOf(<Array>array,<Object>el) |
Number |
Compatibility polyfill for Array.prototype.indexOf |
requestAnimFrame(<Function>fn,<Object>context?,<Boolean>immediate?) |
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(<Number>id) |
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 = new 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)
Method | Returns | Description |
---|---|---|
transform(<Point>point,<Number>scale?) |
Point |
Returns a transformed point, optionally multiplied by the given scale.
Only accepts real |
untransform(<Point>point,<Number>scale?) |
Point |
Returns the reverse transformation of the given point, optionally divided
by the given scale. Only accepts real |
Various utility functions for polyine points processing, used by Leaflet internally to make polylines lightning-fast.
Function | Returns | Description |
---|---|---|
simplify(<Point[]>points,<Number>tolerance) |
Point[] |
Dramatically reduces the number of points in a polyline while retaining its shape and returns a new array of simplified points, using the Douglas-Peucker algorithm. Used for a huge performance boost when processing/displaying Leaflet polylines for each zoom level and also reducing visual noise. tolerance affects the amount of simplification (lesser value means higher quality but slower and with more points). Also released as a separated micro-library Simplify.js. |
pointToSegmentDistance(<Point>p,<Point>p1,<Point>p2) |
Number |
Returns the distance between point p and segment p1 to p2 . |
closestPointOnSegment(<Point>p,<Point>p1,<Point>p2) |
Number |
Returns the closest point from a point p on a segment p1 to p2 . |
clipSegment(<Point>a,<Point>b,<Bounds>bounds,<Boolean>useLastCode?,<Boolean>round?) |
Point[]|Boolean |
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. |
Various utility functions for polygon geometries.
Function | Returns | Description |
---|---|---|
clipPolygon(<Point[]>points,<Bounds>bounds,<Boolean>round?) |
Point[] |
Clips the polygon geometry defined by the given points by the given bounds (using the Sutherland-Hodgeman 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 seperate method for it. |
Utility functions to work with the DOM events, used by Leaflet internally.
Function | Returns | Description |
---|---|---|
on(<HTMLElement>el,<String>types,<Function>fn,<Object>context?) |
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(<HTMLElement>el,<Object>eventMap,<Object>context?) |
this |
Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} |
off(<HTMLElement>el,<String>types,<Function>fn,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified,
it will remove all the listeners of that particular DOM event from the element.
Note that if you passed a custom context to on, you must pass the same
context to off in order to remove the listener. |
off(<HTMLElement>el,<Object>eventMap,<Object>context?) |
this |
Removes a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} |
stopPropagation(<DOMEvent>ev) |
this |
Stop the given event from propagation to parent elements. Used inside the listener functions:
|
disableScrollPropagation(<HTMLElement>el) |
this |
Adds stopPropagation to the element's 'mousewheel' events (plus browser variants). |
disableClickPropagation(<HTMLElement>el) |
this |
Adds stopPropagation to the element's 'click' , 'doubleclick' ,
'mousedown' and 'touchstart' events (plus browser variants). |
preventDefault(<DOMEvent>ev) |
this |
Prevents the default action of the DOM Event ev from happening (such as
following a link in the href of the a element, or doing a POST request
with page reload when a <form> is submitted).
Use it inside listener functions. |
stop(ev) |
this |
Does stopPropagation and preventDefault at the same time. |
getMousePosition(<DOMEvent>ev,<HTMLElement>container?) |
Point |
Gets normalized mouse position from a DOM event relative to the
container or to the whole page if not specified. |
getWheelDelta(<DOMEvent>ev) |
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(<String|HTMLElement>id) |
HTMLElement |
Returns an element given its DOM id, or returns the element itself if it was passed directly. |
getStyle(<HTMLElement>el,<String>styleAttrib) |
String |
Returns the value for a certain style attribute on an element, including computed values or values set through CSS. |
create(<String>tagName,<String>className?,<HTMLElement>container?) |
HTMLElement |
Creates an HTML element with tagName , sets its class to className , and optionally appends it to container element. |
remove(<HTMLElement>el) |
|
Removes el from its parent element |
empty(<HTMLElement>el) |
|
Removes all of el 's children elements from el |
toFront(<HTMLElement>el) |
|
Makes el the last children of its parent, so it renders in front of the other children. |
toBack(<HTMLElement>el) |
|
Makes el the first children of its parent, so it renders back from the other children. |
hasClass(<HTMLElement>el,<String>name) |
Boolean |
Returns true if the element's class attribute contains name . |
addClass(<HTMLElement>el,<String>name) |
|
Adds name to the element's class attribute. |
removeClass(<HTMLElement>el,<String>name) |
|
Removes name from the element's class attribute. |
setClass(<HTMLElement>el,<String>name) |
|
Sets the element's class. |
getClass(<HTMLElement>el) |
String |
Returns the element's class. |
setOpacity(<HTMLElement>el,<Number>opacity) |
|
Set the opacity of an element (including old IE support).
opacity must be a number from 0 to 1 . |
testProp(<String[]>props) |
String|false |
Goes through the array of style names and returns the first name
that is a valid style name for an element. If no such name is found,
it returns false. Useful for vendor-prefixed styles like transform . |
setTransform(<HTMLElement>el,<Point>offset,<Number>scale?) |
|
Resets the 3D CSS transform of el so it is translated by offset pixels
and optionally scaled by scale . Does not have an effect if the
browser doesn't support 3D CSS transforms. |
setPosition(<HTMLElement>el,<Point>position) |
|
Sets the position of el to coordinates specified by position ,
using CSS translate or top/left positioning depending on the browser
(used by Leaflet internally to position its layers). |
getPosition(<HTMLElement>el) |
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(<HTMLElement>el) |
|
Makes the outline
of the element el invisible. Used internally by Leaflet to prevent
focusable elements from displaying an outline when the user performs a
drag interaction on them. |
restoreOutline() |
|
Cancels the effects of a previous L.DomUtil.preventOutline . |
Property | Type | Description |
---|---|---|
TRANSFORM |
String |
Vendor-prefixed fransform style name (e.g. 'webkitTransform' for WebKit). |
TRANSITION |
String |
Vendor-prefixed transform style 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(<HTMLElement>el,<Point>newPos,<Number>duration?,<Number>easeLinearity?) |
|
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(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<HTMLElement>el,<HTMLElement>dragHandle?,<Boolean>preventOutline) |
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(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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 = L.Class.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}
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(<Object>props) |
Function |
Extends the current class given the properties to be included.
Returns a Javascript function that is a class constructor (to be called with new ). |
include(<Object>properties) |
this |
Includes a mixin into the current class. |
mergeOptions(<Object>options) |
this |
Merges options into the defaults of the class. |
addInitHook(<Function>fn) |
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(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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. |
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(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
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(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
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(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
L.Layer
and (re-)implement the following methods.Method | Returns | Description |
---|---|---|
onAdd(<Map>map) |
this |
Should contain code that creates DOM elements for the layer, adds them to |
onRemove(<Map>map) |
this |
Should contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added in |
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(<Map>map) |
this |
Optional method. Called on |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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. |
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. |
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. |
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(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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(<string>position) |
this |
Sets the position of the control. |
getContainer() |
HTMLElement |
Returns the HTMLElement that contains the control. |
addTo(<Map>map) |
this |
Adds the control to the given map. |
remove() |
this |
Removes the control from the map it is currently active on. |
L.Control
and (re-)implement the following methods.Method | Returns | Description |
---|---|---|
onAdd(<Map>map) |
HTMLElement |
Should return the container DOM element for the control and add listeners on relevant map events. Called on |
onRemove(<Map>map) |
|
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. |
An object with methods for projecting geographical coordinates of the world onto a flat surface (and back). See Map projection.
Method | Returns | Description |
---|---|---|
project(<LatLng>latlng) |
Point |
Projects geographical coordinates into a 2D point. |
unproject(<Point>point) |
LatLng |
The inverse of |
Property | Type | Description |
---|---|---|
bounds |
LatLngBounds |
The bounds 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:3395 and Simple CRS. |
L.Projection.Mercator |
Elliptical Mercator projection — more complex than Spherical Mercator. Takes into account that Earth is a geoid, not a perfect sphere. 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. |
Abstract class 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.
Method | Returns | Description |
---|---|---|
latLngToPoint(<LatLng>latlng,<Number>zoom) |
Point |
Projects geographical coordinates into pixel coordinates for a given zoom. |
pointToLatLng(<Point>point,<Number>zoom) |
LatLng |
The inverse of |
project(<LatLng>latlng) |
Point |
Projects geographical coordinates into coordinates in units accepted for this CRS (e.g. meters for EPSG:3857, for passing it to WMS services). |
unproject(<Point>point) |
LatLng |
Given a projected coordinate returns the corresponding LatLng.
The inverse of |
scale(<Number>zoom) |
Number |
Returns the scale used when transforming projected coordinates into
pixel coordinates for a particular zoom. For example, it returns
|
zoom(<Number>scale) |
Number |
Inverse of |
getProjectedBounds(<Number>zoom) |
Bounds |
Returns the projection's bounds scaled and transformed for the provided |
distance(<LatLng>latlng1,<LatLng>latlng2) |
Number |
Returns the distance between two geographical coordinates. |
wrapLatLng(<LatLng>latlng) |
LatLng |
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. |
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. |
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 |
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. |
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(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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(<Map>map) |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom(<Map>map) |
this |
Removes the layer from the given map |
getPane(<String>name?) |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement|Function|Popup>content,<Popup options>options?) |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup(<LatLng>latlng?) |
this |
Opens the bound popup at the specificed |
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(<String|HTMLElement|Popup>content) |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement|Function|Tooltip>content,<Tooltip options>options?) |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip(<LatLng>latlng?) |
this |
Opens the bound tooltip at the specificed |
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(<String|HTMLElement|Tooltip>content) |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
on(<String>type,<Function>fn,<Object>context?) |
this |
Adds a listener function ( |
on(<Object>eventMap) |
this |
Adds a set of type/listener pairs, e.g. |
off(<String>type,<Function>fn?,<Object>context?) |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off(<Object>eventMap) |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire(<String>type,<Object>data?,<Boolean>propagate?) |
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 might can optionally be propagated to event parents. |
listens(<String>type) |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent(<Evented>obj) |
this |
Adds an event parent - an |
removeEventParent(<Evented>obj) |
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
ormap.getPanes
methods. New panes can be created with themap.createPane
method. Every map has the following default panes that differ only in zIndex.