Skip to content

Commit 1875fe2

Browse files
HaudinFlorencedavidbrochart
authored andcommitted
Simplify Geoportal.js.
1 parent 71c3708 commit 1875fe2

File tree

3 files changed

+69
-57
lines changed

3 files changed

+69
-57
lines changed

examples/Geoportal.ipynb

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,34 @@
1717
},
1818
{
1919
"cell_type": "code",
20-
"execution_count": 1,
20+
"execution_count": null,
2121
"id": "119aacd7-fb6b-4bf5-9a97-ac8301eabfed",
2222
"metadata": {},
23-
"outputs": [
24-
{
25-
"ename": "NameError",
26-
"evalue": "name 'layer' is not defined",
27-
"output_type": "error",
28-
"traceback": [
29-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
30-
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
31-
"Input \u001b[0;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 5>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mipyleaflet\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mgeoportal\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m GeoportalWMTS\n\u001b[1;32m 4\u001b[0m m \u001b[38;5;241m=\u001b[39m Map(center\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m48.85\u001b[39m, \u001b[38;5;241m2.35\u001b[39m), zoom\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m14\u001b[39m, zoom_control\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[0;32m----> 5\u001b[0m layer \u001b[38;5;241m=\u001b[39m GeoportalWMTS({\u001b[43mlayer\u001b[49m :\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mORTHOIMAGERY.ORTHOPHOTOS\u001b[39m\u001b[38;5;124m\"\u001b[39m,})\n\u001b[1;32m 6\u001b[0m m\u001b[38;5;241m.\u001b[39madd(layer)\n",
32-
"\u001b[0;31mNameError\u001b[0m: name 'layer' is not defined"
33-
]
34-
}
35-
],
23+
"outputs": [],
3624
"source": [
3725
"from ipyleaflet import *\n",
3826
"from ipyleaflet.geoportal import GeoportalWMTS\n",
39-
"\n",
40-
"m = Map(center=(48.85, 2.35), zoom=14, zoom_control=False)\n",
41-
"layer = GeoportalWMTS(name=\"ORTHOIMAGERY.ORTHOPHOTOS\")\n",
42-
"m.add(layer)"
27+
"m1 = Map(center=(48.799999, 2.26667), zoom=10, zoom_control=True)\n",
28+
"layer1 = GeoportalWMTS() #default\n",
29+
"m1.add(layer1)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "2936c8dc-1546-4f13-8c18-6984aaf1c0e3",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"m2 = Map(center=(44.400002, 3.36667), zoom=8, zoom_control=True)\n",
40+
"layer2 = GeoportalWMTS(layer_name = 'ELEVATION.SLOPES', apiKey = 'altimetrie')\n",
41+
"m2.add(layer2)"
4342
]
4443
},
4544
{
4645
"cell_type": "code",
4746
"execution_count": null,
48-
"id": "85b0340e-4b3b-455c-ae07-8734cd68f765",
47+
"id": "24a0dda1-4d07-437e-9c39-396176d5fa53",
4948
"metadata": {},
5049
"outputs": [],
5150
"source": []
@@ -67,7 +66,7 @@
6766
"name": "python",
6867
"nbconvert_exporter": "python",
6968
"pygments_lexer": "ipython3",
70-
"version": "3.9.13"
69+
"version": "3.10.5"
7170
}
7271
},
7372
"nbformat": 4,

ipyleaflet/geoportal.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,42 @@
33
#
44

55

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

99

1010

1111
class GeoportalWMTS(TileLayer):
12-
"""Geoportal class, with TileLayer as parent class
12+
"""GeoportalWMTS class, with TileLayer as parent class
1313
1414
1515
Attributes
1616
----------
17+
layer_name: string, default "ORTHOIMAGERY.ORTHOPHOTOS"
18+
name of the layer to show.
19+
apiKey: string, default "essentiels"
20+
key to access a given ressource, detailed correspondances are given here : https://geoservices.ign.fr/documentation/services/tableau_ressources
1721
"""
1822

19-
_view_name = Unicode('LeafletGeoportalView').tag(sync=True)
20-
_model_name = Unicode('LeafletGeoportalModel').tag(sync=True)
21-
name = Unicode("ORTHOIMAGERY.ORTHOPHOTOS").tag(sync=True, o=True)
23+
_view_name = Unicode('LeafletGeoportalWMTSView').tag(sync=True)
24+
_model_name = Unicode('LeafletGeoportalWMTSModel').tag(sync=True)
25+
layer_name = Unicode("ORTHOIMAGERY.ORTHOPHOTOS").tag(sync=True, o=True)
26+
apiKey = Unicode("essentiels").tag(sync=True, o=True)
2227

28+
29+
class GeoportalWMS(TileLayer):
30+
"""GeoportalWMS class, with TileLayer as parent class
31+
32+
33+
Attributes
34+
----------
35+
layer_name: string, default "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2"
36+
name of the layer to show.
37+
apiKey: string, default "cartes"
38+
key to access a given ressource, detailed correspondances are given here : https://geoservices.ign.fr/documentation/services/tableau_ressources
39+
"""
40+
41+
_view_name = Unicode('LeafletGeoportalWMSView').tag(sync=True)
42+
_model_name = Unicode('LeafletGeoportalWMSModel').tag(sync=True)
43+
name = Unicode("GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2").tag(sync=True, o=True)
44+
layers = Unicode("essentiels").tag(sync=True, o=True)

js/src/layers/Geoportal.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,41 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
const L = require('../leaflet.js');
5-
const layer = require('./Layer.js');
5+
const layer = require('./TileLayer.js');
66
const utils = require('../utils');
77

8-
export class LeafletGeoportalModel extends layer.LeafletLayerModel {
8+
export class LeafletGeoportalWMTSModel extends layer.LeafletTileLayerModel {
99
defaults() {
1010
return {
1111
...super.defaults(),
12-
_view_name: 'LeafletGeoportalView',
13-
_model_name: 'LeafletGeoportalModel',
14-
name : "ORTHOIMAGERY.ORTHOPHOTOS"
12+
_view_name: 'LeafletGeoportalWMTSView',
13+
_model_name: 'LeafletGeoportalWMTSModel',
14+
layer_name : "ORTHOIMAGERY.ORTHOPHOTOS",
15+
apiKey : "essentiels"
1516
};
1617
}
1718
}
1819

19-
export class LeafletGeoportalView extends layer.LeafletTileLayerView {
20+
export class LeafletGeoportalWMTSView extends layer.LeafletTileLayerView {
2021
create_obj() {
21-
var options = this.get_options();
22-
options.data = this.model.get('data');
23-
this.obj = L.geoportalLayer.WMTS(this.model.get('name'))
22+
this.obj = L.geoportalLayer.WMTS({layer : this.model.get('layer_name'), apiKey : this.model.get('apiKey')})
23+
}
24+
}
2425

26+
export class LeafletGeoportalWMSModel extends layer.LeafletTileLayerModel {
27+
defaults() {
28+
return {
29+
...super.defaults(),
30+
_view_name: 'LeafletGeoportalWMSView',
31+
_model_name: 'LeafletGeoportalWMSModel',
32+
layer_name : "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2",
33+
apiKey : "essentiels"
34+
};
2535
}
36+
}
2637

27-
model_events() {
28-
super.model_events();
29-
this.listenTo(
30-
this.model,
31-
'change:data',
32-
function() {
33-
const data = this.model.get('data');
34-
this.obj.setData(data);
35-
},
36-
this
37-
);
38-
// Separate display_options from the options to perform a shallow copy.
39-
var key = 'display_options';
40-
this.listenTo(
41-
this.model,
42-
'change:' + key,
43-
function() {
44-
var options = {};
45-
options[utils.camel_case(key)] = { ...this.model.get(key) };
46-
L.setOptions(this.obj, options);
47-
},
48-
this
49-
);
38+
export class LeafletGeoportalWMSView extends layer.LeafletTileLayerView {
39+
create_obj() {
40+
this.obj = L.geoportalLayer.WMS({layer : this.model.get('layer_name'), apiKey : this.model.get('apiKey')})
5041
}
5142
}

0 commit comments

Comments
 (0)