fill_layer
StableFills polygons from a source.
Set assigns
Amsterdam's water from OpenStreetMap, in OpenFreeMap's tiles. Click the water.
- @color
- #0f8b8d
- @opacity
- 0.6
- @outline
- true
- @selected
- —
<div id="fill-layer-example">
<.example_frame error={@map_error} error_id="example-fill-map-error">
<.map
id="example-fill-map"
center={[4.8952, 52.3702]}
zoom={13}
style={basemap(@theme)}
events={["map:error"]}
class="h-full w-full"
/>
</.example_frame>
<%!-- OpenFreeMap's TileJSON: OpenStreetMap in the OpenMapTiles schema. --%>
<.vector_tile_source
id="example-fill-osm"
map_id="example-fill-map"
url="https://tiles.openfreemap.org/planet"
events={["source:error"]}
/>
<.fill_layer
id="example-fill-water"
map_id="example-fill-map"
source_id="example-fill-osm"
source_layer="water"
paint={paint(@color, @opacity, @outline, @theme)}
events={["layer:feature_clicked"]}
/>
<div class="space-y-3 border-t border-line px-4 py-4">
<.example_group id="example-fill-assigns" label={gettext("Set assigns")}>
<.example_button
:for={{name, hex} <- colors()}
id={"example-fill-color-#{name}"}
code
pressed={@color == hex}
phx-click="color"
phx-value-color={hex}
>
<.example_swatch color={hex} />{hex}
</.example_button>
<.form
for={@options}
id="example-fill-options"
phx-change="options"
class="grid w-full gap-4 pt-2 sm:max-w-lg sm:grid-cols-[1fr_auto] sm:items-end"
>
<.example_range
field={@options[:opacity]}
label="fill-opacity"
min="0.1"
max="1"
step="0.05"
/>
<.example_checkbox field={@options[:outline]} label="fill-outline-color" />
</.form>
</.example_group>
<.example_note id="example-fill-data" icon="hero-cursor-arrow-rays-micro">
{gettext("Amsterdam's water from OpenStreetMap, in OpenFreeMap's tiles. Click the water.")}
</.example_note>
</div>
<%!-- layer:feature_clicked sets selected. --%>
<.example_readout values={[
color: @color,
opacity: @opacity,
outline: @outline,
selected: @selected || "—"
]} />
</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 layer |
| map_id required | string | — | ID of the map to attach to |
| source_id required | string | — | ID of the data source |
| source_layer | string |
nil
|
Layer name in the source (for vector tiles) |
| paint | map |
%{}
|
Paint properties (fill-color, fill-opacity, fill-outline-color, fill-pattern, etc.) |
| layout | map |
%{}
|
Layout properties (visibility, etc.) |
| filter | any |
nil
|
Filter expression to show subset of features |
| min_zoom | integer |
nil
|
Minimum zoom level for layer visibility |
| max_zoom | integer |
nil
|
Maximum zoom level for layer visibility |
| before_id | string |
nil
|
ID of layer to insert this layer before |
| events | any |
[]
|
a list of event names, or :all
|
| cursor | string |
nil
|
a CSS cursor to show over the features, such as "pointer"
|
| hit_width | any |
nil
|
a number of pixels: the layer answers the pointer within that many pixels of what it draws |
| hover | boolean |
false
|
whether the feature under the pointer has the feature state hover, set in the browser
|
| feature_state | map |
nil
|
a map of feature id => map of state, which paint properties read with feature-state
|