docs/api-reference/widgets/popup-widget.md
import {PopupWidgetDemo} from '@site/src/doc-demos/widgets'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
<PopupWidgetDemo />This widget shows a popup at a fixed position, or when an item in a deck.gl layer has been clicked or hovered.
<Tabs groupId="language"> <TabItem value="js" label="JavaScript">import {Deck} from '@deck.gl/core';
import {PopupWidget} from '@deck.gl/widgets';
import '@deck.gl/widgets/stylesheet.css';
new Deck({
initialViewState: {
longitude: -0.453,
latitude: 51.471,
zoom: 10
},
controller: true,
widgets: [
new PopupWidget({
position: [-0.453, 51.471],
content: {
text: "I'm here"
},
marker: {
html: '<div style="font-size:28px;transform:translate(-50%,-50%);">🏠</div>'
},
defaultIsOpen: true,
closeButton: true,
closeOnClickOutside: true
})
]
});
import {Deck} from '@deck.gl/core';
import {PopupWidget} from '@deck.gl/widgets';
import '@deck.gl/widgets/stylesheet.css';
new Deck({
initialViewState: {
longitude: -0.453,
latitude: 51.471,
zoom: 10
},
controller: true,
widgets: [
new PopupWidget({
position: [-0.453, 51.471],
content: {
text: "I'm here"
},
marker: {
html: '<div style="font-size:28px;transform:translate(-50%,-50%);">🏠</div>'
},
defaultIsOpen: true,
closeButton: true,
closeOnClickOutside: true
})
]
});
import React from 'react';
import DeckGL, {PopupWidget} from '@deck.gl/react';
import '@deck.gl/widgets/stylesheet.css';
function App() {
return (
<DeckGL
initialViewState={{
longitude: -0.453,
latitude: 51.471,
zoom: 10
}}
controller
>
<PopupWidget
position={[-0.453, 51.471]}
content={{text: "I'm here"}}
marker={{
html: '<div style="font-size:28px;transform:translate(-50%,-50%);">🏠</div>'
}}
defaultIsOpen
closeButton
closeOnClickOutside
/>
</DeckGL>
);
}
import {PopupWidget, type PopupWidgetProps} from '@deck.gl/widgets';
new PopupWidget({} satisfies PopupWidgetProps);
PopupWidgetProps {#popupwidgetprops}The PopupWidget accepts the generic WidgetProps and:
Anchor of the popup in world coordinates, e.g. [longitude, latitude].
Content to display in the popup. The object may contain the following fields:
text (string) - Text content to display in the popuphtml (string) - HTML content to display in the popup. If supplied, text is ignored.element (HTMLElement) - HTML element to attach to the popupContent to display at the anchor, regardless of whether the popup is open. Clicking on the marker opens the popup. The object may contain the following fields:
text (string) - Text content to display as the markerhtml (string) - HTML content to display as the marker. If supplied, text is ignored.element (HTMLElement) - HTML element to attach to the markerWhether the pop up is open by default.
trueWhether to show a close button in the popup.
trueClose the popup if clicked outside.
falseCallback when the popup is opened or closed. Receives the following parameters:
isOpen (boolean) - the next state of the popupPosition content relative to the anchor.
One of bottom | left | right | top | bottom-start | bottom-end | left-start | left-end | right-start | right-end | top-start | top-end
'right'Pixel offset from the anchor
10Show an arrow pointing at the anchor. Value can be one of the following:
false - do not display an arrow
number - pixel size of the arrow
[width: number, height: number] - pixel size of the arrow
Default: 10
Learn more about how to replace icons in the styling guide.
| Name | Type | Default |
|---|---|---|
--icon-close | SVG Data Url | Material Symbol Close |