Skip to content

Commit

Permalink
(UPD] Moving to IGN geoplateforme
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Mar 7, 2024
1 parent 4d62643 commit f7a76f1
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 313 deletions.
152 changes: 11 additions & 141 deletions dist/ol-ext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* ol-ext - A set of cool extensions for OpenLayers (ol) in node modules structure
* @description ol3,openlayers,popup,menu,symbol,renderer,filter,canvas,interaction,split,statistic,charts,pie,LayerSwitcher,toolbar,animation
* @version v4.0.15
* @version v4.0.16
* @author Jean-Marc Viglino
* @see https://github.com/Viglino/ol-ext#,
* @license BSD-3-Clause
Expand Down Expand Up @@ -10903,11 +10903,7 @@ ol.control.IsochroneGeoportail = class olcontrolIsochroneGeoportail extends ol.c
this.search(this.get('coordinate'), val);
}
}.bind(this));
/* TODO */
this.set('url', 'https://wxs.ign.fr/' + (options.apiKey || 'essentiels') + '/isochrone/isochrone.json');
/*/
this.set('url', 'https://data.geopf.fr/navigation/isochrone')
/**/
this._ajax = new ol.ext.Ajax({
dataType: 'JSON',
auth: options.auth
Expand Down Expand Up @@ -11016,30 +11012,18 @@ ol.control.IsochroneGeoportail = class olcontrolIsochroneGeoportail extends ol.c
}
var dt = Math.round(option * (this.get('iter') - (iter || 0)) / this.get('iter'));
if (typeof option === 'number') {
// Send data
/* TODO remove old version */
// Send data => Capabilities: https://data.geopf.fr/navigation/getcapabilities
var data = {
'gp-access-lib': '2.1.0',
location: ol.proj.toLonLat(coord, proj),
graphName: (this.get('mode') === 'pedestrian' ? 'Pieton' : 'Voiture'),
exclusions: this.get('exclusions') || undefined,
method: method,
time: method === 'time' ? dt : undefined,
distance: method === 'distance' ? dt : undefined,
reverse: (this.get('direction') === 'reverse'),
smoothing: this.get('smoothing') || true,
holes: this.get('holes') || false
};
/*/
// Capabilities: https://data.geopf.fr/navigation/getcapabilities
var data = {
resource: 'bdtopo-osrm', // "jmk_valhalla_cost_type_test", //
// resource: 'jmk_valhalla_cost_type_test',
resource: 'bdtopo-valhalla',
point: ol.proj.toLonLat(coord, proj),
profile: this.get('mode') === 'pedestrian' ? 'pedestrian' : 'car',
costType: method,
costValue: dt,
geometryFormat: 'geojson',
direction: (this.get('direction') === 'reverse') ? 'arrival' : 'departure',
// crs: 'EPSG:4326'
};
/**/
this._ajax.send(this.get('url'), data, {
coord: coord,
option: option,
Expand Down Expand Up @@ -14643,7 +14627,6 @@ ol.control.RoutingGeoportail = class olcontrolRoutingGeoportail extends ol.contr
element.classList.toggle('ol-collapsed');
});
}
// this.set('url', 'https://wxs.ign.fr/calcul/geoportail/' + options.apiKey + '/rest/1.0.0/route');
this.set('url', 'https://data.geopf.fr/navigation/itineraire')
var content = ol.ext.element.create('DIV', { className: 'content', parent: element });
var listElt = ol.ext.element.create('DIV', { className: 'search-input', parent: content });
Expand Down Expand Up @@ -34396,8 +34379,9 @@ ol.layer.GeoImage = class ollayerGeoImage extends ol.layer.Image {
* @param {string} gppKey the API key to get capabilities for
* @return {*} Promise-like response, use then, catch and finally to get the response
*/
static getCapabilities(gppKey, old) {
var capabilities = {}
static getCapabilities(gppKey) {
// Generic API key (for compatibility)
if (gppKey === 'gpf') gppKey = undefined;
var onSuccess = function () { }
var onError = function () { }
var onFinally = function () { }
Expand All @@ -34420,11 +34404,7 @@ ol.layer.GeoImage = class ollayerGeoImage extends ol.layer.Image {
}
return 'autre';
}
// Next version Geoplateforme with getcapabilities
// TODO remove test
if (!old) {
// Old default apikey
if (gppKey === 'gpf') gppKey = undefined;
// Next version Geoplateforme with getcapabilities
var server = gppKey ? 'https://data.geopf.fr/private/wmts' : 'https://data.geopf.fr/wmts';
var url = server + "?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities";
if (gppKey) {
Expand Down Expand Up @@ -34484,116 +34464,6 @@ if (!old) {
onFinally(capabilities, themes)
}
})
} else {
// Old version
// TODO remove old version
var geopresolutions = [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135, 0.29858214169740677, 0.14929107084870338]
// Transform resolution to zoom
var getZoom = function(res) {
res = Number(res) * 0.000281
for (var r = 0; r < geopresolutions.length; r++)
if (res > geopresolutions[r])
return r
}
// Merge constraints
var mergeConstraints = function(ori) {
for (var i = ori.constraint.length - 1; i > 0; i--) {
for (var j = 0; j < i; j++) {
var bok = true
for (var k = 0; k < 4; k++) {
if (ori.constraint[i].bbox[k] != ori.constraint[j].bbox[k]) {
bok = false
break
}
}
if (!bok)
continue
if (ori.constraint[i].maxZoom == ori.constraint[j].minZoom
|| ori.constraint[j].maxZoom == ori.constraint[i].minZoom
|| ori.constraint[i].maxZoom + 1 == ori.constraint[j].minZoom
|| ori.constraint[j].maxZoom + 1 == ori.constraint[i].minZoom
|| ori.constraint[i].minZoom - 1 == ori.constraint[j].maxZoom
|| ori.constraint[j].minZoom - 1 == ori.constraint[i].maxZoom) {
ori.constraint[j].maxZoom = Math.max(ori.constraint[i].maxZoom, ori.constraint[j].maxZoom)
ori.constraint[j].minZoom = Math.min(ori.constraint[i].minZoom, ori.constraint[j].minZoom)
ori.constraint.splice(i, 1)
break
}
}
}
}
// Get capabilities
ol.ext.Ajax.get({
url: 'https://wxs.ign.fr/' + gppKey + '/autoconf/',
dataType: 'TEXT',
error: function (e) {
onError(e)
onFinally({})
},
success: function (resp) {
var parser = new DOMParser()
var config = parser.parseFromString(resp, "text/xml")
var layers = config.getElementsByTagName('Layer')
for (var i = 0, l; l = layers[i]; i++) {
// WMTS ?
if (!/WMTS/.test(l.getElementsByTagName('Server')[0].attributes['service'].value))
continue
// if (!all && !/geoportail\/wmts/.test(l.find("OnlineResource").attr("href"))) continue;
var service = {
key: gppKey,
server: l.getElementsByTagName('gpp:Key')[0].innerHTML.replace(gppKey + "/", ""),
layer: l.getElementsByTagName('Name')[0].innerHTML,
title: l.getElementsByTagName('Title')[0].innerHTML,
format: l.getElementsByTagName('Format')[0] ? l.getElementsByTagName('Format')[0].innerHTML : 'image.jpeg',
style: l.getElementsByTagName('Style')[0].getElementsByTagName('Name')[0].innerHTML,
queryable: (l.attributes.queryable.value === '1'),
tilematrix: 'PM',
minZoom: getZoom(l.getElementsByTagName('sld:MaxScaleDenominator')[0].innerHTML),
maxZoom: getZoom(l.getElementsByTagName('sld:MinScaleDenominator')[0].innerHTML),
bbox: JSON.parse('[' + l.getElementsByTagName('gpp:BoundingBox')[0].innerHTML + ']'),
desc: l.getElementsByTagName('Abstract')[0].innerHTML.replace(/^<!\[CDATA\[(.*)\]\]>$/, '$1')
}
service.originators = {}
var origin = l.getElementsByTagName('gpp:Originator')
for (var k = 0, o; o = origin[k]; k++) {
var ori = service.originators[o.attributes['name'].value] = {
href: o.getElementsByTagName('gpp:URL')[0].innerHTML,
attribution: o.getElementsByTagName('gpp:Attribution')[0].innerHTML,
logo: o.getElementsByTagName('gpp:Logo')[0].innerHTML,
minZoom: 20,
maxZoom: 0,
constraint: []
}
// Scale contraints
var constraint = o.getElementsByTagName('gpp:Constraint')
for (var j = 0, c; c = constraint[j]; j++) {
var zmax = getZoom(c.getElementsByTagName('sld:MinScaleDenominator')[0].innerHTML)
var zmin = getZoom(c.getElementsByTagName('sld:MaxScaleDenominator')[0].innerHTML)
if (zmin > ori.maxZoom)
ori.maxZoom = zmin
if (zmin < ori.minZoom)
ori.minZoom = zmin
if (zmax > ori.maxZoom)
ori.maxZoom = zmax
if (zmax < ori.minZoom)
ori.minZoom = zmax
ori.constraint.push({
minZoom: zmin,
maxZoom: zmax,
bbox: JSON.parse('[' + c.getElementsByTagName('gpp:BoundingBox')[0].innerHTML + ']')
})
}
// Merge constraints
mergeConstraints(ori)
}
capabilities[service.layer] = service
}
onSuccess(capabilities, {})
onFinally(capabilities, {})
}
})
}
// TODO END
// Promise like response
var response = {
then: function (callback) {
Expand Down
4 changes: 2 additions & 2 deletions dist/ol-ext.min.js

Large diffs are not rendered by default.

34 changes: 7 additions & 27 deletions examples/layer/map.layer.geoportail.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,8 @@ <h1>ol-ext: Geoportail layer</h1>
style="width: calc(100% - 1.5em); box-sizing: border-box;"
/><select id="keys" style="width: 1.5em;" onchange="$('#key').val(this.value); loadCapabilities()">
<option value="" style="font-style: italic; color: #fff; background-color: #369;">choisir une couche</option>
<optgroup label="NEW services">
<option value="gpf">Free Géoplateforme</option>
</optgroup>
<optgroup label="OLD services (deprecated)">
<option value="old:cartes">cartes</option>
<option value="old:ortho">ortho</option>
<option value="old:orthohisto">orthohisto</option>
<option value="old:satellite">satellite</option>
<option value="old:cartovecto">cartovecto</option>
<option value="old:topographie">topographie</option>
<option value="old:economie">economie</option>
<option value="old:environnement">environnement</option>
<option value="old:sol">sol</option>
<option value="old:parcellaire">parcellaire</option>
<option value="old:transports">transports</option>
<option value="old:administratif">administratif</option>
<option value="old:altimetrie">altimetrie</option>
<option value="old:agriculture">agriculture</option>
<option value="old:clc">clc</option>
</optgroup>
<option value="gpf">Free Géoplateforme</option>
<!-- option value="ign_scan_ws">cartes</option -->
</select>
</form>
<div id="result" style="display: none;">
Expand Down Expand Up @@ -198,7 +180,6 @@ <h1>ol-ext: Geoportail layer</h1>

map.addLayer (new ol.layer.Geoportail({
layer: 'ORTHOIMAGERY.ORTHOPHOTOS',
// key: 'gpf', // Use new geoservice
permalink: 'ortho',
className: 'photo',
}));
Expand All @@ -211,7 +192,6 @@ <h1>ol-ext: Geoportail layer</h1>

map.addLayer (new ol.layer.Geoportail({
layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2',
// key: 'gpf', // Use new geoservice
permalink: 'plan',
className: 'plan',
visible: true,
Expand Down Expand Up @@ -326,13 +306,13 @@ <h1>ol-ext: Geoportail layer</h1>
$('#layer').hide();
$('#code').text('');
$('#result label span').text('');
if (!k) k = $('#key').val();
if (!k) {
k = $('#key').val();
}
$('#keys').val('')
if (k) {
var old = /^old:/.test(k)
k = k.replace(/^old:|gpf/, '')
console.log(k)
ol.layer.Geoportail.getCapabilities(k, old).then(function(cap) {
if (k==='gpf') k = '';
ol.layer.Geoportail.getCapabilities(k).then(function(cap) {
$('#result').show();
var ul = $('.options ul');
if (!add) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ol-ext",
"version": "4.0.15",
"version": "4.0.16",
"description": "A set of cool extensions for OpenLayers (ol) in node modules structure",
"main": "dist/ol-ext.js",
"style": "dist/ol-ext.css",
Expand Down
28 changes: 6 additions & 22 deletions src/control/IsochroneGeoportail.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ var ol_control_IsochroneGeoportail = class olcontrolIsochroneGeoportail extends
}
}.bind(this));

/* TODO */
this.set('url', 'https://wxs.ign.fr/' + (options.apiKey || 'essentiels') + '/isochrone/isochrone.json');
/*/
this.set('url', 'https://data.geopf.fr/navigation/isochrone')
/**/
this._ajax = new ol_ext_Ajax({
dataType: 'JSON',
auth: options.auth
Expand Down Expand Up @@ -256,30 +252,18 @@ var ol_control_IsochroneGeoportail = class olcontrolIsochroneGeoportail extends
}
var dt = Math.round(option * (this.get('iter') - (iter || 0)) / this.get('iter'));
if (typeof option === 'number') {
// Send data
/* TODO remove old version */
// Send data => Capabilities: https://data.geopf.fr/navigation/getcapabilities
var data = {
'gp-access-lib': '2.1.0',
location: ol_proj_toLonLat(coord, proj),
graphName: (this.get('mode') === 'pedestrian' ? 'Pieton' : 'Voiture'),
exclusions: this.get('exclusions') || undefined,
method: method,
time: method === 'time' ? dt : undefined,
distance: method === 'distance' ? dt : undefined,
reverse: (this.get('direction') === 'reverse'),
smoothing: this.get('smoothing') || true,
holes: this.get('holes') || false
};
/*/
// Capabilities: https://data.geopf.fr/navigation/getcapabilities
var data = {
resource: 'bdtopo-osrm', // "jmk_valhalla_cost_type_test", //
// resource: 'jmk_valhalla_cost_type_test',
resource: 'bdtopo-valhalla',
point: ol_proj_toLonLat(coord, proj),
profile: this.get('mode') === 'pedestrian' ? 'pedestrian' : 'car',
costType: method,
costValue: dt,
geometryFormat: 'geojson',
direction: (this.get('direction') === 'reverse') ? 'arrival' : 'departure',
// crs: 'EPSG:4326'
};
/**/
this._ajax.send(this.get('url'), data, {
coord: coord,
option: option,
Expand Down
1 change: 0 additions & 1 deletion src/control/RoutingGeoportail.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var ol_control_RoutingGeoportail = class olcontrolRoutingGeoportail extends ol_c
});
}

// this.set('url', 'https://wxs.ign.fr/calcul/geoportail/' + options.apiKey + '/rest/1.0.0/route');
this.set('url', 'https://data.geopf.fr/navigation/itineraire')

var content = ol_ext_element.create('DIV', { className: 'content', parent: element });
Expand Down
Loading

0 comments on commit f7a76f1

Please sign in to comment.