sky
StableMapLibre's sky above the horizon of a pitched map, with fog over 3D terrain and an atmosphere around a globe.
Set assigns
The sky is drawn above the horizon only: lower the pitch below about 69 degrees and it goes out of view. The fog shows over the terrain.
- @palette
- day
- @sky_color
- #199EF3
- @pitch
- 80
- @sky_horizon_blend
- 0.5
- @horizon_fog_blend
- 0.8
- @fog_ground_blend
- 0.5
- @enabled
- true
- @terrain
- false
- @status
- waiting
<div id="sky-example">
<.example_frame
error={@map_error}
error_id="example-sky-map-error"
hosts={["tiles.openfreemap.org", "tiles.mapterhorn.com"]}
>
<%!-- The sky shows above the horizon only: from a pitch of about 69
degrees on a flat map. max_pitch lets the camera tilt past
MapLibre's default of 60. --%>
<.map
id="example-sky-map"
center={[11.3909, 47.2757]}
zoom={11}
pitch={@pitch}
bearing={-20}
max_pitch={85}
style={basemap(@theme)}
events={["map:moved", "map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- A map has one sky. It comes back after a change of basemap, and goes
with the component. --%>
<.sky
:if={@enabled}
map_id="example-sky-map"
sky_color={@sky_color}
horizon_color={@horizon_color}
fog_color={@fog_color}
sky_horizon_blend={@sky_horizon_blend}
horizon_fog_blend={@horizon_fog_blend}
fog_ground_blend={@fog_ground_blend}
events={["sky:enabled", "sky:disabled"]}
/>
<%!-- The fog is drawn over 3D terrain only. --%>
<.raster_dem_source
:if={@terrain}
id="example-sky-dem"
map_id="example-sky-map"
url="https://tiles.mapterhorn.com/tilejson.json"
/>
<.terrain
:if={@terrain}
map_id="example-sky-map"
source_id="example-sky-dem"
exaggeration={1.5}
events={["terrain:error"]}
/>
<div class="space-y-3 border-t border-line px-4 py-4">
<%!-- Assigns: each control changes an assign; sky and map follow. --%>
<.example_group id="example-sky-assigns" label={gettext("Set assigns")}>
<.example_button
:for={{palette, colors} <- palettes()}
id={"example-sky-palette-#{palette}"}
pressed={@palette == palette}
phx-click="palette"
phx-value-palette={palette}
>
<.example_swatch color={colors.sky_color} />{palette}
</.example_button>
<.form
for={@options}
id="example-sky-options"
phx-change="options"
class="grid w-full gap-4 pt-2 sm:grid-cols-2 lg:grid-cols-4 lg:items-end"
>
<.example_range field={@options[:pitch]} label="pitch" min="0" max="85" />
<.example_range
field={@options[:sky_horizon_blend]}
label="sky_horizon_blend"
min="0"
max="1"
step="0.05"
/>
<.example_range
field={@options[:horizon_fog_blend]}
label="horizon_fog_blend"
min="0"
max="1"
step="0.05"
/>
<.example_range
field={@options[:fog_ground_blend]}
label="fog_ground_blend"
min="0"
max="1"
step="0.05"
/>
<.example_checkbox field={@options[:enabled]} label=":if" />
<.example_checkbox field={@options[:terrain]} label="<.terrain>" />
</.form>
</.example_group>
<.example_note id="example-sky-hint" icon="hero-information-circle-micro">
{gettext(
"The sky is drawn above the horizon only: lower the pitch below about 69 degrees and it goes out of view. The fog shows over the terrain."
)}
</.example_note>
</div>
<%!-- sky:enabled and sky:disabled keep status current. --%>
<.example_readout values={[
palette: @palette,
sky_color: @sky_color,
pitch: @pitch,
sky_horizon_blend: @sky_horizon_blend,
horizon_fog_blend: @horizon_fog_blend,
fog_ground_blend: @fog_ground_blend,
enabled: @enabled,
terrain: @terrain,
status: @status
]} />
</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 |
| sky_color | any |
nil
|
a color string, or an expression |
| horizon_color | any |
nil
|
a color string, or an expression |
| fog_color | any |
nil
|
a color string, or an expression |
| fog_ground_blend | any |
nil
|
a number from 0 to 1, or an expression |
| horizon_fog_blend | any |
nil
|
a number from 0 to 1, or an expression |
| sky_horizon_blend | any |
nil
|
a number from 0 to 1, or an expression |
| atmosphere_blend | any |
nil
|
a number from 0 to 1, or an expression |
| events | any |
[]
|
a list of event names, or :all
|