Attribution control component for MapLibre maps in Phoenix LiveView.
This component adds an attribution control that displays map attribution information in a customizable format.
Examples
Basic attribution control:
<.attribution_control
id="attribution-1"
map_id="my-map"
position="bottom-right"
/>With compact mode disabled:
<.attribution_control
id="attribution-1"
map_id="my-map"
position="bottom-left"
compact={false}
/>With custom attribution:
<.attribution_control
id="attribution-1"
map_id="my-map"
position="bottom-right"
custom_attribution="© My Company 2024 | Custom Data Provider"
/>One attribution control per map
<.map> shows MapLibre's attribution control of its own unless its
attribution_control is false. This component takes its place for as
long as it is on the page, so the map shows one attribution control,
whichever of the two is rendered first; the map's own comes back when the
component goes, if the map's attribution_control is still true. There
is no need to pass attribution_control={false} to the map. Of two
attribution_control components on one map, the one mounted first is
shown, and the other once it goes (the browser console says so).
Notes
- The attribution control automatically displays attribution from the map style and sources
- Custom attribution can be added to supplement the automatic attribution
- In compact mode, the attribution is collapsed to an info icon that expands on hover/click
- This is a display-only control with no user events
Position
The control can be positioned in any corner of the map:
"top-left""top-right""bottom-left""bottom-right"(default)
Summary
Functions
Renders an attribution control component.
Functions
Renders an attribution control component.
Attributes
After mount, the control follows a change to any of these attributes
except id and map_id, which are read when it mounts only; each entry
says what a change does.
id(required) - Unique identifier for the controlmap_id(required) - ID of the map to attach toposition- Position of the control. One of:["top-left", "top-right", "bottom-left", "bottom-right"]. Defaults to"bottom-right". A new value moves the control to that cornercompact- If true, displays attribution in compact mode (collapsed). Defaults totrue. MapLibre reads it only when it creates the control, so a new value replaces the control with a new one, in the same placecustom_attribution- Additional custom attribution text to display (optional). A new value replaces the control, ascompactdoes
The control appears once its map is on the page, whether the map is rendered before or after it, and comes back on a map rendered again with the same id. Several controls in one corner are stacked in the order they come in the template, the first nearest the corner, also after one of them changes or moves. A map style change leaves the control alone.
Attributes
id(:string) (required)map_id(:string) (required)position(:string) - Defaults to"bottom-right". Must be one of"top-left","top-right","bottom-left", or"bottom-right".compact(:boolean) - Defaults totrue.custom_attribution(:string) - Defaults tonil.