4
4
# Copyright (c) QuantStack.
5
5
# Distributed under the terms of the Modified BSD License.
6
6
7
- """
8
- TODO: Add module docstring
9
- """
10
7
from ipywidgets import DOMWidget , Widget , widget_serialization
11
8
from traitlets import Unicode , List , Instance , CFloat , Bool , Dict , Int , Float
12
9
from ._frontend import module_name , module_version
13
- import requests
14
- import unicodedata
15
- import configparser
16
-
17
10
18
11
def_loc = [0.0 , 0.0 ]
19
12
20
13
21
14
class Layer (Widget ):
15
+ """Base class for all layers on the map.
16
+ """
22
17
23
18
_model_name = Unicode ('LayerModel' ).tag (sync = True )
24
19
_model_module = Unicode (module_name ).tag (sync = True )
@@ -28,8 +23,27 @@ class Layer(Widget):
28
23
_view_module_version = Unicode (module_version ).tag (sync = True )
29
24
30
25
class TileLayer (Layer ):
31
-
32
- url = Unicode ('https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png' ).tag (sync = True )
26
+ """The TileLayer class serves as the foundational class for both raster and vector tile layers.
27
+
28
+ Attributes
29
+ ----------
30
+ url: str
31
+ The URL template for the tile images.
32
+ attribution: str, default ""
33
+ Attribution text for the tile layer.
34
+ opacity: float, default 1.0
35
+ Opacity of the tile layer, between 0.0 and 1.0.
36
+ visible: bool, default True
37
+ Whether the layer is visible or not.
38
+ min_zoom: int, default 0
39
+ Minimum zoom level for the layer.
40
+ max_zoom: int, default 18
41
+ Maximum zoom level for the layer.
42
+ source_format: dict
43
+ Additional format options for the tile source.
44
+ """
45
+
46
+ url = Unicode ('' ).tag (sync = True )
33
47
attribution = Unicode ("" ).tag (sync = True )
34
48
opacity = Float (1.0 , min = 0.0 , max = 1.0 ).tag (sync = True )
35
49
visible = Bool (True ).tag (sync = True )
@@ -38,24 +52,55 @@ class TileLayer(Layer):
38
52
source_format = Dict ().tag (sync = True )
39
53
40
54
class GeoTIFFTileLayer (Layer ):
41
- _model_name = Unicode ('GeoTIFFTileLayerModel' ).tag (sync = True )
42
- _view_name = Unicode ('GeoTIFFTileLayerView' ).tag (sync = True )
43
- url = Unicode ('' ).tag (sync = True )
55
+ """GeoTIFFTileLayer class for WebGL-based GeoTIFF raster tiles.
56
+
57
+ Attributes
58
+ ----------
59
+ url: str, default ""
60
+ The URL for the WebGL-based GeoTIFF tiles.
61
+ """
62
+ _model_name = Unicode ('GeoTIFFTileLayerModel' ).tag (sync = True )
63
+ _view_name = Unicode ('GeoTIFFTileLayerView' ).tag (sync = True )
64
+ url = Unicode ('' ).tag (sync = True )
44
65
45
66
46
67
class RasterTileLayer (TileLayer ):
68
+ """RasterTileLayer class for WebGL-based raster tiles.
69
+
70
+ Inherits from TileLayer and provides additional functionality for rendering
71
+ raster tiles using WebGL.
72
+ """
47
73
48
74
_view_name = Unicode ('RasterTileLayerView' ).tag (sync = True )
49
75
_model_name = Unicode ('RasterTileLayerModel' ).tag (sync = True )
50
76
51
77
52
78
class VectorTileLayer (TileLayer ):
79
+ """VectorTileLayer class for vector tiles.
80
+ Inherits from TileLayer and provides additional functionality for vector tiles.
81
+
82
+ Attributes
83
+ ----------
84
+ style: dict
85
+ Style options for vector tiles.
86
+ """
53
87
54
88
_view_name = Unicode ('VectorTileLayerView' ).tag (sync = True )
55
89
_model_name = Unicode ('VectorTileLayerModel' ).tag (sync = True )
56
90
style = Dict ({}).tag (sync = True )
57
91
58
92
class GeoJSON (Layer ):
93
+ """GeoJSON class for GeoJSON data layers.
94
+
95
+ Attributes
96
+ ----------
97
+ data: dict
98
+ The GeoJSON data for the layer.
99
+ style: dict
100
+ Style options for the GeoJSON data.
101
+ visible: bool, default True
102
+ Whether the layer is visible or not.
103
+ """
59
104
60
105
_view_name = Unicode ('OpenLayersGeoJSONView' ).tag (sync = True )
61
106
_model_name = Unicode ('OpenLayersGeoJSONModel' ).tag (sync = True )
@@ -65,68 +110,147 @@ class GeoJSON(Layer):
65
110
66
111
67
112
class HeatmapLayer (Layer ):
113
+ """HeatmapLayer class for heatmap visualization.
114
+
115
+ Attributes
116
+ ----------
117
+ points: list of lists [latitude, longitude, weight]
118
+ A list of data points to be displayed on the heatmap, The weight determines the intensity of the heatmap at that point.
119
+ blur: int, default 15
120
+ Specifies the blur radius for the heatmap The blur controls the smoothness of the heatmap, with higher values creating more diffuse effects
121
+ radius: int, default 8
122
+ The radius of each point in the heatmap, affects how large each data point appears on the map
123
+ """
68
124
_view_name = Unicode ('HeatmapLayerView' ).tag (sync = True )
69
125
_model_name = Unicode ('HeatmapLayerModel' ).tag (sync = True )
70
126
points = List ([]).tag (sync = True )
71
127
blur = Int (15 ).tag (sync = True )
72
128
radius = Int (8 ).tag (sync = True )
73
129
74
130
75
-
76
-
77
131
class BaseOverlay (DOMWidget ):
132
+ """Base class for overlays on the map.
133
+
134
+ Attributes
135
+ ----------
136
+ position: list of float, default [0, 0]
137
+ The position of the overlay on the map (it's center).
138
+ """
78
139
79
- _model_module = Unicode (module_name ).tag (sync = True )
80
- _model_module_version = Unicode (module_version ).tag (sync = True )
81
- _view_module = Unicode (module_name ).tag (sync = True )
82
- _view_module_version = Unicode (module_version ).tag (sync = True )
83
- position = List ([0 , 0 ]).tag (sync = True )
140
+ _model_module = Unicode (module_name ).tag (sync = True )
141
+ _model_module_version = Unicode (module_version ).tag (sync = True )
142
+ _view_module = Unicode (module_name ).tag (sync = True )
143
+ _view_module_version = Unicode (module_version ).tag (sync = True )
144
+ position = List ([0 , 0 ]).tag (sync = True )
84
145
85
146
class ImageOverlay (BaseOverlay ):
86
- _view_name = Unicode ('ImageOverlayView' ).tag (sync = True )
87
- _model_name = Unicode ('ImageOverlayModel' ).tag (sync = True )
147
+ """ImageOverlay class.
88
148
89
- image_url = Unicode ('' ).tag (sync = True )
149
+ Image layer from a local or remote image file.
150
+
151
+ Attributes
152
+ ----------
153
+ image_url: string, default ""
154
+ Url to the local or remote image file.
155
+ position: list, default [0., 0]
156
+ center of the image.
157
+ """
158
+ _view_name = Unicode ('ImageOverlayView' ).tag (sync = True )
159
+ _model_name = Unicode ('ImageOverlayModel' ).tag (sync = True )
160
+ image_url = Unicode ('' ).tag (sync = True )
90
161
91
162
class VideoOverlay (BaseOverlay ):
92
- _view_name = Unicode ('VideoOverlayView' ).tag (sync = True )
93
- _model_name = Unicode ('VideoOverlayModel' ).tag (sync = True )
94
-
95
- video_url = Unicode ('' ).tag (sync = True )
163
+ """VideoOverlay class.
164
+
165
+ Video layer from a local or remote video file.
166
+
167
+ Attributes
168
+ ----------
169
+ video_url: string, default ""
170
+ Url to the local or remote image file.
171
+ position: list, default [0., 0]
172
+ center of the video.
173
+ """
174
+ _view_name = Unicode ('VideoOverlayView' ).tag (sync = True )
175
+ _model_name = Unicode ('VideoOverlayModel' ).tag (sync = True )
176
+ video_url = Unicode ('' ).tag (sync = True )
96
177
97
178
class PopupOverlay (BaseOverlay ):
98
- _view_name = Unicode ('PopupOverlayView' ).tag (sync = True )
99
- _model_name = Unicode ('PopupOverlayModel' ).tag (sync = True )
100
-
101
- popup_content = Unicode ('' ).tag (sync = True )
179
+ """PopupOverlay class.
180
+
181
+
182
+ Attributes
183
+ ----------
184
+ popup_content: string, default ""
185
+ Content to display.
186
+ position: list, default [0., 0]
187
+ position of the popup.
188
+ """
189
+ _view_name = Unicode ('PopupOverlayView' ).tag (sync = True )
190
+ _model_name = Unicode ('PopupOverlayModel' ).tag (sync = True )
191
+ popup_content = Unicode ('' ).tag (sync = True )
102
192
103
193
class BaseControl (DOMWidget ):
104
- _model_module = Unicode (module_name ).tag (sync = True )
105
- _model_module_version = Unicode (module_version ).tag (sync = True )
106
- _view_module = Unicode (module_name ).tag (sync = True )
107
- _view_module_version = Unicode (module_version ).tag (sync = True )
108
-
194
+ """BaseControl abstract class.
195
+
196
+ This is the base class for all ipyopenlayers controls. A control is additional
197
+ UI components on top of the Map.
198
+
199
+ """
200
+ _model_module = Unicode (module_name ).tag (sync = True )
201
+ _model_module_version = Unicode (module_version ).tag (sync = True )
202
+ _view_module = Unicode (module_name ).tag (sync = True )
203
+ _view_module_version = Unicode (module_version ).tag (sync = True )
204
+
109
205
class ZoomSlider (BaseControl ):
110
- _view_name = Unicode ('ZoomSliderView' ).tag (sync = True )
111
- _model_name = Unicode ('ZoomSliderModel' ).tag (sync = True )
206
+ """ZoomSlider class for adding a zoom slider control to the map.
207
+ """
208
+ _view_name = Unicode ('ZoomSliderView' ).tag (sync = True )
209
+ _model_name = Unicode ('ZoomSliderModel' ).tag (sync = True )
112
210
113
211
class FullScreen (BaseControl ):
212
+ """FullScreen class, with Control as parent class.
213
+
214
+ A control which contains a button that will put the Map in
215
+ full-screen when clicked.
216
+ """
114
217
_view_name = Unicode ('FullScreenView' ).tag (sync = True )
115
218
_model_name = Unicode ('FullScreenModel' ).tag (sync = True )
116
219
117
220
118
221
class ScaleLine (BaseControl ):
222
+ """ScaleLine class for adding a scale line control to the map.
223
+ """
119
224
_view_name = Unicode ('ScaleLineView' ).tag (sync = True )
120
225
_model_name = Unicode ('ScaleLineModel' ).tag (sync = True )
121
226
122
227
123
228
124
229
class MousePosition (BaseControl ):
230
+ """MousePosition class for displaying the mouse position on the map.
231
+ """
125
232
_view_name = Unicode ('MousePositionView' ).tag (sync = True )
126
233
_model_name = Unicode ('MousePositionModel' ).tag (sync = True )
127
234
128
235
129
236
class Map (DOMWidget ):
237
+ """Map class.
238
+
239
+ The Map class is the main widget in ipyopenlayers.
240
+
241
+ Attributes
242
+ ----------
243
+ layers: list of Layer instances
244
+ The list of layers that are currently on the map.
245
+ controls: list of Control instances
246
+ The list of controls that are currently on the map.
247
+ overlays: list of Overlay instances
248
+ The list of Overlays that are currently on the map.
249
+ center: list, default [0, 0]
250
+ The current center of the map.
251
+ zoom: float, default 0
252
+ The current zoom value of the map."""
253
+
130
254
_model_name = Unicode ('MapModel' ).tag (sync = True )
131
255
_model_module = Unicode (module_name ).tag (sync = True )
132
256
_model_module_version = Unicode (module_version ).tag (sync = True )
@@ -135,41 +259,98 @@ class Map(DOMWidget):
135
259
_view_module_version = Unicode (module_version ).tag (sync = True )
136
260
137
261
center = List (def_loc ).tag (sync = True , o = True )
138
- zoom = CFloat (2 ).tag (sync = True , o = True )
262
+ zoom = CFloat (0 ).tag (sync = True , o = True )
139
263
layers = List (Instance (Layer )).tag (sync = True , ** widget_serialization )
140
264
overlays = List (Instance (BaseOverlay )).tag (sync = True , ** widget_serialization )
141
265
controls = List (Instance (BaseControl )).tag (sync = True , ** widget_serialization )
142
266
143
267
144
268
145
269
def __init__ (self , center = None , zoom = None , ** kwargs ):
270
+ """Initialize the Map with optional center and zoom level.
271
+
272
+ Parameters
273
+ ----------
274
+ center: list of float, optional
275
+ The initial center of the map.
276
+ zoom: float, optional
277
+ The initial zoom level of the map.
278
+ """
146
279
super ().__init__ (** kwargs )
147
- self ._click_callbacks = []
148
280
if center is not None :
149
281
self .center = center
150
282
if zoom is not None :
151
283
self .zoom = zoom
152
284
285
+ def __repr__ (self ):
286
+ """Return a string representation of the Map instance."""
287
+ return f"Map(center={ self .center } , zoom={ self .zoom } )"
288
+
153
289
def add_layer (self , layer ):
290
+ """Add a layer on the map.
291
+
292
+ Parameters
293
+ ----------
294
+ layer: Layer instance
295
+ The new layer to add.
296
+ """
154
297
self .layers = self .layers + [layer ]
155
298
156
299
def add_overlay (self , overlay ):
300
+ """Add an overlay to the map.
301
+
302
+ Parameters
303
+ ----------
304
+ overlay: BaseOverlay instance
305
+ The overlay to add.
306
+ """
157
307
self .overlays = self .overlays + [overlay ]
158
308
159
309
def remove_layer (self , layer ):
310
+ """Remove a layer from the map.
311
+
312
+ Parameters
313
+ ----------
314
+ layer: Layer instance
315
+ The layer to remove.
316
+ """
160
317
self .layers = [x for x in self .layers if x != layer ]
161
318
162
319
def remove_overlay (self , overlay ):
320
+ """Remove an overlay from the map.
321
+
322
+ Parameters
323
+ ----------
324
+ overlay: BaseOverlay instance
325
+ The overlay to remove.
326
+ """
163
327
self .overlays = [x for x in self .overlays if x != overlay ]
164
328
165
329
def add_control (self , control ):
330
+ """Add a control on the map.
331
+
332
+ Parameters
333
+ ----------
334
+ control: Control instance
335
+ The new control to add.
336
+ """
166
337
self .controls = self .controls + [control ]
167
338
168
339
def remove_control (self , control ):
340
+ """Remove a control from the map.
341
+
342
+ Parameters
343
+ ----------
344
+ control: Control instance
345
+ The control to remove.
346
+ """
169
347
self .controls = [x for x in self .controls if x != control ]
170
348
171
349
172
350
def clear_layers (self ):
351
+ """Remove all layers from the map.
352
+
353
+ """
173
354
self .layers = []
174
355
175
356
def on_msg (self , callback ):
0 commit comments