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>
Generated from the component's definition in the library, so it always matches the version this demo runs.
| Attribute | Type | Default | Description |
|---|---|---|---|
| map_id required | string | — | ID of the map to enable terrain on |
| source_id required | string | — | ID of the RasterDEMSource to use for terrain data |
| exaggeration | float |
1.0
|
Vertical exaggeration factor (default: 1.0) |
| events | any |
[]
|
a list of event names, or :all
|