Marker
L.Marker is used to display interactive/draggable icons on the map. Extends Layer
.
Usage example
L.marker([50.5, 30.5]).addTo(map);
Creation
Factory | Description |
---|---|
L.marker( |
Instantiates a Marker object given a geographical point and optionally an options object. |
Options
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. |
Events
Event | Data | Description |
---|---|---|
move
|
Dragging events
Event | Data | Description |
---|---|---|
dragstart
| ||
movestart
| ||
drag
| ||
dragend
| ||
moveend
|
Event | Data | Description |
---|---|---|
click
| ||
dblclick
| ||
mousedown
| ||
mouseover
| ||
mouseout
| ||
contextmenu
|
Event | Data | Description |
---|---|---|
popupopen
| ||
popupclose
|
Event | Data | Description |
---|---|---|
tooltipopen
| ||
tooltipclose
|
Methods
Method | Returns | Description |
---|---|---|
getLatLng() |
LatLng |
Returns the current geographical position of the marker. |
setLatLng( |
this |
Changes the marker position to the given point. |
setZIndexOffset( |
this |
Changes the zIndex offset of the marker. |
setIcon( |
this |
Changes the marker icon. |
setOpacity( |
this |
Changes the opacity of the marker. |
Method | Returns | Description |
---|---|---|
bindPopup( |
this |
Binds a popup to the layer with the passed |
unbindPopup() |
this |
Removes the popup previously bound with |
openPopup( |
this |
Opens the bound popup at the 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( |
this |
Sets the content of the popup bound to this layer. |
getPopup() |
Popup |
Returns the popup bound to this layer. |
Method | Returns | Description |
---|---|---|
bindTooltip( |
this |
Binds a tooltip to the layer with the passed |
unbindTooltip() |
this |
Removes the tooltip previously bound with |
openTooltip( |
this |
Opens the bound tooltip at the 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( |
this |
Sets the content of the tooltip bound to this layer. |
getTooltip() |
Tooltip |
Returns the tooltip bound to this layer. |
Method | Returns | Description |
---|---|---|
addTo( |
this |
Adds the layer to the given map |
remove() |
this |
Removes the layer from the map it is currently active on. |
removeFrom( |
this |
Removes the layer from the given map |
getPane( |
HTMLElement |
Returns the |
Method | Returns | Description |
---|---|---|
on( |
this |
Adds a listener function ( |
on( |
this |
Adds a set of type/listener pairs, e.g. |
off( |
this |
Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to |
off( |
this |
Removes a set of type/listener pairs. |
off() |
this |
Removes all listeners to all events on the object. |
fire( |
this |
Fires an event of the specified type. You can optionally provide an data object — the first argument of the listener function will contain its properties. The event might can optionally be propagated to event parents. |
listens( |
Boolean |
Returns |
once(…) |
this |
Behaves as |
addEventParent( |
this |
Adds an event parent - an |
removeEventParent( |
this |
Removes an event parent, so it will stop receiving propagated events |
addEventListener(…) |
this |
Alias to |
removeEventListener(…) |
this |
Alias to |
clearAllEventListeners(…) |
this |
Alias to |
addOneTimeEventListener(…) |
this |
Alias to |
fireEvent(…) |
this |
Alias to |
hasEventListeners(…) |
Boolean |
Alias to |
Properties
Interaction handlers
Handler
methods). Example:
marker.dragging.disable();
Property | Type | Description |
---|---|---|
dragging
|
addTo()
andremove()
and popup methods like bindPopup() you can also use the following methods: