heatmap_layer
StableShows the density of points from a source as a heatmap.
Points of interest in central Paris from OpenStreetMap, in OpenFreeMap's tiles: shops, cafés, museums and the like.
- @radius
- 10
- @intensity
- 0.3
- @on_map
- false
<div id="heatmap-layer-example">
<.example_frame error={@map_error} error_id="example-heatmap-map-error">
<.map
id="example-heatmap-map"
center={[2.3488, 48.8606]}
zoom={14}
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-heatmap-osm"
map_id="example-heatmap-map"
url="https://tiles.openfreemap.org/planet"
events={["source:error"]}
/>
<.heatmap_layer
id="example-heatmap-layer"
map_id="example-heatmap-map"
source_id="example-heatmap-osm"
source_layer="poi"
paint={paint(@radius, @intensity)}
events={["layer:added"]}
/>
<div class="space-y-3 border-t border-line px-4 py-4">
<.form
for={@options}
id="example-heatmap-options"
phx-change="options"
class="grid w-full gap-4 sm:max-w-lg sm:grid-cols-2"
>
<.example_range field={@options[:radius]} label="heatmap-radius" min="2" max="40" />
<.example_range
field={@options[:intensity]}
label="heatmap-intensity"
min="0.1"
max="2"
step="0.1"
/>
</.form>
<.example_note id="example-heatmap-data" icon="hero-map-micro">
{gettext(
"Points of interest in central Paris from OpenStreetMap, in OpenFreeMap's tiles: shops, cafés, museums and the like."
)}
</.example_note>
</div>
<%!-- layer:added sets on_map. --%>
<.example_readout values={[radius: @radius, intensity: @intensity, on_map: @on_map]} />
</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 (heatmap-radius, heatmap-color, heatmap-weight, 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
|
| feature_state | map |
nil
|
a map of feature id => map of state, which paint properties read with feature-state
|