Class Popup
Hierarchy (View Summary)
Index
Constructors
constructor
Parameters
Optionaloptions: PopupOptionsthe options
Returns Popup
Methods
addClassName
addTo
Adds the popup to a map.
Parameters
- map: MapLibreMap
The MapLibre GL JS map to add the popup to.
Returns this
- map: MapLibreMap
fire
Parameters
- event: string | Event
Optionalproperties: any
Returns this
getElement
getLngLat
Returns the geographical location of the popup's anchor.
The longitude of the result may differ by a multiple of 360 degrees from the longitude previously set by
setLngLatbecausePopupwraps the anchor longitude across copies of the world to keep the popup on screen.Returns LngLat
The geographical location of the popup's anchor.
getMaxWidth
Returns the popup's maximum width.
Returns string
The maximum width of the popup.
isOpen
Returns boolean
trueif the popup is open,falseif it is closed.
listens
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
Parameters
- type: string
The event type
Returns boolean
trueif there is at least one registered listener for specified event type,falseotherwise- type: string
off
Removes a previously registered event listener.
Parameters
- type: string
The event type to remove listeners for.
- listener: Listener
The listener function to remove.
Returns this
- type: string
on
Adds a listener to a specified event type.
Parameters
- type: string
The event type to add a listen for.
- listener: Listener
The function to be called when the event is fired. The listener function is called with the data object passed to
fire, extended withtargetandtypeproperties.
Returns Subscription
- type: string
once
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
- type: string
The event type to listen for.
Optionallistener: ListenerThe function to be called when the event is fired the first time.
Returns Popup | Promise<any>
thisor a promise if a listener is not provided- type: string
removeClassName
setDOMContent
Sets the popup's content to the element provided as a DOM node.
Parameters
- htmlNode: Node
A DOM node to be used as content for the popup.
Returns this
- htmlNode: Node
setEventedParent
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Optionalparent: Evented | nullOptionaldata: any
Returns this
setHTML
Sets the popup's content to the HTML provided as a string.
This method does not perform HTML filtering or sanitization, and must be used only with trusted content. Consider Popup.setText if the content is an untrusted text string.
Parameters
- html: string
A string representing HTML content for the popup.
Returns this
- html: string
setLngLat
Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
Parameters
- lnglat: LngLatLike
The geographical location to set as the popup's anchor.
Returns this
- lnglat: LngLatLike
setMaxWidth
Sets the popup's maximum width. This is setting the CSS property
max-width. Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-widthParameters
- maxWidth: string
A string representing the value for the maximum width.
Returns this
- maxWidth: string
setOffset
setPadding
Sets the popup's padding constraints for positioning.
Parameters
Optionalpadding: PaddingOptionsThe padding to apply as a PaddingOptions object.
Returns void
setSubpixelPositioning
setText
Sets the popup's content to a string of text.
This function creates a Text node in the DOM, so it cannot insert raw HTML. Use this method for security against XSS if the popup content is user-provided.
Parameters
- text: string
Textual content for the popup.
Returns this
- text: string
toggleClassName
Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
Parameters
- className: string
Non-empty string with CSS class name to add/remove
Returns boolean | undefined
if the class was removed return false, if class was added, then return true, undefined if there is no container
- className: string
trackPointer
Tracks the popup anchor to the cursor position on screens with a pointer device (it will be hidden on touchscreens). Replaces the
setLngLatbehavior. For most use cases, setcloseOnClickandcloseButtontofalse.Returns this
A popup component.
Example
Create a popup
Example
Create a popup
Example
See
Events
Event
openof type Event will be fired when the popup is opened manually or programmatically.Event
closeof type Event will be fired when the popup is closed manually or programmatically.