Skip to content

Commit 44610a5

Browse files
committed
Add method to set zoom level
1 parent 6128156 commit 44610a5

File tree

9 files changed

+51
-4
lines changed

9 files changed

+51
-4
lines changed

docs/api/map.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Map
22

3-
::: openlayers.map.Map
3+
::: openlayers.Map
44

5-
::: openlayers.anywidget.MapWidget
5+
::: openlayers.MapWidget

docs/concepts/controls.md

Whitespace-only changes.

docs/concepts/layers.md

Whitespace-only changes.

docs/concepts/map.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Map
2+
3+
The [Map](../../api/map/#openlayers.Map) is the core component of your visualization, to which other components such as [controls](../controls), [layers](../layers) or overlays are added. Components can be added either during initialization or afterwards:
4+
5+
```python
6+
-8<-- "concepts/basic_map.py"
7+
```
8+
9+
The view state of the map ...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import openlayers as ol
2+
3+
# Add components during initialization
4+
m = ol.Map(controls=[ol.ZoomSliderControl()])
5+
6+
# Add components after initialization
7+
m.add_control(ol.FullScreenControl())
8+
9+
# m.add_view_call("setZoom", 5)
10+
m.set_zoom(5)
11+
m.save()

mkdocs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ markdown_extensions:
3333

3434
nav:
3535
- Get started: index.md
36-
# - Concepts: concept.md
36+
- Concepts:
37+
- Map: concepts/map.md
38+
- Controls: concepts/controls.md
39+
- Layers and sources: concepts/layers.md
3740
- API documentation:
3841
- Map: api/map.md
3942
- Controls: api/controls.md

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.

src/openlayers/map.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ def add_layer_call(self, layer_id: str, method_name: str, *args: Any):
5252
layer_call = dict(method=method_name, args=args)
5353
self.add_call("applyCallToLayer", layer_id, layer_call)
5454

55+
def add_view_call(self, method_name: str, *args: Any) -> None:
56+
view_call = dict(method=method_name, args=args)
57+
self.add_call("applyCallToView", view_call)
58+
59+
60+
def set_zoom(self, zoom_level: float | int) -> None:
61+
"""Set the zoom level ot the map view
62+
63+
Args:
64+
zoom_level (float | int): The zoom level of the view
65+
"""
66+
self.add_view_call("setZoom", zoom_level)
67+
5568
def add_layer(self, layer: LayerT | LayerLike | dict) -> None:
5669
"""Add a layer to the map
5770
@@ -140,6 +153,8 @@ def set_style(self, layer_id: str, style: FlatStyle | dict) -> None:
140153

141154
self.add_layer_call(layer_id, "setStyle", style)
142155

156+
def set_view(self, view: View) -> None: ...
157+
143158
def to_html(self, **kwargs) -> str:
144159
"""Render map to HTML"""
145160
data = self.map_options | dict(calls=self.calls)

srcjs/ipywidget-ts/map.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ export default class MapWidget {
133133
this.fitBounds(exent);
134134
}
135135

136+
// --- View Methods
137+
applyCallToView(call: OLAnyWidgetCall): void {
138+
const view = this._map.getView();
139+
console.log("run view method", view);
140+
141+
// @ts-expect-error
142+
view[call.method](...call.args)
143+
}
144+
136145
// --- Layer methods
137146
getLayer(layerId: string): Layer | undefined {
138147
for (let layer of this._map.getLayers().getArray()) {

0 commit comments

Comments
 (0)