Skip to content

Commit ef46168

Browse files
committed
Add zoom and rotate controls with id and type
1 parent c3f45b2 commit ef46168

File tree

7 files changed

+79
-51
lines changed

7 files changed

+79
-51
lines changed

examples/standalone/polygons.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
m = ol.Map(ol.View(projection="EPSG:4326"), layers=[BasemapLayer.osm(), countries])
99
m.add_tooltip("{{ name }}")
1010
# m.add_tooltip()
11+
m.remove_control("zoom")
12+
m.add_control(ol.controls.ZoomControl(zoom_in_label="I", zoom_out_label="O"))
1113
m.add_control(ol.controls.ZoomSliderControl())
1214
m.add_control(ol.controls.InfoBox(
1315
html="PyOL",

notebooks/layers/geopandas.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
},
117117
{
118118
"cell_type": "code",
119-
"execution_count": null,
119+
"execution_count": 11,
120120
"id": "66b75334",
121121
"metadata": {},
122122
"outputs": [],
@@ -127,7 +127,7 @@
127127
},
128128
{
129129
"cell_type": "code",
130-
"execution_count": 8,
130+
"execution_count": 12,
131131
"id": "da76acb0",
132132
"metadata": {},
133133
"outputs": [
@@ -140,7 +140,7 @@
140140
" 'controls': [{}, {}, {}]}"
141141
]
142142
},
143-
"execution_count": 8,
143+
"execution_count": 12,
144144
"metadata": {},
145145
"output_type": "execute_result"
146146
}

src/openlayers/controls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
OverviewMapControl,
1010
ScaleLineControl,
1111
ZoomSliderControl,
12+
ZoomControl,
13+
RotateControl
1214
)
1315

1416
__all__ = [

src/openlayers/js/openlayers.standalone.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/models/controls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ class OverviewMapControl(Control):
4444
layers: list[dict | LayerT] = [TileLayer(source=OSM())]
4545

4646

47+
class ZoomControl(Control):
48+
zoom_in_label: str = Field("+", serialization_alias="zoomInLabel")
49+
zoom_out_label: str = Field("-", serialization_alias="zoomOutLabel")
50+
51+
52+
class RotateControl(Control): ...
53+
54+
4755
# --- Custom controls
4856
class InfoBox(Control):
4957
html: str
@@ -59,5 +67,7 @@ class InfoBox(Control):
5967
ScaleLineControl,
6068
ZoomSliderControl,
6169
OverviewMapControl,
70+
ZoomControl,
71+
RotateControl,
6272
InfoBox,
6373
]

srcjs/ipywidget-ts/controls.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@ import FullScreenControl from 'ol/control/FullScreen.js';
33
import ZoomSliderControl from 'ol/control/ZoomSlider.js';
44
import MousePositionControl from 'ol/control/MousePosition.js';
55
import OverviewMapControl from 'ol/control/OverviewMap.js';
6+
import Zoom from 'ol/control/Zoom';
7+
import Rotate from 'ol/control/Rotate';
68

79
import { InfoBox } from './custom-controls';
810

11+
const zoom = new Zoom();
12+
zoom.setProperties({ id: "zoom", type: "zoomControl" });
13+
14+
const rotate = new Rotate();
15+
rotate.setProperties({ id: "rotate", type: "RotateControl" });
16+
17+
const defaultControls = [zoom, rotate];
18+
919
const controlCatalog: ControlCatalog = {
1020
ScaleLineControl: ScaleLineControl,
1121
FullScreenControl: FullScreenControl,
1222
ZoomSliderControl: ZoomSliderControl,
1323
MousePositionControl: MousePositionControl,
1424
OverviewMapControl: OverviewMapControl,
25+
ZoomControl: Zoom,
26+
RotateControl: Rotate,
1527
InfoBox: InfoBox
1628
};
1729

18-
export { controlCatalog };
30+
export { controlCatalog, defaultControls };

srcjs/ipywidget-ts/map.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Map, View } from "ol";
2-
import { defaults as defaultControls } from 'ol/control/defaults.js';
2+
// import { defaults as defaultControls } from 'ol/control/defaults.js';
33
import GeoJSON from "ol/format/GeoJSON";
44
import Overlay from "ol/Overlay";
55
import Draw from 'ol/interaction/Draw.js';
66
import { fromLonLat, transformExtent, useGeographic } from "ol/proj";
77

88
import { JSONConverter } from "./json";
9+
import { defaultControls } from "./controls";
910
import { addTooltipToMap } from "./tooltip";
1011
import { addSelectFeaturesToMap } from "./select-features";
1112
import { addDragAndDropToMap as addDragAndDropVectorLayersToMap } from "./drag-and-drop";
@@ -85,14 +86,15 @@ export default class MapWidget {
8586
this._model = model;
8687

8788
const view = parseViewDef(mapOptions.view);
88-
let baseControls: Control[] = [];
89+
// let baseControls: Control[] = [];
8990
let baseLayers: Layer[] = [];
9091

9192
this._container = mapElement;
9293
this._map = new Map({
9394
target: mapElement,
9495
view: view,
95-
controls: defaultControls().extend(baseControls),
96+
controls: defaultControls,
97+
// controls: defaultControls().extend(baseControls),
9698
layers: baseLayers,
9799
});
98100

0 commit comments

Comments
 (0)