Skip to content

Commit 6808535

Browse files
author
Stefan Kuethe
committed
Add Heatmap layer
1 parent e0df7e9 commit 6808535

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import openlayers as ol
2+
3+
from openlayers.models.layers import HeatmapLayer

marimo/earthquakes-heatmap.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
3+
import marimo
4+
5+
__generated_with = "0.13.2"
6+
app = marimo.App(width="medium")
7+
8+
9+
@app.cell
10+
def _():
11+
import marimo as mo
12+
import openlayers as ol
13+
return mo, ol
14+
15+
16+
@app.cell
17+
def _():
18+
data = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson"
19+
return (data,)
20+
21+
22+
@app.cell
23+
def _(data, ol):
24+
vector = ol.VectorLayer(
25+
source=ol.VectorSource(url=data)
26+
)
27+
return (vector,)
28+
29+
30+
@app.cell
31+
def _(data, ol):
32+
radius = 8
33+
blur = 15
34+
35+
heatmap = ol.HeatmapLayer(
36+
source=ol.VectorSource(url=data),
37+
opacity=0.5,
38+
weight=["get", "mag"],
39+
radius=radius,
40+
blur=blur
41+
)
42+
return blur, heatmap, radius
43+
44+
45+
@app.cell
46+
def _(heatmap, ol, vector):
47+
m = ol.MapWidget(layers=[ol.BasemapLayer(), vector, heatmap])
48+
m.add_tooltip()
49+
return (m,)
50+
51+
52+
@app.cell
53+
def _(m):
54+
m
55+
return
56+
57+
58+
@app.cell(hide_code=True)
59+
def _(heatmap, m, mo, radius):
60+
mo.ui.slider(start=0, stop=20, step=1, value=radius, label="radius", on_change=lambda r: m.add_layer_call(heatmap.id, "setRadius", r))
61+
62+
return
63+
64+
65+
@app.cell(hide_code=True)
66+
def _(blur, heatmap, m, mo):
67+
mo.ui.slider(start=0, stop=30, step=1, value=blur, label="blur", on_change=lambda b: m.add_layer_call(heatmap.id, "setBlur", b))
68+
return
69+
70+
71+
@app.cell
72+
def _():
73+
return
74+
75+
76+
if __name__ == "__main__":
77+
app.run()

src/openlayers/layers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
WebGLTileLayer,
1212
WebGLVectorLayer,
1313
WebGLVectorTileLayer,
14+
HeatmapLayer,
1415
)
1516

1617
__all__ = [
@@ -22,4 +23,5 @@
2223
"VectorTileLayer",
2324
"WebGLVectorTileLayer",
2425
"VectorImageLayer",
26+
"HeatmapLayer",
2527
]

src/openlayers/models/layers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class WebGLTileLayer(Layer):
8383
style: dict | None = None
8484

8585

86+
class HeatmapLayer(Layer):
87+
radius: int | list | None = 8
88+
blur: int | list | None = 15
89+
weight: str | list | None = "weight"
90+
91+
8692
# --- Layer type
8793
LayerT = Union[
8894
Layer,
@@ -93,4 +99,5 @@ class WebGLTileLayer(Layer):
9399
VectorTileLayer,
94100
WebGLVectorTileLayer,
95101
VectorImageLayer,
102+
HeatmapLayer,
96103
]

0 commit comments

Comments
 (0)