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>
Generated from the component's definition in the library, so it always matches the version this demo runs.
| Attribute | Type | Default | Description |
|---|---|---|---|
| id required | string | — | Unique identifier for the source |
| map_id required | string | — | ID of the map to attach to |
| url | string |
nil
|
TileJSON URL, or a pmtiles:// URL (see "PMTiles" in the module documentation) (either url or tiles must be provided)
|
| tiles | list |
nil
|
List of tile URL templates (e.g., ["https://a.tile.com/{z}/{x}/{y}.pbf"]) |
| min_zoom | integer |
nil
|
Minimum zoom level (default: 0) |
| max_zoom | integer |
nil
|
Maximum zoom level (default: 22) |
| attribution | string |
nil
|
Attribution text |
| bounds | list |
nil
|
Geographic bounds [west, south, east, north] |
| scheme | string |
nil
|
Tile scheme: "xyz" (default) or "tms" |
| promote_id | any |
nil
|
a property name, or a map of source layer => property |
| volatile | boolean |
false
|
Whether data should be cached (default: false) |
| events | any |
[]
|
a list of event names, or :all
|