Popup
Used to open popups in certain places of the map. Use Map.openPopup to open popups while making sure that only one popup is open at one time (recommended for usability), or use Map.addLayer to open as many as you want.
Usage example
If you want to just bind a popup to marker click and then open it, it's really easy:
marker.bindPopup(popupContent).openPopup();
Path overlays like polylines also have a bindPopup
method.
Here's a more complicated way to open a popup on a map:
var popup = L.popup()
.setLatLng(latlng)
.setContent('<p>Hello world!<br />This is a nice popup.</p>')
.openOn(map);
Creation
Factory | Description |
---|---|
L.popup( |
Instantiates a Popup object given an optional options object that describes its appearance and location and an optional source object that is used to tag the popup with a reference to the Layer to which it refers. |
Options
Option | Type | Default | Description |
---|---|---|---|
maxWidth |
Number
| 300 |
Max width of the popup, in pixels. |
minWidth |
Number
| 50 |
Min width of the popup, in pixels. |
maxHeight |
Number
| null |
If set, creates a scrollable container of the given height inside a popup if its content exceeds it. |
autoPan |
Boolean
| true |
Set it to false if you don't want the map to do panning animation
to fit the opened popup. |
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. |
Events
Event | Data | Description |
---|---|---|
popupopen
| ||
popupclose
|
Event | Data | Description |
---|---|---|
tooltipopen
| ||
tooltipclose
|
Methods
Method | Returns | Description |
---|---|---|
getLatLng() |
LatLng |
Returns the geographical point of popup. |
setLatLng( |
this |
Sets the geographical point where the popup will open. |
getContent() |
String|HTMLElement |
Returns the content of the popup. |
setContent( |
this |
Sets the HTML content of the popup. If a function is passed the source layer will be passed to the function. The function should return a |
getElement() |
String|HTMLElement |
Alias for getContent() |
update() |
null |
Updates the popup content, layout and position. Useful for updating the popup after something inside changed, e.g. image loaded. |
isOpen() |
Boolean |
Returns |
bringToFront() |
this |
Brings this popup in front of other popups (in the same map pane). |
bringToBack() |
this |
Brings this popup to the back of other popups (in the same map pane). |
openOn( |
this |
Adds the popup to the map and closes the previous one. The same as |
Method | Returns | Description |
---|---|---|
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 |