navigation_control
StableZoom buttons and a compass.
<div id="navigation-control-example">
<.example_frame error={@map_error} error_id="example-navigation-map-error">
<.map
id="example-navigation-map"
center={[-43.2096, -22.9535]}
zoom={11}
pitch={45}
bearing={-30}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- The control follows its assigns: a new position moves it, a new
option replaces it in the same place. Controls in one corner stand
in template order, so it stays above the full-screen button. --%>
<.navigation_control
id="example-navigation"
map_id="example-navigation-map"
position={@position}
show_compass={@show_compass}
show_zoom={@show_zoom}
visualize_pitch={@visualize_pitch}
/>
<.fullscreen_control id="example-navigation-fullscreen" map_id="example-navigation-map" />
<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-navigation-positions" label="position" code>
<.example_button
:for={position <- positions()}
id={"example-navigation-position-#{position}"}
code
pressed={@position == position}
phx-click="position"
phx-value-position={position}
>
{position}
</.example_button>
</.example_group>
<.example_group id="example-navigation-assigns" label={gettext("Set assigns")}>
<.form
for={@options}
id="example-navigation-options"
phx-change="options"
class="flex flex-wrap gap-x-6 gap-y-2 py-1.5"
>
<.example_checkbox field={@options[:show_compass]} label="show_compass" />
<.example_checkbox field={@options[:show_zoom]} label="show_zoom" />
<.example_checkbox field={@options[:visualize_pitch]} label="visualize_pitch" />
</.form>
</.example_group>
</div>
<.example_readout values={[
position: @position,
show_compass: @show_compass,
show_zoom: @show_zoom,
visualize_pitch: @visualize_pitch
]} />
</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 add the control to |
| position | string |
"top-right"
|
Control position: "top-left", "top-right", "bottom-left", "bottom-right". Defaults to "top-right". A new value moves the control to that corner
|
| show_compass | boolean |
true
|
Show compass button for rotation. Defaults to true. MapLibre builds the buttons when it creates the control, so a new value replaces the control with a new one, in the same place
|
| show_zoom | boolean |
true
|
Show zoom buttons (+/-). Defaults to true. A new value replaces the control, as show_compass does
|
| visualize_pitch | boolean |
false
|
Show pitch visualization in compass. Defaults to false. A new value replaces the control, as show_compass does
|
| global attributes | global | — | Any other HTML attribute, passed on to the component's element. |