Tooltip
Used to display small texts on top of map layers.
Usage example
marker.bindTooltip("my tooltip text").openTooltip();
Note about tooltip offset. Leaflet takes two options in consideration for computing tooltip offseting:
- the
offset
Tooltip option: it defaults to [0, 0], and it's specific to one tooltip. Add a positive x offset to move the tooltip to the right, and a positive y offset to move it to the bottom. Negatives will move to the left and top. - the
tooltipAnchor
Icon option: this will only be considered for Marker. You should adapt this value if you use a custom icon.
Creation
Factory | Description |
---|---|
L.tooltip( |
Instantiates a Tooltip object given an optional options object that describes its appearance and location and an optional source object that is used to tag the tooltip with a reference to the Layer to which it refers. |
Options
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. |
Events
Event | Data | Description |
---|---|---|
popupopen
| ||
popupclose
|
Event | Data | Description |
---|---|---|
tooltipopen
| ||
tooltipclose
|
Methods
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 |