Symbol layer component for MapLibre maps in Phoenix LiveView.
This component renders point data as symbols (icons and/or text labels) with customizable styling for POI labels, place names, and custom markers.
Examples
Basic text labels:
<.symbol_layer
id="city-labels"
map_id="my-map"
source_id="places"
layout={%{
"text-field" => ["get", "name"],
"text-size" => 12
}}
/>Icons with text:
<.symbol_layer
id="poi-labels"
map_id="my-map"
source_id="points-of-interest"
layout={%{
"text-field" => ["get", "name"],
"text-font" => ["Open Sans Regular"],
"text-size" => 12,
"text-anchor" => "top",
"text-offset" => [0, 0.5],
"icon-image" => ["get", "icon"],
"icon-size" => 1.0,
"icon-allow-overlap" => false,
"text-allow-overlap" => false
}}
paint={%{
"text-color" => "#000",
"text-halo-color" => "#fff",
"text-halo-width" => 2,
"icon-opacity" => 1
}}
/>Data-driven styling:
<.symbol_layer
id="markers"
map_id="my-map"
source_id="locations"
layout={%{
"icon-image" => [
"match",
["get", "type"],
"restaurant", "restaurant-15",
"hotel", "lodging-15",
"shop", "shop-15",
"marker-15"
],
"icon-size" => [
"interpolate",
["linear"],
["zoom"],
10, 0.5,
15, 1.5
],
"text-field" => ["get", "name"],
"text-size" => 11,
"text-anchor" => "top",
"text-offset" => [0, 1.2]
}}
paint={%{
"text-color" => "#333",
"text-halo-color" => "#fff",
"text-halo-width" => 1.5
}}
min_zoom={10}
/>Events
The symbol layer can emit the following events to LiveView:
def handle_event("layer:feature_clicked", %{"layer_id" => id, "feature" => feature}, socket) do
IO.inspect(feature, label: "Clicked symbol")
{:noreply, socket}
end
def handle_event("layer:feature_mouseenter", %{"layer_id" => id, "feature" => feature}, socket) do
# Show tooltip, highlight symbol, etc.
{:noreply, socket}
end
def handle_event("layer:feature_mouseleave", %{"layer_id" => id}, socket) do
# Hide tooltip, reset highlight
{:noreply, socket}
end
Summary
Functions
Renders a symbol layer component.
Functions
Renders a symbol layer component.
Attributes
id(required) - Unique identifier for the layermap_id(required) - ID of the map to attach tosource_id(required) - ID of the data sourcesource_layer- Layer name in the source (for vector tiles)paint- Paint properties (text-color, text-halo-color, icon-opacity, etc.)layout- Layout properties (text-field, text-font, icon-image, etc.)filter- Filter expression to show subset of featuresmin_zoom- Minimum zoom level for layer visibilitymax_zoom- Maximum zoom level for layer visibilitybefore_id- ID of layer to insert this layer before
Paint Properties
Text paint properties:
text-color- Color of the texttext-halo-color- Color of the text's halotext-halo-width- Width of the text's halotext-halo-blur- Blur of the text's halotext-opacity- Opacity of the text
Icon paint properties:
icon-color- Color of the iconicon-halo-color- Color of the icon's haloicon-halo-width- Width of the icon's haloicon-halo-blur- Blur of the icon's haloicon-opacity- Opacity of the icon
Layout Properties
Text layout properties:
text-field- Value to use for text contenttext-font- Font stack to use for displaying texttext-size- Font size in pixelstext-anchor- Part of the text placed closest to the anchortext-offset- Offset distance of text from its anchortext-allow-overlap- If true, the text will be visible even if it collidestext-ignore-placement- If true, other symbols can be visible even if they collide with the text
Icon layout properties:
icon-image- Name of image in sprite to use for drawing an image backgroundicon-size- Scale factor for the iconicon-offset- Offset distance of icon from its anchoricon-anchor- Part of the icon placed closest to the anchoricon-allow-overlap- If true, the icon will be visible even if it collidesicon-ignore-placement- If true, other symbols can be visible even if they collide with the icon
Events
layer:feature_clicked- Fired when a feature is clickedlayer:feature_mouseenter- Fired when mouse enters a featurelayer:feature_mouseleave- Fired when mouse leaves a featurelayer:added- Fired when layer is added to maplayer:removed- Fired when layer is removed from map
Attributes
id(:string) (required)map_id(:string) (required)source_id(:string) (required)source_layer(:string) - Defaults tonil.paint(:map) - Defaults to%{}.layout(:map) - Defaults to%{}.filter(:any) - Defaults tonil.min_zoom(:integer) - Defaults tonil.max_zoom(:integer) - Defaults tonil.before_id(:string) - Defaults tonil.