attribution_control
StableShows the attribution of the map's sources.
position
Set assigns
- @enabled
- true
- @position
- bottom-right
- @compact
- false
- @custom_attribution
- nil
- @map_attribution
- true
<div id="attribution-control-example">
<.example_frame error={@map_error} error_id="example-attribution-map-error">
<.map
id="example-attribution-map"
center={[2.3522, 48.8566]}
zoom={12}
attribution_control={@map_attribution}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- While it is on the page, the component takes the place of the map's
own attribution, so the map shows one. A new position moves it; a new
compact or custom_attribution replaces it in the same place. --%>
<.attribution_control
:if={@enabled}
id="example-attribution"
map_id="example-attribution-map"
position={@position}
compact={@compact}
custom_attribution={custom_attribution(@custom)}
/>
<div class="grid gap-x-8 gap-y-4 border-t border-line px-4 py-4 lg:grid-cols-[auto_1fr]">
<.example_group id="example-attribution-positions" label="position" code>
<.example_button
:for={position <- positions()}
id={"example-attribution-position-#{position}"}
code
pressed={@position == position}
phx-click="position"
phx-value-position={position}
>
{position}
</.example_button>
</.example_group>
<.example_group id="example-attribution-assigns" label={gettext("Set assigns")}>
<.form
for={@options}
id="example-attribution-options"
phx-change="options"
class="flex flex-wrap gap-x-6 gap-y-2 py-1.5"
>
<.example_checkbox field={@options[:enabled]} label=":if" />
<.example_checkbox field={@options[:compact]} label="compact" />
<.example_checkbox field={@options[:custom]} label="custom_attribution" />
<.example_checkbox field={@options[:map]} label="<.map attribution_control>" />
</.form>
</.example_group>
</div>
<.example_readout values={[
enabled: @enabled,
position: @position,
compact: @compact,
custom_attribution: custom_attribution(@custom) || "nil",
map_attribution: @map_attribution
]} />
</div>
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 control |
| map_id required | string | — | ID of the map to attach to |
| position | string |
"bottom-right"
|
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 corner
|
| compact | boolean |
true
|
If true, displays attribution in compact mode (collapsed). Defaults to true. MapLibre reads it only when it creates the control, so a new value replaces the control with a new one, in the same place
|
| custom_attribution | string |
nil
|
Additional custom attribution text to display (optional). A new value replaces the control, as compact does
|