Saltar al contenido

sky

Estable

El cielo de MapLibre sobre el horizonte de un mapa inclinado, con niebla sobre el terreno 3D y una atmósfera alrededor de un globo.

Cambiar assigns

El cielo se dibuja solo sobre el horizonte: baja la inclinación por debajo de unos 69 grados y deja de verse. La niebla se ve sobre el terreno.

@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
lib/maplibrex_demo_web/examples/sky_example.html.heex
<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>