A tooltip anchored to a coordinate.
<HoloMap.Popup id="details" lng_lat={@selected_coords}>
<h3>{@selected.name}</h3>
<p>{@selected.address}</p>
</HoloMap.Popup>A popup declared here is open. Closing it means not rendering it, which is ordinary conditional rendering:
{%if @selected}
<HoloMap.Popup id="details" lng_lat={@selected.coords}>
<h3>{@selected.name}</h3>
</HoloMap.Popup>
{/if}That is the whole state model. There is no imperative open/close, because "which popup is open" is application state and belongs in your component.
Props
| Prop | Type | Notes |
|---|---|---|
id | string | Required. Identity across re-renders |
lng_lat | {lng, lat} | Required. Where the popup points |
html | string | Content as an HTML string, instead of slot content |
close_button | boolean | Show MapLibre's own close button |
close_on_click | boolean | Close when the map is clicked |
close_on_move | boolean | Close when the camera moves |
anchor | string | Which side of the popup touches the coordinate |
offset | number, [x, y] or map | Pixel offset from the anchor |
class_name | string | Extra classes on the popup element |
max_width | string | CSS max-width, default "240px" |
focus_after_open | boolean | Move keyboard focus into the popup |
subpixel_positioning | boolean | Position on fractional pixels |
Raw HTML must arrive through an expression
Hologram HTML-escapes literal text attributes before they ever reach a
component, so html="<b>hi</b>" written directly in a template
arrives as the characters <b>hi</b> and renders as visible text. Pass
it as an expression instead (html={@html}, or a value from state)
and the markup survives. Slot content has no such caveat.
Closing with the built-in button
MapLibre closes a popup on its own for three reasons: the close button, a
click on the map (close_on_click, on by default) and a camera move
(close_on_move). None of them go through your state, so without help the
component that rendered the popup still believes it is open, and clicking the
same thing again changes nothing, re-renders nothing, and the popup never
comes back.
on_close is what closes that gap. Handle it by clearing whatever state
opened the popup, and the declaration matches reality again:
{%if @selected}
<HoloMap.Popup id="details" lng_lat={@selected.coords} on_close={:selection_cleared}>
<h3>{@selected.name}</h3>
</HoloMap.Popup>
{/if}
def action(:selection_cleared, _params, component) do
put_state(component, :selected, nil)
endIf you would rather not handle it, set close_button={false} and
close_on_click={false} so the only way to close the popup is through your
own state.
A changed declaration always re-asserts itself: if the props change while MapLibre has the popup closed, it reopens. Selecting a different feature therefore works whether or not the previous popup was dismissed.
Events
on_open fires when the popup is added to the map, on_close when it leaves
it, including every close MapLibre performs on its own. Neither carries a
payload.
Slot content is cloned
Like HoloMap.Marker, popup content reaches MapLibre as an HTML clone, so
Hologram event bindings inside the slot do not fire. Put interactive
controls outside the map and drive them from state instead. See the
Limitations guide.
Summary
Functions
Returns true to indicate that the callee module is a component module (has "use Hologram.Component" directive).
Returns the list of property definitions for the compiled component.
Functions
@spec __is_hologram_component__() :: boolean()
Returns true to indicate that the callee module is a component module (has "use Hologram.Component" directive).
Examples
iex> __is_hologram_component__()
true
Returns the list of property definitions for the compiled component.