Skip to content

Commit 00fe60d

Browse files
authored
Merge pull request #3 from Nour-Cheour10/map-control
Map control
2 parents dd1747d + 6ecf2b8 commit 00fe60d

File tree

5 files changed

+2260
-2054
lines changed

5 files changed

+2260
-2054
lines changed

.yarnrc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: false
4+
15
nodeLinker: node-modules
6+

examples/introduction.ipynb

Lines changed: 175 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": null,
12+
"execution_count": 1,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
@@ -18,60 +18,220 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": null,
21+
"execution_count": 2,
2222
"metadata": {},
23-
"outputs": [],
23+
"outputs": [
24+
{
25+
"data": {
26+
"application/vnd.jupyter.widget-view+json": {
27+
"model_id": "757d5de3cec24c4e83d186b710dcfa59",
28+
"version_major": 2,
29+
"version_minor": 0
30+
},
31+
"text/plain": [
32+
"Map(center=[0.0, 0.0])"
33+
]
34+
},
35+
"execution_count": 2,
36+
"metadata": {},
37+
"output_type": "execute_result"
38+
}
39+
],
2440
"source": [
2541
"m = Map()\n",
2642
"m"
2743
]
2844
},
2945
{
3046
"cell_type": "code",
31-
"execution_count": null,
47+
"execution_count": 5,
3248
"metadata": {},
3349
"outputs": [],
3450
"source": [
35-
"m.layers"
51+
"m.zoom=4\n",
52+
"\n"
3653
]
3754
},
3855
{
3956
"cell_type": "code",
40-
"execution_count": null,
57+
"execution_count": 3,
4158
"metadata": {},
4259
"outputs": [],
4360
"source": [
44-
"layer = TileLayer()\n",
45-
"layer.url = 'wdqjwndqwnd.png'\n",
46-
"layer.url"
61+
"m.center=[10.0,5.0]"
4762
]
4863
},
4964
{
5065
"cell_type": "code",
51-
"execution_count": null,
66+
"execution_count": 6,
5267
"metadata": {},
5368
"outputs": [],
5469
"source": [
55-
"m.add_layer(layer)"
70+
"layere= TileLayer()\n",
71+
"layere.url=\"https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png\"\n"
5672
]
5773
},
5874
{
5975
"cell_type": "code",
60-
"execution_count": null,
76+
"execution_count": 7,
77+
"metadata": {
78+
"scrolled": true
79+
},
80+
"outputs": [],
81+
"source": [
82+
"m.add_layer(layere)"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 8,
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"data": {
92+
"text/plain": [
93+
"[TileLayer(url='https://{a-c}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png')]"
94+
]
95+
},
96+
"execution_count": 8,
97+
"metadata": {},
98+
"output_type": "execute_result"
99+
}
100+
],
101+
"source": [
102+
"m.layers"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": 9,
61108
"metadata": {},
62109
"outputs": [],
110+
"source": [
111+
"m.remove_layer(layere)"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 10,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"data": {
121+
"text/plain": [
122+
"[]"
123+
]
124+
},
125+
"execution_count": 10,
126+
"metadata": {},
127+
"output_type": "execute_result"
128+
}
129+
],
63130
"source": [
64131
"m.layers"
65132
]
66133
},
67134
{
68135
"cell_type": "code",
69-
"execution_count": null,
136+
"execution_count": 11,
70137
"metadata": {},
71138
"outputs": [],
72139
"source": [
73-
"m.layers = []"
140+
"m.clear_layers()"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": 28,
146+
"metadata": {},
147+
"outputs": [
148+
{
149+
"data": {
150+
"text/plain": [
151+
"[]"
152+
]
153+
},
154+
"execution_count": 28,
155+
"metadata": {},
156+
"output_type": "execute_result"
157+
}
158+
],
159+
"source": [
160+
"m.layers"
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": 12,
166+
"metadata": {},
167+
"outputs": [
168+
{
169+
"data": {
170+
"application/vnd.jupyter.widget-view+json": {
171+
"model_id": "59aea50b07f14f028e2fb5e01c43a461",
172+
"version_major": 2,
173+
"version_minor": 0
174+
},
175+
"text/plain": [
176+
"Map(center=[0.0, 0.0])"
177+
]
178+
},
179+
"execution_count": 12,
180+
"metadata": {},
181+
"output_type": "execute_result"
182+
}
183+
],
184+
"source": [
185+
"m1 = Map(center=[0.0, 0.0], zoom=2)\n",
186+
"m1"
187+
]
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": 13,
192+
"metadata": {},
193+
"outputs": [
194+
{
195+
"data": {
196+
"text/plain": [
197+
"2.0"
198+
]
199+
},
200+
"execution_count": 13,
201+
"metadata": {},
202+
"output_type": "execute_result"
203+
}
204+
],
205+
"source": [
206+
"m1.zoom\n"
74207
]
208+
},
209+
{
210+
"cell_type": "code",
211+
"execution_count": 14,
212+
"metadata": {},
213+
"outputs": [
214+
{
215+
"data": {
216+
"text/plain": [
217+
"[0.0, 0.0]"
218+
]
219+
},
220+
"execution_count": 14,
221+
"metadata": {},
222+
"output_type": "execute_result"
223+
}
224+
],
225+
"source": [
226+
"m1.center"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": null,
232+
"metadata": {},
233+
"outputs": [],
234+
"source": []
75235
}
76236
],
77237
"metadata": {
@@ -90,7 +250,7 @@
90250
"name": "python",
91251
"nbconvert_exporter": "python",
92252
"pygments_lexer": "ipython3",
93-
"version": "3.12.3"
253+
"version": "3.10.14"
94254
}
95255
},
96256
"nbformat": 4,

ipyopenlayers/example.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"""
1010

1111
from ipywidgets import DOMWidget, Widget, widget_serialization
12-
from traitlets import Unicode, List, Instance
12+
from traitlets import Unicode, List, Instance, CFloat
1313
from ._frontend import module_name, module_version
14-
14+
def_loc = [0.0, 0.0]
1515

1616
class TileLayer(Widget):
1717

@@ -21,13 +21,10 @@ class TileLayer(Widget):
2121
_view_name = Unicode('TileLayerView').tag(sync=True)
2222
_view_module = Unicode(module_name).tag(sync=True)
2323
_view_module_version = Unicode(module_version).tag(sync=True)
24-
25-
url = Unicode().tag(sync=True)
26-
24+
url = Unicode('https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png').tag(sync=True)
25+
2726

2827
class Map(DOMWidget):
29-
"""TODO: Add docstring here
30-
"""
3128
_model_name = Unicode('MapModel').tag(sync=True)
3229
_model_module = Unicode(module_name).tag(sync=True)
3330
_model_module_version = Unicode(module_version).tag(sync=True)
@@ -36,9 +33,26 @@ class Map(DOMWidget):
3633
_view_module_version = Unicode(module_version).tag(sync=True)
3734

3835
value = Unicode('Hello World').tag(sync=True)
39-
36+
center = List(def_loc).tag(sync=True, o=True)
37+
zoom = CFloat(2).tag(sync=True, o=True)
4038
layers = List(Instance(TileLayer)).tag(sync=True, **widget_serialization)
4139

40+
def __init__(self, center=None, zoom=None, **kwargs):
41+
super().__init__(**kwargs)
42+
43+
if center is not None:
44+
self.center = center
45+
46+
if zoom is not None:
47+
self.zoom = zoom
48+
4249
def add_layer(self, layer):
43-
# Copy layers (workaround ipywidgets issue)
4450
self.layers = self.layers + [layer]
51+
52+
def remove_layer(self, layer):
53+
self.layers = [x for x in self.layers if x != layer]
54+
55+
def clear_layers(self):
56+
self.layers = []
57+
58+

0 commit comments

Comments
 (0)