Skip to content

Commit 1ef06d9

Browse files
Add the LayerSwitcher control.
1 parent c70fb9d commit 1ef06d9

File tree

4 files changed

+120
-13
lines changed

4 files changed

+120
-13
lines changed

examples/GeoportalControls.ipynb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"id": "6bb0dd68-f96d-45c5-b3de-48c2092f2690",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"data": {
11+
"application/vnd.jupyter.widget-view+json": {
12+
"model_id": "72c6852ad1be48459976e5b4c009a77a",
13+
"version_major": 2,
14+
"version_minor": 0
15+
},
16+
"text/plain": [
17+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
18+
]
19+
},
20+
"metadata": {},
21+
"output_type": "display_data"
22+
}
23+
],
24+
"source": [
25+
"from ipyleaflet import *\n",
26+
"from ipyleaflet.geoportal import GeoportalWMTS, GeoportalLayerSwitcher\n",
27+
"m = Map(center=(44.799999, 2.26667), zoom=10, zoom_control=True)\n",
28+
"layer1 = GeoportalWMTS() #default\n",
29+
"layer2 = GeoportalWMTS(layer = 'ELEVATION.SLOPES', api_key = 'altimetrie')\n",
30+
"m.add(layer1)\n",
31+
"m.add(layer2)\n",
32+
"layer_control = GeoportalLayerSwitcher()\n",
33+
"m.add(layer_control)"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"id": "57062455-fe86-4e3b-8eaf-94e996b44830",
40+
"metadata": {},
41+
"outputs": [],
42+
"source": []
43+
}
44+
],
45+
"metadata": {
46+
"kernelspec": {
47+
"display_name": "Python 3 (ipykernel)",
48+
"language": "python",
49+
"name": "python3"
50+
},
51+
"language_info": {
52+
"codemirror_mode": {
53+
"name": "ipython",
54+
"version": 3
55+
},
56+
"file_extension": ".py",
57+
"mimetype": "text/x-python",
58+
"name": "python",
59+
"nbconvert_exporter": "python",
60+
"pygments_lexer": "ipython3",
61+
"version": "3.10.5"
62+
}
63+
},
64+
"nbformat": 4,
65+
"nbformat_minor": 5
66+
}

examples/Geoportal.ipynb renamed to examples/GeoportalLayers.ipynb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,25 @@
1717
},
1818
{
1919
"cell_type": "code",
20-
"execution_count": null,
20+
"execution_count": 2,
2121
"id": "68a99b3b-58f1-4251-a724-f5135ac72be1",
2222
"metadata": {},
23-
"outputs": [],
23+
"outputs": [
24+
{
25+
"data": {
26+
"application/vnd.jupyter.widget-view+json": {
27+
"model_id": "abe319d952074d1c8517503b7c05313b",
28+
"version_major": 2,
29+
"version_minor": 0
30+
},
31+
"text/plain": [
32+
"Map(center=[44.799999, 2.26667], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', '…"
33+
]
34+
},
35+
"metadata": {},
36+
"output_type": "display_data"
37+
}
38+
],
2439
"source": [
2540
"from ipyleaflet import *\n",
2641
"from ipyleaflet.geoportal import GeoportalWMTS\n",
@@ -64,14 +79,6 @@
6479
"layer4 = GeoportalWMTS(layer = 'HYDROGRAPHY.BCAE.LATEST', api_key = 'agriculture', format = 'image/png')\n",
6580
"m4.add(layer4)"
6681
]
67-
},
68-
{
69-
"cell_type": "code",
70-
"execution_count": null,
71-
"id": "b6edf13b-f9a1-45c4-b28a-7e9028d4f89f",
72-
"metadata": {},
73-
"outputs": [],
74-
"source": []
7582
}
7683
],
7784
"metadata": {

ipyleaflet/geoportal.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#
44

55

6-
from traitlets import Unicode
7-
from .leaflet import TileLayer
6+
from traitlets import Unicode, Dict
7+
from .leaflet import TileLayer, Control
88

99

1010
class GeoportalWMTS(TileLayer):
@@ -25,4 +25,15 @@ class GeoportalWMTS(TileLayer):
2525
_model_name = Unicode('LeafletGeoportalWMTSModel').tag(sync=True)
2626
layer = Unicode('ORTHOIMAGERY.ORTHOPHOTOS').tag(sync=True, o=True)
2727
api_key = Unicode('essentiels').tag(sync=True, o=True)
28-
format = Unicode('image/jpeg').tag(sync=True, o=True)
28+
format = Unicode('image/jpeg').tag(sync=True, o=True)
29+
30+
31+
class GeoportalLayerSwitcher(Control):
32+
"""GeoportalLayerSwitcher class, with Control as parent class
33+
34+
Attributes
35+
----------
36+
"""
37+
38+
_view_name = Unicode('LeafletGeoportalLayerSwitcherView').tag(sync=True)
39+
_model_name = Unicode('LeafletGeoportalLayerSwitcherModel').tag(sync=True)

js/src/layers/Geoportal.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const L = require('../leaflet.js');
55
const layer = require('./TileLayer.js');
6+
const control = require('../controls/Control.js');
67
const utils = require('../utils');
78

89
export class LeafletGeoportalWMTSModel extends layer.LeafletTileLayerModel {
@@ -20,6 +21,28 @@ export class LeafletGeoportalWMTSModel extends layer.LeafletTileLayerModel {
2021

2122
export class LeafletGeoportalWMTSView extends layer.LeafletTileLayerView {
2223
create_obj() {
24+
console.log('this.get_options():', this.get_options())
2325
this.obj = L.geoportalLayer.WMTS(this.get_options(), {format : this.model.get('format')})
2426
}
2527
}
28+
29+
export class LeafletGeoportalLayerSwitcherModel extends control.LeafletControlModel {
30+
defaults() {
31+
return {
32+
...super.defaults(),
33+
_view_name: 'LeafletGeoportalLayerSwitcherView',
34+
_model_name: 'LeafletGeoportalLayerSwitcherModel'
35+
};
36+
}
37+
}
38+
39+
export class LeafletGeoportalLayerSwitcherView extends control.LeafletControlView {
40+
initialize(parameters) {
41+
super.initialize(parameters);
42+
this.map_view = this.options.map_view;
43+
}
44+
create_obj() {
45+
this.obj = L.geoportalControl.LayerSwitcher()
46+
}
47+
}
48+

0 commit comments

Comments
 (0)