terrain
StableRenders 3D terrain from a raster DEM source, with adjustable exaggeration.
Set assigns
- @exaggeration
- 1.5
- @pitch
- 70
- @enabled
- true
- @status
- waiting
- @control
- false
- @control_enabled
- true
<div id="terrain-example">
<.example_frame
error={@map_error}
error_id="example-terrain-map-error"
hosts={["tiles.openfreemap.org", "tiles.mapterhorn.com"]}
>
<%!-- max_pitch lets the camera tilt past MapLibre's default of 60. --%>
<.map
id="example-terrain-map"
center={[11.3909, 47.2757]}
zoom={12}
pitch={@pitch}
bearing={-20}
max_pitch={85}
style={basemap(@theme)}
events={["map:moved", "map:error"]}
class="h-full w-full"
/>
</.example_frame>
<.raster_dem_source
id="example-terrain-dem"
map_id="example-terrain-map"
url="https://tiles.mapterhorn.com/tilejson.json"
/>
<.terrain
:if={@enabled}
map_id="example-terrain-map"
source_id="example-terrain-dem"
exaggeration={@exaggeration}
events={["terrain:enabled", "terrain:disabled", "terrain:error"]}
/>
<%!-- A button that switches the terrain on and off. While it is on the
map it decides the terrain, and <.terrain> stands by; its terrain
comes back when the control goes. --%>
<.terrain_control
:if={@control}
id="example-terrain-control"
map_id="example-terrain-map"
terrain_source_id="example-terrain-dem"
exaggeration={@exaggeration}
enabled={@control_enabled}
events={["terrain_control:toggled", "terrain_control:error"]}
/>
<div class="border-t border-line px-4 py-4">
<%!-- Assigns: each control changes an assign; terrain and map follow. --%>
<.example_group id="example-terrain-assigns" label={gettext("Set assigns")}>
<.form
for={@options}
id="example-terrain-options"
phx-change="options"
class="grid w-full gap-4 sm:grid-cols-[1fr_1fr_auto_auto] sm:items-end"
>
<.example_range
field={@options[:exaggeration]}
label="exaggeration"
min="0.5"
max="3"
step="0.1"
/>
<.example_range field={@options[:pitch]} label="pitch" min="0" max="85" />
<.example_checkbox field={@options[:enabled]} label=":if" />
<.example_checkbox field={@options[:control]} label="<.terrain_control>" />
</.form>
</.example_group>
</div>
<%!-- terrain:enabled and terrain:disabled keep status current, and
terrain_control:toggled keeps control_enabled. --%>
<.example_readout values={[
exaggeration: @exaggeration,
pitch: @pitch,
enabled: @enabled,
status: @status,
control: @control,
control_enabled: @control_enabled
]} />
</div>
The events this component sends to the LiveView, as the library documents them. Each arrives in handle_event/3. Use the preview; the last payload of each event the example receives appears here. A component sends only the events its events attribute names, so the example receives those its LiveView handles.
-
terrain:enabled
Fired once, the first time the terrain is on, with
source_idandexaggeration. Not fired again when a style change or a new assign turns it on againNot received yet.
-
terrain:disabled
Fired when the component is removed and turns the terrain off. A terrain that is no longer the component's own (another one was set since) is left on, and the event is not fired
Not received yet.
-
terrain:error
Fired, with
error, when MapLibre fails to enable the terrain. A source that is not on the map yet is not an errorNot received yet.