Fill layer component for MapLibre maps in Phoenix LiveView.
This component renders polygon data as filled areas with customizable styling for regions, zones, and administrative boundaries.
Examples
Basic fill layer:
<.fill_layer
id="states"
map_id="my-map"
source_id="state-data"
paint={%{
"fill-color" => "#088",
"fill-opacity" => 0.4
}}
/>Data-driven styling with outline:
<.fill_layer
id="countries"
map_id="my-map"
source_id="country-data"
paint={%{
"fill-color" => [
"match",
["get", "continent"],
"North America", "#1f78b4",
"Europe", "#33a02c",
"Asia", "#e31a1c",
"Africa", "#ff7f00",
"#808080"
],
"fill-opacity" => 0.6,
"fill-outline-color" => "#000"
}}
/>With filters and pattern:
<.fill_layer
id="parks"
map_id="my-map"
source_id="land-use"
source_layer="parks"
filter={["==", "type", "park"]}
paint={%{
"fill-color" => "#00ff00",
"fill-opacity" => 0.3,
"fill-outline-color" => "#006600"
}}
min_zoom={10}
max_zoom={22}
/>Events
The fill 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 region")
{:noreply, socket}
end
def handle_event("layer:feature_mouseenter", %{"layer_id" => id, "feature" => feature}, socket) do
# Highlight region, show info, etc.
{:noreply, socket}
end
def handle_event("layer:feature_mouseleave", %{"layer_id" => id}, socket) do
# Reset highlight
{:noreply, socket}
end
Summary
Functions
Renders a fill layer component.
Functions
Renders a fill 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 (fill-color, fill-opacity, fill-outline-color, fill-pattern, etc.)layout- Layout properties (visibility, 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
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.