Skip to content

Commit 6993f0d

Browse files
Add MousePosition control.
1 parent 79b7fde commit 6993f0d

File tree

4 files changed

+98
-12
lines changed

4 files changed

+98
-12
lines changed

examples/GeoportalControls.ipynb

+66-9
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 3,
66
"id": "6bb0dd68-f96d-45c5-b3de-48c2092f2690",
77
"metadata": {},
88
"outputs": [],
99
"source": [
1010
"from ipyleaflet import *\n",
11-
"from ipyleaflet.geoportal import GeoportalWMTS, GeoportalLayerSwitcher, GeoportalSearchEngine, GeoportalRoute"
11+
"from ipyleaflet.geoportal import GeoportalWMTS, GeoportalLayerSwitcher, GeoportalSearchEngine, GeoportalRoute, GeoportalMousePosition"
1212
]
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 3,
16+
"execution_count": 4,
1717
"id": "fdeacb8e-3113-453d-ab63-a5ab639bf0c8",
1818
"metadata": {},
1919
"outputs": [
2020
{
2121
"data": {
2222
"application/vnd.jupyter.widget-view+json": {
23-
"model_id": "95aeab83e1fe49fc87dcae3e3c80b6a9",
23+
"model_id": "6a239c9944c143c8ad49af3d1d5417c2",
2424
"version_major": 2,
2525
"version_minor": 0
2626
},
@@ -33,7 +33,7 @@
3333
}
3434
],
3535
"source": [
36-
"#Route for itinerary calculation\n",
36+
"#Route control for itinerary calculation\n",
3737
"layer = GeoportalWMTS(layer = 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', api_key = 'cartes', format = 'image/png')\n",
3838
"m = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
3939
"m.add(layer)\n",
@@ -43,14 +43,14 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 8,
46+
"execution_count": 5,
4747
"id": "3a686d99-c3ca-4596-81aa-24442564bea2",
4848
"metadata": {},
4949
"outputs": [
5050
{
5151
"data": {
5252
"application/vnd.jupyter.widget-view+json": {
53-
"model_id": "6111476c55a64564b77ba196455b171c",
53+
"model_id": "c8dacf4132a44828a29e0d238dcdc266",
5454
"version_major": 2,
5555
"version_minor": 0
5656
},
@@ -63,7 +63,7 @@
6363
}
6464
],
6565
"source": [
66-
"#LayerSwitcher\n",
66+
"#LayerSwitcher control\n",
6767
"m1 = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
6868
"layer1 = GeoportalWMTS() #default\n",
6969
"layer2 = GeoportalWMTS(layer = 'ELEVATION.SLOPES', api_key = 'altimetrie')\n",
@@ -79,9 +79,66 @@
7979
},
8080
{
8181
"cell_type": "code",
82-
"execution_count": null,
82+
"execution_count": 6,
8383
"id": "57062455-fe86-4e3b-8eaf-94e996b44830",
8484
"metadata": {},
85+
"outputs": [
86+
{
87+
"data": {
88+
"application/vnd.jupyter.widget-view+json": {
89+
"model_id": "ca2a469baad0480780ead5013c4d7395",
90+
"version_major": 2,
91+
"version_minor": 0
92+
},
93+
"text/plain": [
94+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
95+
]
96+
},
97+
"metadata": {},
98+
"output_type": "display_data"
99+
}
100+
],
101+
"source": [
102+
"#SearchEngine control\n",
103+
"m2 = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
104+
"#layer1 = GeoportalWMTS() #default\n",
105+
"search_control = GeoportalSearchEngine()\n",
106+
"m2.add(search_control)"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 7,
112+
"id": "0a7ca855-c96d-4864-9b9c-1873712033bb",
113+
"metadata": {},
114+
"outputs": [
115+
{
116+
"data": {
117+
"application/vnd.jupyter.widget-view+json": {
118+
"model_id": "fa99ee68017947eba8768c90410b9e03",
119+
"version_major": 2,
120+
"version_minor": 0
121+
},
122+
"text/plain": [
123+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
124+
]
125+
},
126+
"metadata": {},
127+
"output_type": "display_data"
128+
}
129+
],
130+
"source": [
131+
"#MousePosition control\n",
132+
"m3 = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
133+
"mouse_position_control = GeoportalMousePosition()\n",
134+
"m3.add(mouse_position_control)"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": null,
140+
"id": "17a9e9bb-f3a5-40e5-90ea-8d57049cda5f",
141+
"metadata": {},
85142
"outputs": [],
86143
"source": []
87144
}

ipyleaflet/geoportal.py

+10
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ class GeoportalRoute(Control):
6060
_view_name = Unicode('LeafletGeoportalRouteView').tag(sync=True)
6161
_model_name = Unicode('LeafletGeoportalRouteModel').tag(sync=True)
6262

63+
64+
class GeoportalMousePosition(Control):
65+
"""GeoportalMousePosition class, with Control as parent class
66+
67+
Attributes
68+
----------
69+
"""
70+
71+
_view_name = Unicode('LeafletGeoportalMousePositionView').tag(sync=True)
72+
_model_name = Unicode('LeafletGeoportalMousePositionModel').tag(sync=True)

js/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@jupyter-widgets/base": "^2 || ^3 || ^4.0.0",
2929
"buffer": "^6.0.3",
3030
"crypto-browserify": "^3.12.0",
31+
"geoportal-extensions-leaflet": "^2.2.4",
3132
"leaflet": "^1.7.1",
3233
"leaflet-ant-path": "^1.3.0",
3334
"leaflet-defaulticon-compatibility": "^0.1.1",
@@ -45,9 +46,7 @@
4546
"proj4": "^2.6.0",
4647
"proj4leaflet": "^1.0.1",
4748
"spin.js": "^4.1.0",
48-
"stream-browserify": "^3.0.0",
49-
"geoportal-extensions-leaflet": "2.2.4"
50-
49+
"stream-browserify": "^3.0.0"
5150
},
5251
"devDependencies": {
5352
"@jupyterlab/builder": "^3.0.0",

js/src/layers/Geoportal.js

+20
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,24 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
8585
}
8686
}
8787

88+
export class LeafletGeoportalMousePositionModel extends control.LeafletControlModel {
89+
defaults() {
90+
return {
91+
...super.defaults(),
92+
_view_name: 'LeafletGeoportalMousePositionView',
93+
_model_name: 'LeafletGeoportalMousePositionModel'
94+
};
95+
}
96+
}
97+
98+
export class LeafletGeoportalMousePositionView extends control.LeafletControlView {
99+
initialize(parameters) {
100+
super.initialize(parameters);
101+
this.map_view = this.options.map_view;
102+
}
103+
create_obj() {
104+
this.obj = L.geoportalControl.MousePosition({})
105+
}
106+
}
107+
88108

0 commit comments

Comments
 (0)