Skip to content

Commit 7862bf6

Browse files
author
Stefan Kuethe
committed
Allow list as style parameter
1 parent dbd678e commit 7862bf6

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

docs/showcase/style-expressions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
# Style expressions
22

33
<iframe src="https://marimo.app/l/5a5k2w?embed=true" width="100%" height=700 frameBorder="0"></iframe>
4+
5+
```python
6+
advanced_style = [
7+
{
8+
"filter": [">", ["get", "pop_max"], 10000000],
9+
"style": {
10+
"text-value": [
11+
"concat",
12+
["get", "adm1name"],
13+
", ",
14+
["get", "adm0name"],
15+
],
16+
"text-font": "16px sans-serif",
17+
"text-fill-color": "white",
18+
"text-stroke-color": "gray",
19+
"text-stroke-width": 2,
20+
},
21+
},
22+
{
23+
"else": True,
24+
"filter": [">", ["get", "pop_max"], 5000000],
25+
"style": {
26+
"text-value": ["get", "nameascii"],
27+
"text-font": "12px sans-serif",
28+
"text-fill-color": "white",
29+
"text-stroke-color": "gray",
30+
"text-stroke-width": 2,
31+
},
32+
},
33+
]
34+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import openlayers as ol
2+
3+
polygons = ol.VectorLayer(
4+
background="#1a2b39",
5+
source=ol.VectorSource(
6+
url="https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_land.geojson"
7+
),
8+
style=ol.FlatStyle(
9+
fill_color="darkgrey",
10+
),
11+
)
12+
13+
points = ol.VectorLayer(
14+
source=ol.VectorSource(
15+
url="https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_populated_places_simple.geojson"
16+
),
17+
style=ol.FlatStyle(
18+
circle_radius=["get", "scalerank"],
19+
circle_fill_color="gray",
20+
circle_stroke_color="white",
21+
),
22+
)
23+
24+
# ---
25+
advanced_style = [
26+
{
27+
"filter": [">", ["get", "pop_max"], 10000000],
28+
"style": {
29+
"text-value": [
30+
"concat",
31+
["get", "adm1name"],
32+
", ",
33+
["get", "adm0name"],
34+
],
35+
"text-font": "16px sans-serif",
36+
"text-fill-color": "white",
37+
"text-stroke-color": "gray",
38+
"text-stroke-width": 2,
39+
},
40+
},
41+
{
42+
"else": True,
43+
"filter": [">", ["get", "pop_max"], 5000000],
44+
"style": {
45+
"text-value": ["get", "nameascii"],
46+
"text-font": "12px sans-serif",
47+
"text-fill-color": "white",
48+
"text-stroke-color": "gray",
49+
"text-stroke-width": 2,
50+
},
51+
},
52+
]
53+
# ---
54+
55+
text = ol.VectorLayer(
56+
declutter = False,
57+
source=ol.VectorSource(
58+
url="https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_populated_places_simple.geojson"
59+
),
60+
style=advanced_style
61+
)
62+
63+
m = ol.Map(layers=[polygons, points, text])
64+
m.save()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "openlayers"
3-
version = "0.1.1"
3+
version = "0.1.2-rc.1"
44
description = "Python Bindings for OpenLayersJS"
55
readme = "README.md"
66
authors = [{ name = "Stefan Kuethe", email = "[email protected]" }]

src/openlayers/models/layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TileLayer(Layer): ...
3434

3535

3636
class VectorTileLayer(Layer):
37-
style: dict | FlatStyle | None = default_style()
37+
style: dict | FlatStyle | list | None = default_style()
3838

3939
@field_validator("style")
4040
def validate_style(cls, v):

0 commit comments

Comments
 (0)