Skip to content

Commit 71c3708

Browse files
HaudinFlorencedavidbrochart
authored andcommitted
Integrate geoportal-extensions-leaflet and start with adding a GeoportalLayer.WMTS.
1 parent 6db416c commit 71c3708

File tree

6 files changed

+153
-1
lines changed

6 files changed

+153
-1
lines changed

examples/Geoportal.ipynb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "121b2e3e-faa5-4f53-87c9-9a3112440e98",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# Set up for JupyterLite\n",
11+
"try:\n",
12+
" import piplite\n",
13+
" await piplite.install('ipyleaflet')\n",
14+
"except ImportError:\n",
15+
" pass"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 1,
21+
"id": "119aacd7-fb6b-4bf5-9a97-ac8301eabfed",
22+
"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+
],
36+
"source": [
37+
"from ipyleaflet import *\n",
38+
"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)"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "85b0340e-4b3b-455c-ae07-8734cd68f765",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": []
52+
}
53+
],
54+
"metadata": {
55+
"kernelspec": {
56+
"display_name": "Python 3 (ipykernel)",
57+
"language": "python",
58+
"name": "python3"
59+
},
60+
"language_info": {
61+
"codemirror_mode": {
62+
"name": "ipython",
63+
"version": 3
64+
},
65+
"file_extension": ".py",
66+
"mimetype": "text/x-python",
67+
"name": "python",
68+
"nbconvert_exporter": "python",
69+
"pygments_lexer": "ipython3",
70+
"version": "3.9.13"
71+
}
72+
},
73+
"nbformat": 4,
74+
"nbformat_minor": 5
75+
}

ipyleaflet/geoportal.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
#
4+
5+
6+
from traitlets import Unicode
7+
from .leaflet import TileLayer
8+
9+
10+
11+
class GeoportalWMTS(TileLayer):
12+
"""Geoportal class, with TileLayer as parent class
13+
14+
15+
Attributes
16+
----------
17+
"""
18+
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)
22+

js/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
"proj4": "^2.6.0",
4646
"proj4leaflet": "^1.0.1",
4747
"spin.js": "^4.1.0",
48-
"stream-browserify": "^3.0.0"
48+
"stream-browserify": "^3.0.0",
49+
"geoportal-extensions-leaflet": "2.2.4"
50+
4951
},
5052
"devDependencies": {
5153
"@jupyterlab/builder": "^3.0.0",

js/src/jupyter-leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from './layers/LayerGroup.js';
3030
export * from './layers/FeatureGroup.js';
3131
export * from './layers/GeoJSON.js';
3232
export * from './layers/DivIcon.js';
33+
export * from './layers/Geoportal.js';
3334

3435
//Controls
3536
export * from './controls/AttributionControl.js';

js/src/layers/Geoportal.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
const L = require('../leaflet.js');
5+
const layer = require('./Layer.js');
6+
const utils = require('../utils');
7+
8+
export class LeafletGeoportalModel extends layer.LeafletLayerModel {
9+
defaults() {
10+
return {
11+
...super.defaults(),
12+
_view_name: 'LeafletGeoportalView',
13+
_model_name: 'LeafletGeoportalModel',
14+
name : "ORTHOIMAGERY.ORTHOPHOTOS"
15+
};
16+
}
17+
}
18+
19+
export class LeafletGeoportalView extends layer.LeafletTileLayerView {
20+
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'))
24+
25+
}
26+
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+
);
50+
}
51+
}

js/src/leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require('leaflet-fullscreen');
1515
require('leaflet-transform');
1616
require('leaflet.awesome-markers');
1717
require('leaflet-search');
18+
require('geoportal-extensions-leaflet')
1819

1920
// Monkey patch GridLayer for smoother URL updates
2021
L.patchGridLayer = function (layer) {

0 commit comments

Comments
 (0)