Skip to content

Commit 79b7fde

Browse files
Add Route control.
1 parent 72b7067 commit 79b7fde

File tree

3 files changed

+100
-10
lines changed

3 files changed

+100
-10
lines changed

examples/GeoportalControls.ipynb

+66-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,79 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
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\n",
11+
"from ipyleaflet.geoportal import GeoportalWMTS, GeoportalLayerSwitcher, GeoportalSearchEngine, GeoportalRoute"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 3,
17+
"id": "fdeacb8e-3113-453d-ab63-a5ab639bf0c8",
18+
"metadata": {},
19+
"outputs": [
20+
{
21+
"data": {
22+
"application/vnd.jupyter.widget-view+json": {
23+
"model_id": "95aeab83e1fe49fc87dcae3e3c80b6a9",
24+
"version_major": 2,
25+
"version_minor": 0
26+
},
27+
"text/plain": [
28+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
29+
]
30+
},
31+
"metadata": {},
32+
"output_type": "display_data"
33+
}
34+
],
35+
"source": [
36+
"#Route for itinerary calculation\n",
37+
"layer = GeoportalWMTS(layer = 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', api_key = 'cartes', format = 'image/png')\n",
1238
"m = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
39+
"m.add(layer)\n",
40+
"route_control = GeoportalRoute()\n",
41+
"m.add(route_control)"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 8,
47+
"id": "3a686d99-c3ca-4596-81aa-24442564bea2",
48+
"metadata": {},
49+
"outputs": [
50+
{
51+
"data": {
52+
"application/vnd.jupyter.widget-view+json": {
53+
"model_id": "6111476c55a64564b77ba196455b171c",
54+
"version_major": 2,
55+
"version_minor": 0
56+
},
57+
"text/plain": [
58+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
59+
]
60+
},
61+
"metadata": {},
62+
"output_type": "display_data"
63+
}
64+
],
65+
"source": [
66+
"#LayerSwitcher\n",
67+
"m1 = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
1368
"layer1 = GeoportalWMTS() #default\n",
14-
"layer2 = GeoportalWMTS(layer = 'ELEVATION.SLOPE')\n",
15-
"m.add(layer1)\n",
16-
"m.add(layer2)\n",
69+
"layer2 = GeoportalWMTS(layer = 'ELEVATION.SLOPES', api_key = 'altimetrie')\n",
70+
"layer3 = GeoportalWMTS(layer = 'HYDROGRAPHY.BCAE.LATEST', api_key = 'agriculture', format = 'image/png')\n",
71+
"layer4 = GeoportalWMTS(layer = 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', api_key = 'cartes', format = 'image/png')\n",
72+
"m1.add(layer1)\n",
73+
"m1.add(layer2)\n",
74+
"m1.add(layer3)\n",
75+
"m1.add(layer4)\n",
1776
"layer_control = GeoportalLayerSwitcher()\n",
18-
"search_control = GeoportalSearchEngine()\n",
19-
"m.add(layer_control)\n",
20-
"m.add(search_control)"
77+
"m1.add(layer_control)"
2178
]
2279
},
2380
{
@@ -45,7 +102,7 @@
45102
"name": "python",
46103
"nbconvert_exporter": "python",
47104
"pygments_lexer": "ipython3",
48-
"version": "3.10.5"
105+
"version": "3.9.12"
49106
}
50107
},
51108
"nbformat": 4,

ipyleaflet/geoportal.py

+12
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,15 @@ class GeoportalSearchEngine(Control):
4848

4949
_view_name = Unicode('LeafletGeoportalSearchEngineView').tag(sync=True)
5050
_model_name = Unicode('LeafletGeoportalSearchEngineModel').tag(sync=True)
51+
52+
53+
class GeoportalRoute(Control):
54+
"""GeoportalRoute class, with Control as parent class
55+
56+
Attributes
57+
----------
58+
"""
59+
60+
_view_name = Unicode('LeafletGeoportalRouteView').tag(sync=True)
61+
_model_name = Unicode('LeafletGeoportalRouteModel').tag(sync=True)
62+

js/src/layers/Geoportal.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,28 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
6161
this.map_view = this.options.map_view;
6262
}
6363
create_obj() {
64-
this.obj = L.geoportalControl.SearchEngine({position : "topright"})
64+
this.obj = L.geoportalControl.SearchEngine({position : "bottomleft"})
6565
}
6666
}
6767

68+
export class LeafletGeoportalRouteModel extends control.LeafletControlModel {
69+
defaults() {
70+
return {
71+
...super.defaults(),
72+
_view_name: 'LeafletGeoportalLayerSwitcherView',
73+
_model_name: 'LeafletGeoportalLayerSwitcherModel'
74+
};
75+
}
76+
}
77+
78+
export class LeafletGeoportalRouteView extends control.LeafletControlView {
79+
initialize(parameters) {
80+
super.initialize(parameters);
81+
this.map_view = this.options.map_view;
82+
}
83+
create_obj() {
84+
this.obj = L.geoportalControl.Route({})
85+
}
86+
}
87+
88+

0 commit comments

Comments
 (0)