Saltar al contenido

control_button

Estable

Un botón de control del mapa con un icono o contenido propio, y un estado activo.

Pulsa el botón de la esquina superior izquierda del mapa: cada pulsación llega a handle_event/3, que inclina o aplana el mapa.

@tilted
false
@pitch
0
@presses
0
lib/maplibrex_demo_web/examples/control_button_example.html.heex
<div id="control-button-example">
  <.example_frame error={@map_error} error_id="example-control-button-map-error">
    <.map
      id="example-control-button-map"
      center={[2.1734, 41.3851]}
      zoom={15}
      pitch={@pitch}
      bearing={-20}
      style={basemap(@theme)}
      events={["map:moved", "map:error"]}
      class="h-full w-full"
    />
  </.example_frame>

  <%!-- phx-click is passed on to the button on the map; active tints it,
        in the colour this app gives --maplibrex-control-active-background. --%>
  <.control_button
    id="example-control-button-tilt"
    map_id="example-control-button-map"
    position="top-left"
    tooltip={tooltip(@tilted)}
    active={@tilted}
    class="grid! place-items-center"
    phx-click="tilt"
  >
    <.icon name="hero-cube-transparent" class="size-5" />
  </.control_button>

  <div class="border-t border-line px-4 py-4">
    <.example_note id="example-control-button-hint" icon="hero-cursor-arrow-rays-micro">
      {gettext(
        "Press the button in the map's top-left corner: each press reaches handle_event/3, which tilts or flattens the map."
      )}
    </.example_note>
  </div>

  <%!-- map:moved keeps pitch current when the map is tilted by hand. --%>
  <.example_readout values={[tilted: @tilted, pitch: @pitch, presses: @presses]} />
</div>