MaplibreX.Components.FillLayer (MaplibreX v0.1.0)

Copy Markdown View Source

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

fill_layer(assigns)

Renders a fill layer component.

Attributes

  • id (required) - Unique identifier for the layer
  • map_id (required) - ID of the map to attach to
  • source_id (required) - ID of the data source
  • source_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 features
  • min_zoom - Minimum zoom level for layer visibility
  • max_zoom - Maximum zoom level for layer visibility
  • before_id - ID of layer to insert this layer before

Events

  • layer:feature_clicked - Fired when a feature is clicked
  • layer:feature_mouseenter - Fired when mouse enters a feature
  • layer:feature_mouseleave - Fired when mouse leaves a feature
  • layer:added - Fired when layer is added to map
  • layer:removed - Fired when layer is removed from map

Attributes

  • id (:string) (required)
  • map_id (:string) (required)
  • source_id (:string) (required)
  • source_layer (:string) - Defaults to nil.
  • paint (:map) - Defaults to %{}.
  • layout (:map) - Defaults to %{}.
  • filter (:any) - Defaults to nil.
  • min_zoom (:integer) - Defaults to nil.
  • max_zoom (:integer) - Defaults to nil.
  • before_id (:string) - Defaults to nil.