Skip to content

Commit e755647

Browse files
committed
Refactor
1 parent cb8f3c5 commit e755647

File tree

7 files changed

+211
-86
lines changed

7 files changed

+211
-86
lines changed

notebooks/layers/geojson.ipynb

Lines changed: 116 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"id": "60fa6ce0-0354-44d5-8250-eb84224c70ef",
77
"metadata": {},
88
"outputs": [],
99
"source": [
10-
"from openlayers.anywidget import MapWidget\n",
11-
"from openlayers.json_defs import VectorSource, WebGLVectorLayer"
10+
"import openlayers as ol"
1211
]
1312
},
1413
{
1514
"cell_type": "code",
16-
"execution_count": 3,
15+
"execution_count": 2,
1716
"id": "8f37390a-9447-4dff-b8e1-6633ca089e7d",
1817
"metadata": {},
1918
"outputs": [],
@@ -23,7 +22,7 @@
2322
},
2423
{
2524
"cell_type": "code",
26-
"execution_count": 4,
25+
"execution_count": 3,
2726
"id": "ef931766-ee1b-4cfe-8eb5-d17199ecd9f4",
2827
"metadata": {},
2928
"outputs": [
@@ -34,22 +33,25 @@
3433
" 'source': {'url': 'https://openlayers.org/data/vector/populated-places.json',\n",
3534
" 'format': {'@@type': 'GeoJSON'},\n",
3635
" '@@type': 'VectorSource'},\n",
36+
" 'opacity': 1.0,\n",
37+
" 'visible': True,\n",
3738
" 'style': {'circle-fill-color': 'red',\n",
3839
" 'circle-stroke-color': 'yellow',\n",
3940
" 'circle-stroke-width': 0.75,\n",
4041
" 'circle-radius': 5},\n",
42+
" 'fitBounds': False,\n",
4143
" '@@type': 'WebGLVectorLayer'}"
4244
]
4345
},
44-
"execution_count": 4,
46+
"execution_count": 3,
4547
"metadata": {},
4648
"output_type": "execute_result"
4749
}
4850
],
4951
"source": [
50-
"circle_layer = WebGLVectorLayer(\n",
52+
"circle_layer = ol.WebGLVectorLayer(\n",
5153
" id=\"populated-places\",\n",
52-
" source=VectorSource(\n",
54+
" source=ol.VectorSource(\n",
5355
" url=url\n",
5456
" ),\n",
5557
" style={\n",
@@ -64,53 +66,59 @@
6466
},
6567
{
6668
"cell_type": "code",
67-
"execution_count": 6,
69+
"execution_count": 5,
6870
"id": "28b6070b-3282-4435-b1d9-5d6e57dc5c74",
6971
"metadata": {},
7072
"outputs": [
7173
{
7274
"data": {
7375
"text/plain": [
74-
"{'viewOptions': {'center': (0, 0), 'zoom': 0},\n",
76+
"{'view': {'center': (0.0, 0.0),\n",
77+
" 'zoom': 0,\n",
78+
" 'projection': 'EPSG:3857',\n",
79+
" '@@type': 'View'},\n",
7580
" 'layers': [{'id': 'populated-places',\n",
7681
" 'source': {'url': 'https://openlayers.org/data/vector/populated-places.json',\n",
7782
" 'format': {'@@type': 'GeoJSON'},\n",
7883
" '@@type': 'VectorSource'},\n",
84+
" 'opacity': 1.0,\n",
85+
" 'visible': True,\n",
7986
" 'style': {'circle-fill-color': 'red',\n",
8087
" 'circle-stroke-color': 'yellow',\n",
8188
" 'circle-stroke-width': 0.75,\n",
8289
" 'circle-radius': 5},\n",
90+
" 'fitBounds': False,\n",
8391
" '@@type': 'WebGLVectorLayer'}]}"
8492
]
8593
},
86-
"execution_count": 6,
94+
"execution_count": 5,
8795
"metadata": {},
8896
"output_type": "execute_result"
8997
}
9098
],
9199
"source": [
92-
"m = MapWidget(layers=[circle_layer])\n",
93-
"m.map_options"
100+
"m = ol.MapWidget(layers=[circle_layer])\n",
101+
"m.options"
94102
]
95103
},
96104
{
97105
"cell_type": "code",
98-
"execution_count": 7,
106+
"execution_count": 6,
99107
"id": "0160f0b9-c2c1-4480-b890-8dece1eaca1d",
100108
"metadata": {},
101109
"outputs": [
102110
{
103111
"data": {
104112
"application/vnd.jupyter.widget-view+json": {
105-
"model_id": "85f1c6e6430946f8a19861f8fbb31f2d",
113+
"model_id": "2d66f67cdfc24f91860facfd2552d2c4",
106114
"version_major": 2,
107115
"version_minor": 1
108116
},
109117
"text/plain": [
110-
"MapWidget(height='400px', map_options={'viewOptions': {'center': (0, 0), 'zoom': 0}, 'layers': [{'id': 'popula"
118+
"MapWidget(height='400px', options={'view': {'center': (0.0, 0.0), 'zoom': 0, 'projection': 'EPSG:3857', '@@typ"
111119
]
112120
},
113-
"execution_count": 7,
121+
"execution_count": 6,
114122
"metadata": {},
115123
"output_type": "execute_result"
116124
}
@@ -121,9 +129,99 @@
121129
},
122130
{
123131
"cell_type": "code",
124-
"execution_count": null,
132+
"execution_count": 7,
125133
"id": "d8adafbf-d719-475d-aaba-e5c268784034",
126134
"metadata": {},
135+
"outputs": [
136+
{
137+
"data": {
138+
"text/plain": [
139+
"{'layers': [{'id': 'populated-places',\n",
140+
" 'opacity': 1,\n",
141+
" 'visible': True,\n",
142+
" 'fitBounds': False,\n",
143+
" 'maxResolution': None,\n",
144+
" 'minResolution': 0,\n",
145+
" 'minZoom': None,\n",
146+
" 'maxZoom': None,\n",
147+
" 'type': 'WebGLVectorLayer'}],\n",
148+
" 'controls': []}"
149+
]
150+
},
151+
"execution_count": 7,
152+
"metadata": {},
153+
"output_type": "execute_result"
154+
}
155+
],
156+
"source": [
157+
"m.metadata"
158+
]
159+
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": 8,
163+
"id": "a66a808e",
164+
"metadata": {},
165+
"outputs": [],
166+
"source": [
167+
"m.add_control(ol.ZoomSliderControl())"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": 11,
173+
"id": "6c46e94b",
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"cid = m.metadata[\"controls\"][0][\"id\"]"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": 12,
183+
"id": "3b693e8e",
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"m.remove_control(cid)"
188+
]
189+
},
190+
{
191+
"cell_type": "code",
192+
"execution_count": 13,
193+
"id": "5e740b5b",
194+
"metadata": {},
195+
"outputs": [],
196+
"source": [
197+
"m.add_layer(ol.basemaps.BasemapLayer())"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": 14,
203+
"id": "1e769336",
204+
"metadata": {},
205+
"outputs": [],
206+
"source": [
207+
"m.remove_layer(\"populated-places\")"
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": 15,
213+
"id": "4e0edd9c",
214+
"metadata": {},
215+
"outputs": [],
216+
"source": [
217+
"m.add_layer(circle_layer)"
218+
]
219+
},
220+
{
221+
"cell_type": "code",
222+
"execution_count": null,
223+
"id": "a4ef255d",
224+
"metadata": {},
127225
"outputs": [],
128226
"source": []
129227
}

notebooks/layers/geopandas.ipynb

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": null,
17+
"execution_count": 2,
1818
"id": "a0ddec1d-6418-4913-8ca8-7511b16f2ba9",
1919
"metadata": {},
2020
"outputs": [],
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 2,
27+
"execution_count": 3,
2828
"id": "66dca5d9-9aeb-4aac-9192-c2212c7896a9",
2929
"metadata": {},
3030
"outputs": [],
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": 3,
37+
"execution_count": 4,
3838
"id": "e8dd1dba-0691-496a-9d00-ef9af37ac5a7",
3939
"metadata": {},
4040
"outputs": [
@@ -54,7 +54,7 @@
5454
"- Prime Meridian: Greenwich"
5555
]
5656
},
57-
"execution_count": 3,
57+
"execution_count": 4,
5858
"metadata": {},
5959
"output_type": "execute_result"
6060
}
@@ -67,7 +67,7 @@
6767
},
6868
{
6969
"cell_type": "code",
70-
"execution_count": 4,
70+
"execution_count": 5,
7171
"id": "d89002c7-b977-45fa-9cc0-4bd21c94e26d",
7272
"metadata": {},
7373
"outputs": [
@@ -77,7 +77,7 @@
7777
"{'center': (0.0, 0.0), 'zoom': 0, 'projection': 'EPSG:3857'}"
7878
]
7979
},
80-
"execution_count": 4,
80+
"execution_count": 5,
8181
"metadata": {},
8282
"output_type": "execute_result"
8383
}
@@ -90,22 +90,22 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 5,
93+
"execution_count": 10,
9494
"id": "6e1a8778-5b94-41c6-9936-dd2654d83eb0",
9595
"metadata": {},
9696
"outputs": [
9797
{
9898
"data": {
9999
"application/vnd.jupyter.widget-view+json": {
100-
"model_id": "abc4074859844aafa32c1274bfd5841f",
100+
"model_id": "fec92215d43c4b78864fc69c262a5f29",
101101
"version_major": 2,
102102
"version_minor": 1
103103
},
104104
"text/plain": [
105105
"MapWidget(calls=[{'method': 'addLayer', 'args': ({'id': 'geopandas', 'source': {'@@geojson': {'type': 'Feature…"
106106
]
107107
},
108-
"execution_count": 5,
108+
"execution_count": 10,
109109
"metadata": {},
110110
"output_type": "execute_result"
111111
}
@@ -151,10 +151,21 @@
151151
},
152152
{
153153
"cell_type": "code",
154-
"execution_count": null,
154+
"execution_count": 7,
155155
"id": "f69816db-ee91-4d54-b6e2-edd3004a2ab1",
156156
"metadata": {},
157-
"outputs": [],
157+
"outputs": [
158+
{
159+
"data": {
160+
"text/plain": [
161+
"{'fill-color': 'green', 'stroke-color': 'red', 'stroke-width': 2}"
162+
]
163+
},
164+
"execution_count": 7,
165+
"metadata": {},
166+
"output_type": "execute_result"
167+
}
168+
],
158169
"source": [
159170
"from openlayers.styles import FlatStyle\n",
160171
"\n",
@@ -164,7 +175,7 @@
164175
},
165176
{
166177
"cell_type": "code",
167-
"execution_count": null,
178+
"execution_count": 8,
168179
"id": "5acb39ef",
169180
"metadata": {},
170181
"outputs": [],
@@ -176,18 +187,12 @@
176187
},
177188
{
178189
"cell_type": "code",
179-
"execution_count": null,
190+
"execution_count": 11,
180191
"id": "846eb00d-f11b-4bda-a5ef-7d9de969816a",
181192
"metadata": {},
182193
"outputs": [],
183194
"source": [
184-
"#m.calls\n",
185-
"layer_id = \"geopandas\"\n",
186-
"# m.add_call(\"setLayerProperty\", layer_id, \"style\", style)\n",
187-
"# m.add_call(\"setLayerStyle\", layer_id, style)\n",
188-
"layer_call = dict(method=\"setStyle\", args=[style])\n",
189-
"# m.add_call(\"applyCallToLayer\", layer_id, layer_call)\n",
190-
"m.add_layer_call(layer_id, \"setStyle\", style)"
195+
"m.add_drag_and_drop_vector_layers_interaction()"
191196
]
192197
},
193198
{
@@ -276,7 +281,7 @@
276281
],
277282
"metadata": {
278283
"kernelspec": {
279-
"display_name": ".venv",
284+
"display_name": "Python 3 (ipykernel)",
280285
"language": "python",
281286
"name": "python3"
282287
},

src/openlayers/js/openlayers.anywidget.js

Lines changed: 44 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openlayers/js/openlayers.standalone.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/ipywidget-ts/drag-and-drop.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ function addDragAndDropToMap(map: Map, formats?: FeatureFormat[], style?: FlatSt
3939
source: vectorSource,
4040
style: style || undefined
4141
});
42-
vectorLayer.set("id", `drag-and-drop-${Date.now()}`);
43-
vectorLayer.set("type", "VectorLayer");
42+
// vectorLayer.set("id", `drag-and-drop-${Date.now()}`);
43+
// vectorLayer.set("type", "VectorLayer");
44+
vectorLayer.setProperties({
45+
id: `drag-and-drop-${Date.now()}`,
46+
type: "VectorLayer"
47+
});
4448
map.addLayer(vectorLayer);
4549
map.getView().fit(vectorSource.getExtent());
4650
});

0 commit comments

Comments
 (0)