Skip to content

map

Stable

A MapLibre GL JS map whose center, zoom, pitch, bearing and style follow the LiveView's assigns.

Generated from the component's definition in the library, so it always matches the version this demo runs.

Attribute Type Default Description
id required string — Unique identifier for the map
center list nil Map center coordinates as [longitude, latitude]. Without it, or with nil, the map opens at the configured default_center, [0, 0] unless configured (see MaplibreX). A new value after mount moves the map there at once, at the zoom it has, also on a globe (see "Projection"); nil after mount leaves the map where it is. A centre the map itself has just reported in map:moved, rendered back by the LiveView, is not applied to it again
zoom any nil number
style any nil Map style URL or style object. Without it, or with nil, the configured default_style. A new value after mount replaces the style; the layers, sources and terrain of the map's components come back on the new style, and changes to them that arrive while it loads (in the same update, say) are applied once it is in place
min_zoom any nil number
max_zoom any nil number
min_pitch any nil number, degrees
max_pitch any nil number, degrees, up to 180
bearing any 0 number, degrees
pitch any 0 number, degrees
bounds list nil Fit map to bounds [[west, south], [east, north]]. Optional. The map opens on them, whatever center and zoom say. New bounds after mount fit the map to them at once, with no animation and no padding, as when it opens, and win over a center or zoom changed in the same render; no longer giving them leaves the map where it is. For an animated fit, use fit_bounds/3
max_bounds list nil Maximum bounds the map can be panned to. Optional. A new value after mount applies at once; no longer giving it lifts the limit
interactive boolean true Whether the user can move the map with the mouse, touch and the keyboard. Defaults to true. After mount, false turns off every one of MapLibre's interaction handlers and true turns them all on again, also on a map created with false. The JS and server-pushed commands move the map either way
attribution_control boolean true Show MapLibre's attribution control, in the bottom-right corner. Defaults to true. After mount, false removes it and true adds it back. An <.attribution_control> (MaplibreX.Components.AttributionControl) on the map takes its place while it is there, so that the map shows one attribution control
fly any nil true, or a map of :from, :duration or :speed, and :curve; read at mount only
projection any nil a projection name, such as "globe" or :globe, or MapLibre's projection specification as a map
curtain any nil true, or a map of :timeout and :label; read at mount only
follow any nil the id of a marker on the map, or {layer_id, feature_id} for a feature of a <.geojson_layer>, which the camera keeps at the centre; nil or false for none
debug boolean false log MaplibreX's lifecycle messages in the browser console, for the whole page
class string "maplibrex-map" CSS classes for the map container. Read when the map mounts only: LiveView does not patch the attributes of the map element, which is phx-update="ignore", except its data-* ones. Put classes that change on a wrapper element
testid string nil Test ID for the map element (data-testid), patched like any data-* attribute
global attributes global — Any other HTML attribute, passed on to the component's element.
events any [] a list of event names, or :all

Slots

  • inner_block Optional.
  • loader replaces the curtain's built-in loader; ignored without `curtain`