Skip to content

Commit 21ad722

Browse files
author
Stefan Kuethe
committed
Fix notebooks
1 parent a0e08bc commit 21ad722

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "6981339e",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%pip install openlayers"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "304dc023",
16+
"metadata": {},
17+
"source": [
18+
"# Style expressions\n",
19+
"\n",
20+
"See also [style-expressions](https://openlayers.org/en/latest/examples/style-expressions.html)"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "3f0152d1",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"import openlayers as ol"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "429e976f",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"polygons = ol.VectorLayer(\n",
41+
" background=\"#1a2b39\",\n",
42+
" source=ol.VectorSource(\n",
43+
" url=\"https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_land.geojson\"\n",
44+
" ),\n",
45+
" style=ol.FlatStyle(\n",
46+
" fill_color=\"darkgrey\",\n",
47+
" )\n",
48+
")"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"id": "34c4c9e5",
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"points = ol.VectorLayer(\n",
59+
" source=ol.VectorSource(\n",
60+
" url=\"https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_populated_places_simple.geojson\"\n",
61+
" ),\n",
62+
" style=ol.FlatStyle(\n",
63+
" circle_radius=[\"get\", \"scalerank\"],\n",
64+
" circle_fill_color=\"gray\",\n",
65+
" circle_stroke_color=\"white\"\n",
66+
" )\n",
67+
")"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"id": "40f2bac1",
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"m = ol.MapWidget(layers=[polygons, points])"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"id": "a69adbaf",
84+
"metadata": {},
85+
"outputs": [],
86+
"source": [
87+
"m"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"id": "dd071b90",
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"text_style = [\n",
98+
" {\n",
99+
" \"filter\": [\">\", [\"get\", \"pop_max\"], 10000000],\n",
100+
" \"style\": {\n",
101+
" \"text-value\": [\n",
102+
" \"concat\",\n",
103+
" [\"get\", \"adm1name\"],\n",
104+
" \", \",\n",
105+
" [\"get\", \"adm0name\"],\n",
106+
" ],\n",
107+
" \"text-font\": \"16px sans-serif\",\n",
108+
" \"text-fill-color\": \"white\",\n",
109+
" \"text-stroke-color\": \"gray\",\n",
110+
" \"text-stroke-width\": 2,\n",
111+
" },\n",
112+
" },\n",
113+
" {\n",
114+
" \"else\": True,\n",
115+
" \"filter\": [\">\", [\"get\", \"pop_max\"], 5000000],\n",
116+
" \"style\": {\n",
117+
" \"text-value\": [\"get\", \"nameascii\"],\n",
118+
" \"text-font\": \"12px sans-serif\",\n",
119+
" \"text-fill-color\": \"white\",\n",
120+
" \"text-stroke-color\": \"gray\",\n",
121+
" \"text-stroke-width\": 2,\n",
122+
" },\n",
123+
" },\n",
124+
"]"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": null,
130+
"id": "0d711fa7",
131+
"metadata": {},
132+
"outputs": [],
133+
"source": [
134+
"text = ol.VectorLayer(\n",
135+
" declutter=False,\n",
136+
" source=ol.VectorSource(\n",
137+
" url=\"https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_populated_places_simple.geojson\"\n",
138+
" ),\n",
139+
" style=text_style\n",
140+
")"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"id": "81240cc2",
147+
"metadata": {},
148+
"outputs": [],
149+
"source": [
150+
"m.add_layer(text)"
151+
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": null,
156+
"id": "60b2e317",
157+
"metadata": {},
158+
"outputs": [],
159+
"source": []
160+
}
161+
],
162+
"metadata": {
163+
"kernelspec": {
164+
"display_name": ".venv",
165+
"language": "python",
166+
"name": "python3"
167+
},
168+
"language_info": {
169+
"codemirror_mode": {
170+
"name": "ipython",
171+
"version": 3
172+
},
173+
"file_extension": ".py",
174+
"mimetype": "text/x-python",
175+
"name": "python",
176+
"nbconvert_exporter": "python",
177+
"pygments_lexer": "ipython3",
178+
"version": "3.11.11"
179+
}
180+
},
181+
"nbformat": 4,
182+
"nbformat_minor": 5
183+
}

0 commit comments

Comments
 (0)