Skip to content

Commit 1092ea0

Browse files
committed
Update openlayers and widget files
1 parent 5ecb93e commit 1092ea0

File tree

4 files changed

+220
-45
lines changed

4 files changed

+220
-45
lines changed

docs/source/_static/embed-bundle.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/source/_static/embed-bundle.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

ipyopenlayers/openlayers.py

Lines changed: 220 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
# Copyright (c) QuantStack.
55
# Distributed under the terms of the Modified BSD License.
66

7-
"""
8-
TODO: Add module docstring
9-
"""
107
from ipywidgets import DOMWidget, Widget, widget_serialization
118
from traitlets import Unicode, List, Instance, CFloat, Bool, Dict, Int, Float
129
from ._frontend import module_name, module_version
13-
import requests
14-
import unicodedata
15-
import configparser
16-
1710

1811
def_loc = [0.0, 0.0]
1912

2013

2114
class Layer(Widget):
15+
"""Base class for all layers on the map.
16+
"""
2217

2318
_model_name = Unicode('LayerModel').tag(sync=True)
2419
_model_module = Unicode(module_name).tag(sync=True)
@@ -28,8 +23,27 @@ class Layer(Widget):
2823
_view_module_version = Unicode(module_version).tag(sync=True)
2924

3025
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)
3347
attribution = Unicode("").tag(sync=True)
3448
opacity = Float(1.0, min=0.0, max=1.0).tag(sync=True)
3549
visible = Bool(True).tag(sync=True)
@@ -38,24 +52,55 @@ class TileLayer(Layer):
3852
source_format = Dict().tag(sync=True)
3953

4054
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)
4465

4566

4667
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+
"""
4773

4874
_view_name = Unicode('RasterTileLayerView').tag(sync=True)
4975
_model_name = Unicode('RasterTileLayerModel').tag(sync=True)
5076

5177

5278
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+
"""
5387

5488
_view_name = Unicode('VectorTileLayerView').tag(sync=True)
5589
_model_name = Unicode('VectorTileLayerModel').tag(sync=True)
5690
style = Dict({}).tag(sync=True)
5791

5892
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+
"""
59104

60105
_view_name = Unicode('OpenLayersGeoJSONView').tag(sync=True)
61106
_model_name = Unicode('OpenLayersGeoJSONModel').tag(sync=True)
@@ -65,68 +110,147 @@ class GeoJSON(Layer):
65110

66111

67112
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+
"""
68124
_view_name = Unicode('HeatmapLayerView').tag(sync=True)
69125
_model_name = Unicode('HeatmapLayerModel').tag(sync=True)
70126
points= List([]).tag(sync=True)
71127
blur =Int(15).tag(sync=True)
72128
radius = Int(8).tag(sync=True)
73129

74130

75-
76-
77131
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+
"""
78139

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)
84145

85146
class ImageOverlay (BaseOverlay):
86-
_view_name = Unicode('ImageOverlayView').tag(sync=True)
87-
_model_name = Unicode('ImageOverlayModel').tag(sync=True)
147+
"""ImageOverlay class.
88148
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)
90161

91162
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)
96177

97178
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)
102192

103193
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+
109205
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)
112210

113211
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+
"""
114217
_view_name = Unicode('FullScreenView').tag(sync=True)
115218
_model_name = Unicode('FullScreenModel').tag(sync=True)
116219

117220

118221
class ScaleLine(BaseControl):
222+
"""ScaleLine class for adding a scale line control to the map.
223+
"""
119224
_view_name = Unicode('ScaleLineView').tag(sync=True)
120225
_model_name = Unicode('ScaleLineModel').tag(sync=True)
121226

122227

123228

124229
class MousePosition(BaseControl):
230+
"""MousePosition class for displaying the mouse position on the map.
231+
"""
125232
_view_name = Unicode('MousePositionView').tag(sync=True)
126233
_model_name = Unicode('MousePositionModel').tag(sync=True)
127234

128235

129236
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+
130254
_model_name = Unicode('MapModel').tag(sync=True)
131255
_model_module = Unicode(module_name).tag(sync=True)
132256
_model_module_version = Unicode(module_version).tag(sync=True)
@@ -135,41 +259,98 @@ class Map(DOMWidget):
135259
_view_module_version = Unicode(module_version).tag(sync=True)
136260

137261
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)
139263
layers = List(Instance(Layer)).tag(sync=True, **widget_serialization)
140264
overlays=List(Instance(BaseOverlay)).tag(sync=True, **widget_serialization)
141265
controls=List(Instance(BaseControl)).tag(sync=True, **widget_serialization)
142266

143267

144268

145269
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+
"""
146279
super().__init__(**kwargs)
147-
self._click_callbacks = []
148280
if center is not None:
149281
self.center = center
150282
if zoom is not None:
151283
self.zoom = zoom
152284

285+
def __repr__(self):
286+
"""Return a string representation of the Map instance."""
287+
return f"Map(center={self.center}, zoom={self.zoom})"
288+
153289
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+
"""
154297
self.layers = self.layers + [layer]
155298

156299
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+
"""
157307
self.overlays = self.overlays + [overlay]
158308

159309
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+
"""
160317
self.layers = [x for x in self.layers if x != layer]
161318

162319
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+
"""
163327
self.overlays = [x for x in self.overlays if x != overlay]
164328

165329
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+
"""
166337
self.controls = self.controls + [control]
167338

168339
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+
"""
169347
self.controls = [x for x in self.controls if x != control]
170348

171349

172350
def clear_layers(self):
351+
"""Remove all layers from the map.
352+
353+
"""
173354
self.layers = []
174355

175356
def on_msg(self, callback):

src/widget.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ export class MapView extends DOMWidgetView {
152152
handleMapClick(event: MapBrowserEvent<MouseEvent>) {
153153
const coordinate = event.coordinate;
154154
const [lon, lat] = coordinate;
155-
this.model.set('clicked_position', [lon, lat]);
156-
this.model.save_changes();
157155
this.send({ lon, lat });
158156
}
159157
layersChanged() {

0 commit comments

Comments
 (0)