The map container. Everything else in HoloMap goes inside one.
<HoloMap.Map cid="explorer" style={@style_url} center={{-70.66, 19.45}} zoom={11}>
<HoloMap.Source.GeoJSON id="parcels" data={@parcels} />
<HoloMap.Layer.Fill id="parcels-fill" source="parcels" paint={%{fill_color: "#3b82f6"}} />
</HoloMap.Map>The cid is the map's identity
cid is Hologram's component id, and HoloMap uses it as the map's name
throughout: the DOM container is hm--<cid>, the browser registry is keyed by
it, and it is the first argument to every HoloMap.API function. One
identifier, no second id prop to keep in sync.
A cid is mandatory. Hologram only runs init/3, and therefore only allows
actions, on stateful components, and the map needs an action to boot.
Sizing
A map with no height renders as a zero-pixel box, which is the single most
common way to end up staring at a blank page. height defaults to "400px"
for that reason. Pass class instead when the size comes from your own CSS,
and set height={nil} to opt out of the inline style entirely.
The worker URL
MapLibre parses tiles in a Web Worker that it builds by importing
maplibre-gl-worker.mjs, resolved relative to its own module URL. Hologram
bundles MapLibre into a page bundle under /hologram/, so that resolution
lands on a file which is not there, and the failure happens inside a worker,
where nothing reports it. The symptom is a map that renders its background,
logs nothing, and never draws a single tile.
HoloMap sets the URL explicitly to avoid that. The default assumes the
application serves maplibre-gl-worker.mjs and maplibre-gl-shared.mjs from
/assets/; the Installation guide has the copy step, and
worker_url overrides the path if they live elsewhere.
Declarative camera versus animated camera
center, zoom, bearing and pitch are state. Changing one jumps the
camera there, and panning the map by hand does not write back into them:
the props describe where the application thinks the camera should be, not
where the user dragged it. Nothing re-renders while the user interacts, so
there is no fight between the two.
When a camera move is an event rather than a value, such as flying to a
search result, use HoloMap.API.fly_to/2 and leave the props alone.
Props
| Prop | Type | Notes |
|---|---|---|
style | string or map | Required. Style URL or inline style object |
center | {lng, lat} | Camera centre |
zoom / bearing / pitch | number | Camera attitude |
min_zoom / max_zoom / min_pitch / max_pitch | number | Camera constraints |
max_bounds | bounds | Pan constraint, in any shape HoloMap.Spec.bounds/1 accepts |
interactive | boolean | false for a static, non-navigable map |
hash | boolean | Sync the camera to the URL fragment |
attribution_control | boolean | MapLibre's built-in attribution. See HoloMap.Control.Attribution to place it yourself |
cooperative_gestures | boolean | Require ctrl/⌘ to scroll-zoom, so the page still scrolls |
drag_rotate / drag_pan / scroll_zoom / double_click_zoom / box_zoom / keyboard / touch_zoom_rotate | boolean | Individual interaction handlers |
antialias / pixel_ratio / fade_duration / render_world_copies / bearing_snap / track_resize / pitch_with_rotate / max_tile_cache_size / local_ideograph_font_family / validate_style / locale | various | Passed straight through to MapLibre |
options | map | Raw MapLibre constructor options, merged last. Keys must be MapLibre's own camelCase names: options={%{"maxCanvasSize" => [2048, 2048]}} |
worker_url | string | Where the application serves maplibre-gl-worker.mjs. Default "/assets/maplibre-gl-worker.mjs". See below |
class | string | CSS classes for the wrapper element |
height / width | string | Inline size for the canvas. nil opts out and leaves sizing to CSS |
Event props
on_load, on_click, on_dbl_click, on_context_menu, on_mouse_move,
on_move_start, on_move_end, on_zoom_end, on_rotate_end,
on_pitch_end, on_idle, on_error.
Events
Handlers receive a payload with center, zoom, bearing, pitch and
bounds, plus lng_lat and point for pointer events:
def action(:map_moved, params, component) do
put_state(component, :bounds, params.bounds)
endSee HoloMap.Event for the handler syntax and the Events
guide for the full payload reference.
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.