Skip to content

Commit 9a580e8

Browse files
Separate Geoportal.js between 2 separate files for layers and controls, and update the SearchEngine, MousePosition and Route controls.
1 parent db52eb3 commit 9a580e8

File tree

5 files changed

+184
-98
lines changed

5 files changed

+184
-98
lines changed

examples/GeoportalControls.ipynb

+23-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
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, GeoportalRoute, GeoportalMousePosition, GeoportalElevationPath, GeoportalIsocurve"
11+
"from ipyleaflet.geoportal import GeoportalLayerSwitcher, GeoportalSearchEngine, GeoportalRoute, GeoportalMousePosition, GeoportalElevationPath, GeoportalIsocurve"
1212
]
1313
},
1414
{
@@ -19,7 +19,7 @@
1919
"outputs": [],
2020
"source": [
2121
"#Route control for itinerary calculation\n",
22-
"layer = GeoportalWMTS(layer = 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', api_key = 'cartes', format = 'image/png')\n",
22+
"layer = basemap_to_tiles(basemaps.GeoportailFrance.plan)\n",
2323
"m = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
2424
"m.add(layer)\n",
2525
"route_control = GeoportalRoute()\n",
@@ -28,21 +28,33 @@
2828
},
2929
{
3030
"cell_type": "code",
31-
"execution_count": null,
31+
"execution_count": 2,
3232
"id": "3a686d99-c3ca-4596-81aa-24442564bea2",
3333
"metadata": {},
34-
"outputs": [],
34+
"outputs": [
35+
{
36+
"data": {
37+
"application/vnd.jupyter.widget-view+json": {
38+
"model_id": "47bf5fd8b8aa413fb0eacad5627beee6",
39+
"version_major": 2,
40+
"version_minor": 0
41+
},
42+
"text/plain": [
43+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
44+
]
45+
},
46+
"execution_count": 2,
47+
"metadata": {},
48+
"output_type": "execute_result"
49+
}
50+
],
3551
"source": [
3652
"#LayerSwitcher control\n",
3753
"m1 = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
38-
"layer1 = GeoportalWMTS() #default\n",
39-
"layer2 = GeoportalWMTS(layer = 'ELEVATION.SLOPES', api_key = 'altimetrie')\n",
40-
"layer3 = GeoportalWMTS(layer = 'HYDROGRAPHY.BCAE.LATEST', api_key = 'agriculture', format = 'image/png')\n",
41-
"layer4 = GeoportalWMTS(layer = 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', api_key = 'cartes', format = 'image/png')\n",
54+
"layer1 = basemap_to_tiles(basemaps.GeoportailFrance.plan)\n",
55+
"layer2 = basemap_to_tiles(basemaps.GeoportailFrance.orthos)\n",
4256
"m1.add(layer1)\n",
4357
"m1.add(layer2)\n",
44-
"m1.add(layer3)\n",
45-
"m1.add(layer4)\n",
4658
"layer_control = GeoportalLayerSwitcher()\n",
4759
"m1.add(layer_control)"
4860
]

ipyleaflet/geoportal.py

+62-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55

6-
from traitlets import Unicode
6+
from traitlets import Unicode, Bool, List, Dict
77
from .leaflet import TileLayer, Control
88

99

@@ -21,11 +21,11 @@ class GeoportalWMTS(TileLayer):
2121
format of the image
2222
"""
2323

24-
_view_name = Unicode('LeafletGeoportalWMTSView').tag(sync=True)
25-
_model_name = Unicode('LeafletGeoportalWMTSModel').tag(sync=True)
26-
layer = Unicode('ORTHOIMAGERY.ORTHOPHOTOS').tag(sync=True, o=True)
27-
api_key = Unicode('essentiels').tag(sync=True, o=True)
28-
format = Unicode('image/jpeg').tag(sync=True, o=True)
24+
_view_name = Unicode("LeafletGeoportalWMTSView").tag(sync=True)
25+
_model_name = Unicode("LeafletGeoportalWMTSModel").tag(sync=True)
26+
layer = Unicode("ORTHOIMAGERY.ORTHOPHOTOS").tag(sync=True, o=True)
27+
api_key = Unicode("essentiels").tag(sync=True, o=True)
28+
format = Unicode("image/jpeg").tag(sync=True, o=True)
2929

3030

3131
class GeoportalLayerSwitcher(Control):
@@ -35,8 +35,8 @@ class GeoportalLayerSwitcher(Control):
3535
----------
3636
"""
3737

38-
_view_name = Unicode('LeafletGeoportalLayerSwitcherView').tag(sync=True)
39-
_model_name = Unicode('LeafletGeoportalLayerSwitcherModel').tag(sync=True)
38+
_view_name = Unicode("LeafletGeoportalLayerSwitcherView").tag(sync=True)
39+
_model_name = Unicode("LeafletGeoportalLayerSwitcherModel").tag(sync=True)
4040

4141

4242
class GeoportalSearchEngine(Control):
@@ -46,8 +46,21 @@ class GeoportalSearchEngine(Control):
4646
----------
4747
"""
4848

49-
_view_name = Unicode('LeafletGeoportalSearchEngineView').tag(sync=True)
50-
_model_name = Unicode('LeafletGeoportalSearchEngineModel').tag(sync=True)
49+
_view_name = Unicode("LeafletGeoportalSearchEngineView").tag(sync=True)
50+
_model_name = Unicode("LeafletGeoportalSearchEngineModel").tag(sync=True)
51+
layer = Unicode("ORTHOIMAGERY.ORTHOPHOTOS").tag(sync=True, o=True)
52+
api_key = Unicode("essentiels").tag(sync=True, o=True)
53+
format = Unicode("image/jpeg").tag(sync=True, o=True)
54+
position = Unicode("topleft").tag(sync=True, o=True)
55+
collapsed = Bool(True).tag(sync=True, o=True)
56+
zoomTo = Unicode("auto").tag(sync=True, o=True)
57+
displayInfo = Bool(True).tag(sync=True, o=True)
58+
apiKey = Unicode("cartes").tag(sync=True, o=True)
59+
displayAdvancedSearch = Bool(True).tag(sync=True, o=True)
60+
resources = List(["PositionOfInterest", "StreetAddress"]).tag(sync=True, o=True)
61+
advancedSearch = Dict({}).tag(sync=True, o=True)
62+
geocodeOptions = Dict({}).tag(sync=True, o=True)
63+
autocompleteOptions = Dict({}).tag(sync=True, o=True)
5164

5265

5366
class GeoportalRoute(Control):
@@ -57,8 +70,14 @@ class GeoportalRoute(Control):
5770
----------
5871
"""
5972

60-
_view_name = Unicode('LeafletGeoportalRouteView').tag(sync=True)
61-
_model_name = Unicode('LeafletGeoportalRouteModel').tag(sync=True)
73+
_view_name = Unicode("LeafletGeoportalRouteView").tag(sync=True)
74+
_model_name = Unicode("LeafletGeoportalRouteModel").tag(sync=True)
75+
position = Unicode("bottomleft").tag(sync=True)
76+
collapsed = Bool(True).tag(sync=True)
77+
exclusions = Dict({"toll": True, "bridge": False, "tunnel": True}).tag(sync=True)
78+
graphs = List(["Pieton", "Voiture"]).tag(sync=True)
79+
autocompleteOptions = Dict({}).tag(sync=True)
80+
routeOptions = Dict({}).tag(sync=True)
6281

6382

6483
class GeoportalMousePosition(Control):
@@ -68,8 +87,27 @@ class GeoportalMousePosition(Control):
6887
----------
6988
"""
7089

71-
_view_name = Unicode('LeafletGeoportalMousePositionView').tag(sync=True)
72-
_model_name = Unicode('LeafletGeoportalMousePositionModel').tag(sync=True)
90+
_view_name = Unicode("LeafletGeoportalMousePositionView").tag(sync=True)
91+
_model_name = Unicode("LeafletGeoportalMousePositionModel").tag(sync=True)
92+
position = Unicode("bottomleft").tag(sync=True)
93+
collapsed = Bool(False).tag(sync=True)
94+
displayAltitude = Bool(True).tag(sync=True)
95+
displayCoordinates = Bool(True).tag(sync=True)
96+
editCoordinates = Bool(False).tag(sync=True)
97+
altitude = Dict({}).tag(sync=True)
98+
serviceOptions = Dict({})
99+
crs = Unicode().tag(sync=True)
100+
label = Unicode().tag(sync=True)
101+
selectedtype = Unicode().tag(sync=True)
102+
systems = (
103+
List(
104+
[
105+
{crs: "", label: "Lon,Lat", selectedtype: "Geographical"},
106+
{crs: "", label: "Lambert 93", selectedtype: "Metric"},
107+
]
108+
).tag(sync=True),
109+
)
110+
units = List(["DEC", "DMS"]).tag(sync=True)
73111

74112

75113
class GeoportalElevationPath(Control):
@@ -79,8 +117,8 @@ class GeoportalElevationPath(Control):
79117
----------
80118
"""
81119

82-
_view_name = Unicode('LeafletGeoportalElevationPathView').tag(sync=True)
83-
_model_name = Unicode('LeafletGeoportalElevationPathModel').tag(sync=True)
120+
_view_name = Unicode("LeafletGeoportalElevationPathView").tag(sync=True)
121+
_model_name = Unicode("LeafletGeoportalElevationPathModel").tag(sync=True)
84122

85123

86124
class GeoportalIsocurve(Control):
@@ -90,5 +128,11 @@ class GeoportalIsocurve(Control):
90128
----------
91129
"""
92130

93-
_view_name = Unicode('LeafletGeoportalIsocurveView').tag(sync=True)
94-
_model_name = Unicode('LeafletGeoportalIsocurveModel').tag(sync=True)
131+
_view_name = Unicode("LeafletGeoportalIsocurveView").tag(sync=True)
132+
_model_name = Unicode("LeafletGeoportalIsocurveModel").tag(sync=True)
133+
collapsed = (Bool(False).tag(sync=True),)
134+
methods = (List(["time", "distance"]).tag(sync=True),)
135+
exclusions = (Dict({}).tag(sync=True),)
136+
graphs = (List(["Pieton", "Voiture"]).tag(sync=True),)
137+
isocurveOptions = (Dict({}).tag(sync=True),)
138+
autocompleteOptions = Dict({}).tag(sync=True)

js/src/layers/Geoportal.js renamed to js/src/controls/GeoportalControls.js

+71-68
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,8 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
const L = require('../leaflet.js');
5-
const layer = require('./TileLayer.js');
65
const control = require('../controls/Control.js');
7-
const utils = require('../utils');
86

9-
export class LeafletGeoportalWMTSModel extends layer.LeafletTileLayerModel {
10-
defaults() {
11-
return {
12-
...super.defaults(),
13-
_view_name: 'LeafletGeoportalWMTSView',
14-
_model_name: 'LeafletGeoportalWMTSModel',
15-
layer : 'ORTHOIMAGERY.ORTHOPHOTOS',
16-
apiKey : 'essentiels',
17-
format : 'image/jpeg'
18-
};
19-
}
20-
}
21-
22-
export class LeafletGeoportalWMTSView extends layer.LeafletTileLayerView {
23-
create_obj() {
24-
this.obj = L.geoportalLayer.WMTS({layer : this.model.get('layer'), apiKey : this.model.get('api_key')}, {format : this.model.get('format')})
25-
}
26-
}
277

288
export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlModel {
299
defaults() {
@@ -49,8 +29,18 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
4929
defaults() {
5030
return {
5131
...super.defaults(),
52-
_view_name: 'LeafletGeoportalSearchEngineView',
53-
_model_name: 'LeafletGeoportalSearchEngineModel'
32+
_view_name: 'LeafletGeoportalSearchEngineView',
33+
_model_name: 'LeafletGeoportalSearchEngineModel',
34+
position : 'topleft',
35+
collapsed : true,
36+
zoomTo : 'auto',
37+
displayInfo : true,
38+
apiKey : 'cartes',
39+
displayAdvancedSearch : true,
40+
resources : ["PositionOfInterest", "StreetAddress"],
41+
advancedSearch : {},
42+
geocodeOptions : {},
43+
autocompleteOptions : {}
5444
};
5545
}
5646
}
@@ -61,31 +51,25 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
6151
this.map_view = this.options.map_view;
6252
}
6353
create_obj() {
64-
this.obj = L.geoportalControl.SearchEngine({
65-
position : "topleft",
66-
collapsed : true,
67-
zoomTo : "auto",
68-
displayInfo : true,
69-
displayAdvancedSearch : true,
70-
resources : ["PositionOfInterest", "StreetAddress"],
71-
advancedSearch : {
72-
PositionOfInterest : [{name : "municipality", title : "Ville"}],
73-
StreetAddress : [{}],
74-
CadastralParcel : null,
75-
},
76-
apiKey : "cartes",
77-
geocodeOptions : {},
78-
autocompleteOptions : {}
79-
})
54+
this.obj = L.geoportalControl.SearchEngine(this.get_options())
8055
}
8156
}
8257

8358
export class LeafletGeoportalRouteModel extends control.LeafletControlModel {
8459
defaults() {
8560
return {
8661
...super.defaults(),
87-
_view_name: 'LeafletGeoportalLayerSwitcherView',
88-
_model_name: 'LeafletGeoportalLayerSwitcherModel'
62+
_view_name: 'LeafletGeoportalRouteView',
63+
_model_name: 'LeafletGeoportalRouteModel',
64+
position : "bottomleft",
65+
collapsed : true,
66+
exclusions : {"toll" : true,
67+
"bridge" : false,
68+
"tunnel" : true
69+
},
70+
graphs : ['Pieton', 'Voiture'],
71+
autocompleteOptions : {},
72+
routeOptions : {}
8973
};
9074
}
9175
}
@@ -96,27 +80,45 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
9680
this.map_view = this.options.map_view;
9781
}
9882
create_obj() {
99-
this.obj = L.geoportalControl.Route({
100-
position : "bottomleft",
101-
collapsed : true,
102-
exclusions : {
103-
"toll" : true,
104-
"bridge" : false,
105-
"tunnel" : true
106-
},
107-
graphs : ['Pieton', 'Voiture'],
108-
autocompleteOptions : {},
109-
routeOptions : {}
110-
})
83+
this.obj = L.geoportalControl.Route(this.get_options())
11184
}
11285
}
11386

11487
export class LeafletGeoportalMousePositionModel extends control.LeafletControlModel {
11588
defaults() {
11689
return {
11790
...super.defaults(),
118-
_view_name: 'LeafletGeoportalMousePositionView',
119-
_model_name: 'LeafletGeoportalMousePositionModel'
91+
_view_name: 'LeafletGeoportalMousePositionView',
92+
_model_name: 'LeafletGeoportalMousePositionModel',
93+
position : 'bottomleft',
94+
collapsed : false,
95+
displayAltitude : true,
96+
displayCoordinates : true,
97+
editCoordinates : false,
98+
crs : '',
99+
label : '',
100+
selectedtype: '',
101+
altitude : {
102+
triggerDelay : 100,
103+
responseDelay : 500,
104+
noDataValue : -99999,
105+
noDataValueTolerance : 90000,
106+
serviceOptions : {}
107+
},
108+
systems : [
109+
{
110+
crs : L.CRS.EPSG4326,
111+
label : "Lon,Lat",
112+
selectedtype : "Geographical"
113+
},
114+
{
115+
crs : L.geoportalCRS.EPSG2154,
116+
label : "Lambert 93",
117+
selectedtype : "Metric"
118+
}
119+
],
120+
units : ["DEC", "DMS"]
121+
120122
};
121123
}
122124
}
@@ -155,29 +157,30 @@ export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlMo
155157
defaults() {
156158
return {
157159
...super.defaults(),
158-
_view_name: 'LeafletGeoportalIsocurve',
159-
_model_name: 'LeafletGeoportalIsocurveModel'
160-
};
160+
_view_name: 'LeafletGeoportalIsocurve',
161+
_model_name: 'LeafletGeoportalIsocurveModel',
162+
collapsed : false,
163+
methods : ["time", "distance"],
164+
exclusions : {
165+
toll : true,
166+
bridge : false,
167+
tunnel : true
168+
},
169+
graphs : ["Pieton", "Voiture"],
170+
isocurveOptions : {},
171+
autocompleteOptions : {}
172+
161173
}
162174
}
175+
}
163176

164177
export class LeafletGeoportalIsocurveView extends control.LeafletControlView {
165178
initialize(parameters) {
166179
super.initialize(parameters);
167180
this.map_view = this.options.map_view;
168181
}
169182
create_obj() {
170-
this.obj = L.geoportalControl.Isocurve({
171-
collapsed : false,
172-
methods : ["time", "distance"],
173-
exclusions : {
174-
toll : true,
175-
bridge : false,
176-
tunnel : true
177-
},
178-
graphs : ["Pieton", "Voiture"],
179-
isocurveOptions : {},
180-
autocompleteOptions : {}})
183+
this.obj = L.geoportalControl.Isocurve(this.get_options())
181184
}
182185
}
183186

0 commit comments

Comments
 (0)