circle_layer
EstableDibuja los puntos de una fuente como círculos.
Cambiar assigns
feature_state
Un punto por país, de las teselas de demostración de MapLibre. Haz clic en uno para seleccionarlo: su estado de elemento (feature state) lo rodea con un anillo. El punto bajo el puntero se ilumina.
- @color
- #7c5cd6
- @radius
- 6
- @selected
- —
<div id="circle-layer-example">
<.example_frame
error={@map_error}
error_id="example-circle-map-error"
hosts={["tiles.openfreemap.org", "demotiles.maplibre.org"]}
>
<.map
id="example-circle-map"
center={[15, 25]}
zoom={1.3}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- MapLibre's demo tiles: a point per country in the "centroids" layer.
promote_id: each point's id is its NAME, which feature state finds
it by. --%>
<.vector_tile_source
id="example-circle-countries"
map_id="example-circle-map"
tiles={["https://demotiles.maplibre.org/tiles/{z}/{x}/{y}.pbf"]}
max_zoom={6}
attribution="Natural Earth, MapLibre demo tiles"
promote_id="NAME"
events={["source:error"]}
/>
<%!-- feature_state: the selected country's point has selected: true, and
hover lights the point under the pointer, in the browser. The ring's
paint reads both with ["feature-state", ...]. --%>
<.circle_layer
id="example-circle-layer"
map_id="example-circle-map"
source_id="example-circle-countries"
source_layer="centroids"
paint={paint(@color, @radius, @theme)}
feature_state={selection(@selected)}
hover
events={["layer:feature_clicked"]}
/>
<div class="space-y-3 border-t border-line px-4 py-4">
<.example_group id="example-circle-assigns" label={gettext("Set assigns")}>
<.example_button
:for={{name, hex} <- colors()}
id={"example-circle-color-#{name}"}
code
pressed={@color == hex}
phx-click="color"
phx-value-color={hex}
>
<.example_swatch color={hex} />{hex}
</.example_button>
<.form
for={@options}
id="example-circle-options"
phx-change="options"
class="w-full pt-2 sm:max-w-xs"
>
<.example_range field={@options[:radius]} label="circle-radius" min="2" max="14" />
</.form>
</.example_group>
<.example_group id="example-circle-selection" label="feature_state" code>
<.example_button id="example-circle-clear" phx-click="clear" disabled={!@selected}>
{gettext("Clear the selection")}
</.example_button>
</.example_group>
<.example_note id="example-circle-data" icon="hero-cursor-arrow-rays-micro">
{gettext(
"A point per country, from MapLibre's demo tiles. Click one to select it: its feature state rings it. The point under the pointer is lit."
)}
</.example_note>
</div>
<%!-- layer:feature_clicked sets selected. --%>
<.example_readout values={[color: @color, radius: @radius, selected: @selected || "—"]} />
</div>