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 starts from
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. The symptom is a map that renders its
background and never draws a single tile. MapLibre reports the failed worker
through the map's error event, so on_error receives it, with the message
"Worker failed to load. Check that the worker URL is correct.". A map without
on_error leaves MapLibre to log it to the browser console.
HoloMap sets the URL explicitly to avoid that. The default assumes the
application serves maplibre-gl-worker.mjs from /assets/; the
Installation guide has the copy step, and worker_url
overrides the path if the worker lives elsewhere.
The default URL carries the version of the MapLibre the page loaded as a v
query parameter, /assets/maplibre-gl-worker.mjs?v=6.19.0 on 6.19.0, as
MapLibre's own default has since 6.13.0. Upgrading maplibre-gl therefore
changes the URL, and no cache can hand the new library the old worker.
Plug.Static ignores the query and serves the file; a CDN in front of it
has to keep the query in its cache key. A worker_url you set is used as
it is, with nothing added: put a version or a content hash in it, or serve
the file with headers that make browsers revalidate it, as Plug.Static's
default ETag without a max-age does.
MapLibre keeps one worker URL per page, and the first map to boot sets it. A
later map that asks for another one, its own worker_url or the default,
runs on the page's worker, and the browser runtime logs a warning once for
each other URL. Give every map on a page the same worker_url. The other
settings MapLibre keeps for the whole page follow the same rule (see
Settings for the whole page).
Settings for the whole page
MapLibre keeps a few settings in its module, for every map it draws, and takes each before it builds the first map:
| Prop | MapLibre | What it sets |
|---|---|---|
worker_url | setWorkerUrl | Where the workers start from (see The worker URL) |
worker_count | setWorkerCount | How many workers parse tiles. MapLibre's default is 1, and up to 3 in Safari |
max_parallel_image_requests | setMaxParallelImageRequests | The most images, raster tiles among them, requested at a time. MapLibre's default is 16 |
trusted_types_policy | setTrustedTypesPolicy | The name of the Trusted Types policy the browser runtime creates for MapLibre, on a page that enforces Trusted Types. See the Installation guide |
prewarm | prewarm | Start the workers before the map is built, and keep them for the next map once the last one is gone |
The first map to boot sets them, before MapLibre builds it, in that order:
prewarm starts the workers, so it comes after what they are built with. A
later map runs with the settings in place: one that asks for another value
of a setting logs a warning in the browser console, once for each value,
naming the setting, and a change to one on a map that is built logs one as
well. A map that leaves a setting out asks for nothing, except worker_url,
whose default is a URL of its own.
The rule holds for each copy of MapLibre: every Hologram page bundle carries its own (see the Registering JavaScript guide), and the first map of a page whose bundle the browser had not loaded yet sets that copy's settings. Give every map of the application the same values, or leave them out, rather than setting them on one page only.
prewarm suits an application that moves between pages with maps: MapLibre
ends its workers when the last map of its copy goes, and starts them again
for the next one, unless they were prewarmed.
Declarative camera versus animated camera
center, zoom, bearing, pitch, roll and elevation 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.
The limits, min_zoom, max_zoom, min_pitch, max_pitch and
max_bounds, are state as well. A change that leaves the camera outside the
new limits makes MapLibre zoom, pitch or pan it back within them. Like a
jump, that move is not reported: on_move_start, on_move_end,
on_zoom_end and on_pitch_end do not fire for it. The camera props keep
the values the application gave them, and the next move the user makes
reports where the limits left the camera.
A limit set back to nil is lifted, and the camera is as free as on a map
built without it: no bounds, a zoom from -2 to 22 and a pitch from 0 to 60,
MapLibre's defaults. A camera prop set to nil is different: it leaves the
camera where it is.
render_world_copies and pixel_ratio apply as they change too, and set
back to nil they return to MapLibre's defaults: world copies drawn, and the
device's pixel ratio. A new pixel_ratio resizes the canvas, which MapLibre
reports as a move, and that move is not reported either.
Interaction
interactive, cooperative_gestures and the eight handler props,
drag_rotate, drag_pan, scroll_zoom, double_click_zoom, box_zoom,
keyboard, touch_zoom_rotate and touch_pitch, apply as they change, so
a "lock the map" toggle can be state:
<HoloMap.Map cid="explorer" style={@style} interactive={!@locked} />interactive={false} turns off every one of the eight handlers. It also
takes away the grab cursor over the map and the canvas's place in the tab
order, as MapLibre does for a map built that way. Set back to true or
nil, it turns on again each handler whose own prop is not false. A
handler prop that changes while the map is not interactive applies once it
is. cooperative_gestures stands apart, as in MapLibre: interactive
leaves it as it is.
Handler settings
A handler prop takes true, false, or a map of the handler's settings,
which turns it on with them:
<HoloMap.Map cid="explorer" style={@style}
drag_rotate={%{around: "pointer"}}
keyboard={%{rotation: false}}
touch_zoom_rotate={%{rotation: false}} />| Prop | Settings |
|---|---|
drag_rotate | around: "center", MapLibre's default, turns the map about its centre; "pointer" about the point under the pointer where the drag starts, which keeps its place on screen while the map turns and tilts. movement, with "center" only: "circular", the default, follows the pointer round the centre like a wheel; "linear" turns the map as the pointer moves sideways, as "pointer" always does |
drag_pan | how the map glides on once a drag ends: max_speed, the fastest it glides, in pixels per second, 1400 unless set; deceleration, how fast it slows, 2500; and linearity, the share of the drag's speed it keeps, 0.3 |
scroll_zoom | around: "center" zooms about the centre rather than the pointer. zoom_rate and wheel_zoom_rate, how far a trackpad's and a mouse wheel's movement zooms, 1/100 and 1/450 unless set |
touch_zoom_rotate | rotation: false keeps two fingers from turning the map, which they still zoom. around: "center". zoom_rate, how far a pinch zooms, 1 unless set, and zoom_threshold, how far it must go before it zooms, 0.1 |
touch_pitch | around: "center" |
keyboard | rotation: false keeps Shift with the arrow keys from turning and tilting the map. The arrow keys still pan it, and + and - zoom it |
around and movement take strings or atoms. double_click_zoom and
box_zoom take true or false alone. A setting the handler does not
take, or a value MapLibre does not, raises ArgumentError, and so does
movement with around: "pointer".
Settings apply as they change. MapLibre reads around, movement and the
glide as a handler turns on, so a change to them turns the handler off and
on again with the new ones. The others go through the handler's setters,
and one taken out of the map returns to MapLibre's default. A handler that
is off, through its own prop or interactive, keeps its rotation and rates
for when it turns on.
Debug toggles
show_tile_boundaries, show_collision_boxes, show_overdraw_inspector
and show_padding turn on MapLibre's rendering debug views: an outline and
the id of each tile, boxes around the labels and icons that show which were
placed and which collided, a shade for how many times each pixel was
drawn, and the camera's padding. Each applies as it changes, so a debug
switch can be state:
<HoloMap.Map cid="dev" style={@style} show_tile_boundaries={@debug}
show_collision_boxes={@debug} />They are properties of MapLibre's map rather than options, and the browser
runtime sets them once the map is built and as they change. MapLibre draws
collision boxes from the style's tiles, so show_collision_boxes waits for
the style, as a layer does, while one loads or the WebGL context is lost.
Each is off unless set.
Global state
A style can read named values with MapLibre's global-state expression,
and global_state sets them. One change to it restyles every layer that
reads a name, in the browser, with no paint, layout or filter sent again:
<HoloMap.Map cid="explorer" style={@style} global_state={%{theme: @theme, min_population: @min}}>
<HoloMap.Source.GeoJSON id="cities" data={@cities} />
<HoloMap.Layer.Circle
id="cities"
source="cities"
filter={[">=", ["get", "population"], ["global-state", "min_population"]]}
paint={%{circle_color: ["match", ["global-state", "theme"], "dark", "#e5e7eb", "#111827"]}}
/>
</HoloMap.Map>Each name is sent as written, an atom as its name: min_population stays
min_population, since it is the application's own word and not a style
property. A value is anything an expression can read, such as a number, a
string, a boolean or a list.
The map is built with the global state, so the first render already draws
with it. A change sets each name that changed with MapLibre's
setGlobalStateProperty, and only those. A name taken out of the map, or
set to nil, goes back to the default the style declares for it in its
state, or to null when the style declares none. A name the style does
not declare is set all the same, and global-state reads it.
The global state belongs to the style in MapLibre, and a new style starts
from its own defaults. The browser runtime hands every new style the
global state the map declares, whether MapLibre diffs it or builds it from
scratch, so the values hold through a style change. A change made while a
new style loads applies once it has loaded. A value set some other way,
through HoloMap.Runtime.call/3, is not handed to a new style, which can
set the name back to its default.
Setting the global state fires no map event. HoloMap.API.request/4 reads
the state the map holds with "getGlobalState".
Projection
projection picks how the map is drawn: "mercator", "globe" or
"vertical-perspective", or an expression that picks one, such as a globe
for world views that turns flat when the map zooms in on a city:
<HoloMap.Map cid="world" style={@style} projection={@projection}
on_projection_transition={:projection_changed}>
<HoloMap.Control.Globe />
</HoloMap.Map>
projection={["step", ["zoom"], "vertical-perspective", 11, "mercator"]}MapLibre has no projection option: the projection belongs to the style, and
a style may declare its own. The prop wins over the style's. It is put in
place once the first style has loaded, and as it changes, with MapLibre's
setProjection, without a style reload. A style change keeps it: MapLibre
is handed it in place of the new style's own when it diffs the new style,
and it is put in place again once a style built from scratch has loaded.
Set to nil, the projection goes back to the one the style declares, or to
mercator for a style that declares none. A map without the prop draws with
the style's projection, as MapLibre does.
MapLibre keeps the projection an expression made when it is asked for
"globe" next, and goes on drawing as the expression does. The browser
runtime puts mercator in place in between, unreported, so a prop that goes
from an expression to "globe" draws a globe.
HoloMap.Control.Globe switches the projection as the user clicks it. The
prop is put back only when its value changes, or the style does, as the
camera props are: a render that leaves it as it was leaves the user's
choice alone.
on_projection_transition reports each projection MapLibre puts in place:
the one the map starts with, once its first style has loaded, a change to
the prop, a click on HoloMap.Control.Globe, a style MapLibre diffs that
changes the projection, and every style built from scratch, which puts one
in place again. A style the prop replaces the projection of reports only
the prop's. Its payload is the camera, as for the other map events, and
projection, the projection's type as the prop takes it: a name, or the
expression. An action that writes it back into the state the prop reads
from changes nothing, and keeps that state in step with the control:
def action(:projection_changed, params, component) do
put_state(component, :projection, params.projection)
endA globe zooming in past an expression's switch, or past the zoom where
MapLibre's own "globe" turns flat, is not a new projection, and is not
reported.
HoloMap.Terrain and HoloMap.Sky stay through a change of projection.
MapLibre draws terrain on a globe too, without the fog it gives terrain on
a flat map, and logs "calculateFogMatrix is not supported on globe
projection." once when it does. The sky's atmosphere_blend is the glow
around a globe.
Glyphs and font faces
glyphs points the map's text at another glyph server, a URL with the
{fontstack} and {range} tokens MapLibre fills in. font_faces names
font files to draw text with, for scripts a glyph server cannot draw, such
as Arabic or Khmer, whose letters change shape with the marks and letters
next to them:
<HoloMap.Map
cid="explorer"
style={@style}
glyphs="https://fonts.example.com/{fontstack}/{range}.pbf"
font_faces={%{"Noto Sans Arabic" => "https://fonts.example.com/noto-arabic.woff2"}}
>Each key of font_faces is a font name a symbol layer's text_font names,
sent as written. Its value is the URL of a font file, or a list of faces,
each a map with the url and the unicode_range it covers:
font_faces={%{"Noto Sans Regular" => [
%{url: "/fonts/NotoSansKhmer-Regular.ttf", unicode_range: ["U+1780-17FF"]},
%{url: "/fonts/NotoSansDevanagari-Regular.ttf", unicode_range: ["U+0900-097F"]}
]}}MapLibre draws a character with the first face of its font that covers it, and takes the rest from the glyph server. It downloads a font file only once a character the file covers is drawn, and skips a face it cannot load or read, with a console warning.
Each replaces the style's own: font_faces is not merged with the font
faces a style declares. Both belong to the style in MapLibre, which has no
option for either. They are put in place once the first style has loaded,
and as they change, with setGlyphs and setFontFaces, and each change
lays the map's labels out again. A style change keeps them: every new
style, whether MapLibre diffs it or builds it from scratch, has them put in
place once it has loaded, before it draws, and after a WebGL context loss
MapLibre builds the style with them. Set to nil, they go back to the
style's own, or to none for a style without: with no glyphs, MapLibre draws
text with the fonts the device has. A glyphs URL MapLibre refuses, one
without its two tokens, is reported through on_error, and the map keeps
the glyphs it had. Neither fires a map event.
Request transform and missing images
transform_request and missing_image_resolver each name a function the
application registered in JavaScript with register.function (see the
Registering JavaScript guide), since a prop cannot carry
a function:
<HoloMap.Map cid="explorer" style={@style}
transform_request="signedRequests"
missing_image_resolver="drawIcons" />MapLibre calls the transform_request function just before each request it
makes, the style's first, with the URL, the kind of resource ("Style",
"Source", "Tile", "Glyphs", "SpriteImage", "SpriteJSON",
"Image") and %{map, cid, request}, in which map is null for the
style's request, made while MapLibre builds the map, and request is the
request the request_rules made (see Request rules),
or {url}. It answers the request to make instead, {url, headers, credentials}, or a promise of one, or nothing to leave request as it is.
An error it throws fails that request, which on_error hears, the style's
first request among them. A style whose request fails ends the style change
that asked for it (see Changing the style).
MapLibre calls the missing_image_resolver function for each image a tile
needs that neither the style's sprite nor the map holds, with the image's
id and %{map, cid}, and waits for the promise it returns before it reports
the image as missing. The function adds the image with the map's
addImage. on_style_image_missing fires only for an image that is still
missing afterwards. An image a HoloMap.Image declares is left to the
component, even while it loads, and the function is not asked for it. An
error the function throws, or a promise of its that rejects, is reported
through on_error, and the image stays missing.
Both apply as they change, without rebuilding the map. A name nothing has registered yet is warned about once in the browser console, and MapLibre goes on as it would without the prop until a function is registered under it: the name is looked up each time MapLibre calls.
Request rules
A tile server that wants a header or a cookie on its requests needs no
JavaScript: request_rules lists what to add to the requests MapLibre
makes, by the start of their URL.
<HoloMap.Map cid="private" style={@style} request_rules={[
%{url_prefix: "https://tiles.example.com/", headers: %{"Authorization" => "Bearer " <> @token}},
%{url_prefix: "https://cdn.example.com/", credentials: "include"}
]} />Each rule is a map with:
url_prefix- required. The rule applies to a request whose URL starts with it. Both are resolved against the page first, so"/tiles/"matches the page's own/tiles/whether MapLibre requests it by a relative or an absolute URL, and a prefix that stops at a host,"https://tiles.example.com", ends there: it does not matchhttps://tiles.example.com.attacker.net/.headers- a map of header names to string values, sent as written. A header set tonilis left out.credentials-"include"to send cookies with a request to another origin, or"same-origin", the browser's default.
The first rule that matches a request applies, and only that one, so a
narrower prefix goes before a broader one, and a rule with url_prefix
alone keeps the rules after it off its requests. MapLibre makes the
style's request while it builds the map, and it goes through the rules too.
A change to the rules applies from MapLibre's next request, with
setTransformRequest: what MapLibre has already loaded stays as it is.
The rules apply before transform_request: its function receives the
request they made as request, to sign it or to answer another, and
what it answers wins. A request it throws for is not made, whatever the
rules added.
The rules reach the requests MapLibre makes itself. A protocol registered
with register.protocol is handed the headers and credentials with the
rest of the request, and does with them what it does: PMTiles' protocol
makes requests of its own, without them (see the
Registering JavaScript guide). A header on a
request to another origin makes the browser ask the server first, with a
CORS preflight, so the server must allow the header.
The rules are rendered into the page
Every value in request_rules, a token among them, is written into the
page's HTML, where anyone who can open the page can read it. Put there
only what the browser may hold: a token scoped to reading those tiles,
short-lived, or tied to the user who sees the page. A secret that must
stay on the server belongs in a proxy that adds it there. The browser
runtime does not repeat a rule's values in its console warnings or in
what on_error receives, and the ArgumentError a rule it cannot send
raises names the key, not the value.
Changing the style
style applies as it changes, compared by value, so an inline style rendered
again unchanged does nothing. MapLibre diffs the new style against the one on
the map, and the browser runtime carries every source, layer and
HoloMap.Sprite the components declared into the new style, so only the
basemap changes: the map does not go blank, sources both styles share keep
their tiles, and a sprite and glyphs both styles use are not requested
again. The components' layers keep their template order, a before_id
names a layer of the new style, and each layer goes back to its props,
losing whatever HoloMap.API set on it. Images, sprites, terrain, sky, the
feature state of the components' sources, the global_state, the
projection, glyphs and font_faces stay as they were, and
HoloMap.Light's light is set again over the new style's own. A new style
the diff finds nothing to change in leaves the map as it is, and one that
fails MapLibre's validation is reported through on_error, or the browser
console, and the map keeps the style it has.
A source, layer or sprite whose id the new style uses is the new style's,
as on the first style: its component adds nothing, the layers of such a
source stay off the map, and the browser runtime logs a warning naming them.
MapLibre builds the new style from scratch instead when it cannot diff it,
for example when the new style sets centerAltitude, and when the change
comes before the first style has loaded. The map then starts from an empty
style, and the components' sources, layers, images, sprites, terrain, sky
and light are declared again once it has loaded, over a style that starts
with the global_state, and the projection, glyphs and font_faces are
put in place again. HoloMap.API.set_style/3 with diff: false asks for that
on purpose. Either way, changes and HoloMap.API calls made while the style
changes wait for it.
Style changes made one after another before their styles arrive end on the
last style asked for, whatever order the styles arrive in. MapLibre aborts
the request for a style when the next change comes, but can lose track of
the newer request and diff its style when it arrives, after a later
change's (Map#_diffStyle, 6.19.0 and 6.20.0). The browser runtime hands
such a style's diff the style the map has, so it changes nothing, and the
changes and calls that wait go on waiting for the last style.
A style MapLibre cannot load ends the change all the same: a URL that
answers 404 or cannot be reached, a body that is not JSON, a
transform_request function that throws for the style's request, and a
style that fails MapLibre's validation. MapLibre's error reaches
on_error, or the browser console. A style MapLibre was to diff leaves the
map with the style it had, and the changes and calls that waited run on it.
A style built from scratch, and the map's first style, leave the map with
no style at all: HoloMap.API.request/4 answers the requests that waited
with an :error naming MapLibre's, and answers so every request made until
the map is asked for another style. The changes and the other calls wait
for that style, as they wait for a first one, and a
HoloMap.API.set_style/3 call asks for it at once.
The style prop keeps the value the page rendered, so rendering the same
value again asks for nothing: setting it back to the style the map kept
diffs that style against itself, which changes nothing, and asking for a
failed URL again takes another value first, or HoloMap.API.set_style/3,
which asks every time it is called.
Losing the WebGL context
A browser can take a page's WebGL context away, when the GPU resets or too
many contexts are open, and give it back later. on_webgl_context_lost and
on_webgl_context_restored report both. In between MapLibre has no style
and draws nothing, and changes and HoloMap.API calls made meanwhile wait,
as they do while a style changes. Once the context is back, MapLibre builds
the style the map had again, from a copy it kept, and the components'
sources, layers, images, sprites, terrain and sky are theirs as they were,
with what HoloMap.API set on them. HoloMap.Light's light, which the
copy leaves out, is set again. The global_state, the projection,
glyphs and font_faces are the ones the map declares, a style changed
meanwhile is then diffed against it, and a source, layer or sprite whose
id the style held before stays the style's, without a second warning.
Feature state is gone, and so is a global state value set through
HoloMap.Runtime.call/3, as on a style MapLibre builds from scratch. A context lost while a style is still loading leaves
MapLibre nothing to build again, and the map stays blank until its style
changes.
Props read only when the map is built
MapLibre reads some options only while it builds the map, and has no setter
to change them afterwards. The props table below marks them build only:
hash, attribution_control, antialias, pitch_with_rotate,
fade_duration, bearing_snap, track_resize, max_tile_cache_size,
local_ideograph_font_family, validate_style, locale, worker_url,
bounds, fit_bounds_options, rotate_speed, pitch_speed,
roll_enabled, reduce_motion, click_tolerance, max_canvas_size,
max_tile_cache_zoom_levels, zoom_levels_to_overscale,
terrain_skirt_length, cross_source_collisions,
refresh_expired_tiles, maplibre_logo and logo_position.
A change to one leaves the map as it was built, and the browser runtime logs
a console warning that names the MapLibre option, once for each option on
each map. A key of options is build only as well, unless it is the
MapLibre name of an option that applies as it changes, such as
"maxBounds", which then applies as its prop does.
Props
| Prop | Type | After the map is built | Notes |
|---|---|---|---|
style | string or map | Applies | Required. Style URL or inline style object. See Changing the style |
center | {lng, lat} | Applies | Camera centre |
zoom / bearing / pitch | number | Applies | Camera attitude |
roll | number | Applies | The camera's turn about the line it looks along, in degrees |
elevation | number | Applies | The centre's elevation, in metres above sea level. Over terrain, MapLibre puts the centre back on the ground on the next move, unless HoloMap.API.set_center_clamped_to_ground/2 turned that off |
min_zoom / max_zoom / min_pitch / max_pitch | number | Applies | Camera constraints. nil lifts one |
max_bounds | bounds | Applies | Pan constraint, in any shape HoloMap.Spec.bounds/1 accepts. nil lifts it |
interactive | boolean | Applies | false for a static, non-navigable map. See Interaction |
hash | boolean | Build only | Sync the camera to the URL fragment |
attribution_control | boolean | Build only | MapLibre's built-in attribution. See HoloMap.Control.Attribution to place it yourself |
cooperative_gestures | boolean | Applies | 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 / touch_pitch | boolean or map | Applies | Individual interaction handlers, on or off, or on with settings. See Handler settings |
antialias | boolean | Build only | Ask the WebGL context for antialiasing, which smooths the edges of fill-extrusion layers. Sent as MapLibre's canvasContextAttributes |
render_world_copies | boolean | Applies | Draw the world again beyond 180 degrees of longitude. Default true |
pixel_ratio | number | Applies | Render at this ratio of canvas pixels to CSS pixels instead of the device's |
projection | string or list | Applies | "mercator", "globe", "vertical-perspective" or an expression. Wins over the style's projection. nil returns to it. See Projection |
global_state | map | Applies | Values the style's global-state expressions read, by name. A name set to nil or taken out goes back to the style's default. See Global state |
glyphs | string | Applies | Glyph server URL, with {fontstack} and {range}. Replaces the style's glyphs. nil returns to them. See Glyphs and font faces |
font_faces | map | Applies | Font files by font name, a URL or a list of %{url: url, unicode_range: ranges}. Replaces the style's font faces. nil returns to them. See Glyphs and font faces |
transform_request | string | Applies | The name of a function registered in JavaScript that MapLibre calls before each request. See Request transform and missing images |
request_rules | list of maps | Applies | Headers and credentials to add to the requests whose URL starts with a prefix. Rendered into the page. See Request rules |
missing_image_resolver | string | Applies | The name of a function registered in JavaScript that adds an image a layer asks for and the map lacks. See Request transform and missing images |
fade_duration / bearing_snap / track_resize / pitch_with_rotate / max_tile_cache_size / local_ideograph_font_family / validate_style / locale | various | Build only | Passed straight through to MapLibre |
bounds | bounds | Build only | A box, in any shape HoloMap.Spec.bounds/1 accepts, that the first view fits. It wins over center and zoom. HoloMap.API.fit_bounds/3 fits a box later |
fit_bounds_options | map | Build only | How the first view fits bounds: the options of HoloMap.API.fit_bounds/3, such as padding and max_zoom. MapLibre fits it without animating |
center_clamped_to_ground | boolean | Applies | false stops MapLibre keeping the centre on the terrain, which a pitch past 90 degrees needs. Default true. See HoloMap.API.set_center_clamped_to_ground/2 |
zoom_snap | number | Applies | The camera's moves, and the glide that ends a zoom gesture, land on a zoom that is a multiple of it: 1 for whole levels. Default 0, any zoom |
anisotropic_filter_pitch | number | Applies | The pitch, from 0 to 180, above which raster layers are filtered anisotropically. Default 20 |
cancel_pending_tile_requests_while_zooming | boolean | Applies | false keeps loading the tiles of the zoom levels a zoom passes through, so detail appears gradually, at the cost of more requests. Default true |
rotate_speed / pitch_speed | number | Build only | Degrees a mouse drag turns or tilts the map per pixel. Default 0.8 and -0.5 |
roll_enabled | boolean | Build only | Let a right-button drag with Ctrl held roll the camera. Default false |
reduce_motion | boolean | Build only | true skips the animation of camera moves not marked :essential and the glide after a gesture; false keeps both whatever the user's system asks. MapLibre sets it for every map the page's copy of MapLibre draws. Left out, MapLibre follows prefers-reduced-motion |
click_tolerance | number | Build only | The pixels the pointer may move between press and release for it to count as a click. Default 3 |
max_canvas_size | {width, height} | Build only | The largest canvas MapLibre draws, in pixels. Default {4096, 4096} |
max_tile_cache_zoom_levels | integer | Build only | How many zoom levels of each source's tiles MapLibre keeps in its cache. Default 5 |
zoom_levels_to_overscale | integer | Build only | Past a source's maxzoom, how many zoom levels up to the map's max_zoom stretch its tiles rather than split them, which is cheaper at high zooms but moves labels centred on polygons. Default 4 |
terrain_skirt_length | "auto" or "none" | Build only | "none" leaves out the skirts along terrain tiles' edges, which can show as lines under a see-through background, at the cost of hairline gaps between tiles. Default "auto" |
cross_source_collisions | boolean | Build only | false lets labels of different sources overlap. Default true |
refresh_expired_tiles | boolean | Build only | false keeps tiles past the expiry their server gave them. Default true |
show_tile_boundaries / show_collision_boxes / show_overdraw_inspector / show_padding | boolean | Applies | MapLibre's rendering debug views. See Debug toggles |
maplibre_logo | boolean | Build only | Show MapLibre's logo. Default false. HoloMap.Control.Logo adds it as a component instead, which can change |
logo_position | string | Build only | The corner of maplibre_logo: "top-left", "top-right", "bottom-left" or "bottom-right". Default "bottom-left" |
options | map | Build only, but see above | Raw MapLibre constructor options, merged last. Keys must be MapLibre's own camelCase names: options={%{"maplibreLogo" => true}}. A typed prop is the better choice where there is one. A "canvasContextAttributes" map given here is merged with antialias, and its keys win |
worker_url | string | Build only | Where the application serves maplibre-gl-worker.mjs. Default "/assets/maplibre-gl-worker.mjs?v=<MapLibre version>". See The worker URL |
worker_count / max_parallel_image_requests | positive integer | Once per page | MapLibre's worker count and the most image requests it makes at a time. See Settings for the whole page |
trusted_types_policy | string | Once per page | The name of a Trusted Types policy for MapLibre. See Settings for the whole page |
prewarm | boolean | Once per page | Start MapLibre's workers early, and keep them between maps. See Settings for the whole page |
class | string | Applies | CSS classes for the wrapper element |
height / width | string | Applies | Inline size for the canvas. nil opts out and leaves sizing to CSS |
Event props
Each listens for the MapLibre event of the same name: on_dbl_click for
dblclick, on_source_data_loading for sourcedataloading.
| Group | Props |
|---|---|
| Lifecycle | on_load, on_idle, on_error, on_resize, on_webgl_context_lost, on_webgl_context_restored |
| Loading | on_data, on_data_loading, on_data_abort, on_source_data, on_source_data_loading, on_source_data_abort, on_style_data, on_style_image_missing |
| Pointer | on_click, on_dbl_click, on_context_menu, on_mouse_move, on_mouse_down, on_mouse_up, on_mouse_over, on_mouse_out, on_wheel, on_touch_start, on_touch_move, on_touch_end, on_touch_cancel, on_cooperative_gesture_prevented |
| Camera | on_move_start, on_move, on_move_end, on_zoom_start, on_zoom, on_zoom_end, on_rotate_start, on_rotate, on_rotate_end, on_pitch_start, on_pitch, on_pitch_end, on_roll_start, on_roll, on_roll_end, on_drag_start, on_drag, on_drag_end, on_box_zoom_start, on_box_zoom_end, on_box_zoom_cancel |
| Rendering | on_render, on_projection_transition, on_terrain |
MapLibre fires on_move, on_zoom, on_rotate, on_pitch, on_roll
and on_drag on every frame of a move, and on_render on every frame it
draws. Their handlers are throttled to 100 ms unless they name a
throttle or a debounce of their own; the last event of a move always
arrives (see "Throttling and debouncing" in HoloMap.Event).
Events
Handlers receive a payload with center, zoom, bearing, pitch and
bounds, plus:
lng_latandpointfor the mouse and touch events, where the pointer is, or the centre of the touches.errorforon_error: a map with themessage, plus thestatusandurlof a failed request and thesource_idof a source's error when MapLibre reports them. The one exception is a map MapLibre could not build, below.projectionforon_projection_transition.data_typefor the loading events,"source"or"style", and for a source's,source_id,is_source_loaded, whether the source has no request left outstanding, andsource_data_type:"metadata","content","visibility","idle", ornilfor a tile.idforon_style_image_missing: the image a layer asked for that neither the style's sprite nor aHoloMap.Imageholds, and that themissing_image_resolver, if any, did not add.gesture_typeforon_cooperative_gesture_prevented:"wheel_zoom"or"touch_pan".terrainforon_terrain:%{source: id, exaggeration: number}, ornilwhen terrain is taken away.def action(:map_moved, params, component) do put_state(component, :bounds, params.bounds) end
A loading state per source, from on_source_data_loading and
on_source_data:
def action(:source_loading, %{source_id: id}, component) do
put_state(component, :loading, Map.put(component.state.loading, id, true))
end
def action(:source_progress, %{source_id: id, is_source_loaded: true}, component) do
put_state(component, :loading, Map.delete(component.state.loading, id))
end
def action(:source_progress, _params, component), do: componentA camera move the runtime makes for a camera prop is not reported, by any
of the camera events. on_terrain reports every terrain MapLibre puts in
place, HoloMap.Terrain's included, as on_projection_transition reports
the projection prop's. See HoloMap.Event for the handler syntax and the
Events guide for the full payload reference.
A map MapLibre cannot build
MapLibre draws with WebGL2. On a browser or device that cannot create a
WebGL2 context, it cannot build the map at all, and the container stays
empty. on_error receives that failure once, with MapLibre's message,
"WebGL2 is required to display this map. ...", and its payload carries
error alone: there is no camera to read center, zoom, bearing,
pitch or bounds from. Camera limits MapLibre refuses when it builds the
map, such as a min_zoom above max_zoom, are reported the same way. A map
without on_error logs the error to the browser console.
The map is not built again while its container stays on the page, and the
other maps on the page are built as usual. HoloMap.API calls made for it
are dropped at once, with a console warning that names MapLibre's error,
the ones queued for its boot among them. Telling the failure apart from
the errors of a map that was built takes a match on the camera:
def action(:map_failed, %{center: _center} = params, component) do
put_state(component, :notice, "The map reported: " <> params.error.message)
end
def action(:map_failed, params, component) do
put_state(component, :notice, "This browser cannot show the map. " <> params.error.message)
end
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.