summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-30 20:30:07 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-05-30 20:30:07 +0200
commit921b3f382270c4910764abed7e22597aa1a9efb8 (patch)
tree11b2515969552f42a44fe5cc5e375a271f232c7e
parentd747bb7da4800b6956194fb4ead89ec73e0c84a9 (diff)
downloadChimère-921b3f382270c4910764abed7e22597aa1a9efb8.tar.bz2
Chimère-921b3f382270c4910764abed7e22597aa1a9efb8.zip
JS: helper for Géoportail layer
-rw-r--r--chimere/static/chimere/js/jquery.chimere.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js
index 39b1abd..4e9e89b 100644
--- a/chimere/static/chimere/js/jquery.chimere.js
+++ b/chimere/static/chimere/js/jquery.chimere.js
@@ -74,6 +74,49 @@ var LayerSwitcher = function(options){
}; // LayerSwitcher
+
+// Géoportail (IGN)
+// example: geoportail_layer('2mqbg0z6cx7ube8gsou10nrt', 'GEOGRAPHICALGRIDSYSTEMS.MAPS', 'Géoportail - Plan IGN', 18, 'image/jpeg')
+// geoportail_layer('2mqbg0z6cx7ube8gsou10nrt', 'CADASTRALPARCELS.PARCELS', 'Géoportail - Cadastre', 20, 'image/png')
+function geoportail_layer(key, layer, name, max_zoom, image_format){
+ var resolutions = [];
+ var matrixIds = [];
+ var proj3857 = ol.proj.get('EPSG:3857');
+ var maxResolution = ol.extent.getWidth(proj3857.getExtent()) / 256;
+ for (var i = 0; i < max_zoom; i++) {
+ matrixIds[i] = i.toString();
+ resolutions[i] = maxResolution / Math.pow(2, i);
+ }
+
+ var plan_tileGrid = new ol.tilegrid.WMTS({
+ origin: [-20037508, 20037508],
+ resolutions: resolutions,
+ matrixIds: matrixIds
+ });
+
+ var plan_ign_source = new ol.source.WMTS({
+ url: 'http://wxs.ign.fr/' + key + '/wmts',
+ layer: layer,
+ matrixSet: 'PM',
+ format: image_format,
+ projection: 'EPSG:3857',
+ tileGrid: plan_tileGrid,
+ style: 'normal',
+ attributions: [new ol.Attribution({
+ html: '<a href="http://www.geoportail.fr/" target="_blank">' +
+ '<img src="http://api.ign.fr/geoportail/api/js/latest/' +
+ 'theme/geoportal/img/logo_gp.gif"></a>'
+ })]
+ });
+
+ return new ol.layer.Tile({
+ baselayer: true,
+ name: name,
+ source: plan_ign_source
+ });
+}
+
+
function transformExtent(extent) {
return ol.proj.transformExtent(
extent, EPSG_DISPLAY_PROJECTION, EPSG_PROJECTION);