Fill extrusion layer component for MapLibre maps in Phoenix LiveView.
This component renders 3D extruded polygons, commonly used for buildings and data visualizations with height/elevation dimensions.
Examples
Basic 3D buildings:
<.fill_extrusion_layer
id="buildings-3d"
map_id="my-map"
source_id="buildings"
paint={%{
"fill-extrusion-color" => "#aaa",
"fill-extrusion-height" => ["get", "height"],
"fill-extrusion-base" => 0,
"fill-extrusion-opacity" => 0.6
}}
/>Buildings with base height and vertical gradient:
<.fill_extrusion_layer
id="buildings-gradient"
map_id="my-map"
source_id="buildings"
paint={%{
"fill-extrusion-color" => [
"interpolate",
["linear"],
["get", "height"],
0, "#fbb03b",
50, "#223b53",
100, "#e55e5e"
],
"fill-extrusion-height" => ["get", "height"],
"fill-extrusion-base" => ["get", "min_height"],
"fill-extrusion-opacity" => 0.9,
"fill-extrusion-vertical-gradient" => true
}}
filter={["==", "extrude", "true"]}
/>Data visualization with extrusion:
<.fill_extrusion_layer
id="population-3d"
map_id="my-map"
source_id="counties"
paint={%{
"fill-extrusion-color" => "#00f",
"fill-extrusion-height" => [
"*",
["get", "population"],
0.001
],
"fill-extrusion-base" => 0,
"fill-extrusion-opacity" => 0.7
}}
/>Events
The fill extrusion layer can emit the following events to LiveView:
def handle_event("layer:feature_clicked", %{"layer_id" => layer_id, "features" => features}, socket) do
IO.inspect(features, label: "Clicked buildings")
{:noreply, socket}
end
def handle_event("layer:feature_mouseenter", %{"layer_id" => layer_id, "features" => features}, socket) do
IO.inspect(features, label: "Hovering over building")
{:noreply, socket}
end
def handle_event("layer:added", %{"layer_id" => layer_id}, socket) do
IO.inspect(layer_id, label: "3D layer added")
{:noreply, socket}
end
Summary
Functions
Renders a fill extrusion layer component.
Functions
Renders a fill extrusion 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-extrusion-color, fill-extrusion-height, 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
Paint Properties
fill-extrusion-color- Color of the extruded polygonsfill-extrusion-height- Height of the extrusion (meters or expression)fill-extrusion-base- Base height of the extrusion (default: 0)fill-extrusion-opacity- Opacity of the extrusion (0-1)fill-extrusion-pattern- Name of image in sprite for pattern fillfill-extrusion-translate- Offset distance [x, y] in pixelsfill-extrusion-translate-anchor- "map" or "viewport"fill-extrusion-vertical-gradient- Apply vertical color gradient (default: true)
All paint properties support data-driven styling and interpolation expressions.
Layout Properties
visibility- "visible" or "none" (default: "visible")
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.