vector_tile_source
StableAdds vector tiles, from a TileJSON URL or a tile template, for layers to draw.
Set assigns
:if
- @continent
- Europe
- @enabled
- true
- @status
- waiting
- @data_events
- 0
<div id="vector-tile-source-example">
<.example_frame
error={@map_error}
error_id="example-vector-map-error"
hosts={["tiles.openfreemap.org", "demotiles.maplibre.org"]}
>
<.map
id="example-vector-map"
center={[15, 25]}
zoom={1.3}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- MapLibre's demo tiles: Natural Earth countries in a "countries" source
layer, up to zoom 6. A tile template, so the attribution given here
is the one shown. A source draws nothing itself: the layers below
name it with source_id and pick the source layer to draw. --%>
<.vector_tile_source
:if={@enabled}
id="example-vector-countries"
map_id="example-vector-map"
tiles={["https://demotiles.maplibre.org/tiles/{z}/{x}/{y}.pbf"]}
max_zoom={6}
attribution="Natural Earth, MapLibre demo tiles"
events={["source:added", "source:data", "source:removed", "source:error"]}
/>
<.fill_layer
:if={@enabled}
id="example-vector-fill"
map_id="example-vector-map"
source_id="example-vector-countries"
source_layer="countries"
paint={fill_paint(@continent)}
/>
<.line_layer
:if={@enabled}
id="example-vector-borders"
map_id="example-vector-map"
source_id="example-vector-countries"
source_layer="countries"
paint={%{"line-color" => "#7c5cd6", "line-width" => 0.6, "line-opacity" => 0.6}}
/>
<div class="grid gap-x-8 gap-y-4 border-t border-line px-4 py-4 lg:grid-cols-[1fr_auto]">
<.example_group id="example-vector-continents" label={gettext("Set assigns")}>
<.example_button
:for={continent <- continents()}
id={"example-vector-continent-#{slug(continent)}"}
pressed={@continent == continent}
phx-click="continent"
phx-value-continent={slug(continent)}
>
{continent_name(continent)}
</.example_button>
</.example_group>
<.example_group id="example-vector-toggle" label=":if" code>
<.form for={@options} id="example-vector-options" phx-change="options" class="py-1.5">
<.example_checkbox field={@options[:enabled]} label="enabled" />
</.form>
</.example_group>
</div>
<%!-- source:added, source:data and source:removed keep status current. --%>
<.example_readout values={[
continent: @continent,
enabled: @enabled,
status: @status,
data_events: @data_events
]} />
</div>
The events this component sends to the LiveView, as the library documents them. Each arrives in handle_event/3. Use the preview; the last payload of each event the example receives appears here. A component sends only the events its events attribute names, so the example receives those its LiveView handles.
-
source:added
Fired once, with
source_id, the first time the source is on the map (not again when a style change, or a map rendered again with the same id, puts it back)Not received yet.
-
source:removed
Fired, with
source_id, once the source is gone after the component is removed, ifsource:addedwas firedNot received yet.
-
source:data
Fired for each of MapLibre's
sourcedataloadingandsourcedataevents about this source: its data is loading, or has loaded or changedNot received yet.
-
source:error
Fired when MapLibre reports an error loading the source or one of its tiles, or fails to add or replace the source
Not received yet.