From 14d5916e67a175a206645276674bd13f4d9a1eed Mon Sep 17 00:00:00 2001 From: Bruno Binet Date: Thu, 7 Mar 2013 22:25:13 +0100 Subject: [PATCH] Add wmts-from-capabilities example it demonstrates how to create a wmts source by retrieving its configuration from a wmts getCapabilities. --- examples/wmts-from-capabilities.html | 53 ++++++++++++++++++++++ examples/wmts-from-capabilities.js | 66 ++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 examples/wmts-from-capabilities.html create mode 100644 examples/wmts-from-capabilities.js diff --git a/examples/wmts-from-capabilities.html b/examples/wmts-from-capabilities.html new file mode 100644 index 0000000000..5a7844a548 --- /dev/null +++ b/examples/wmts-from-capabilities.html @@ -0,0 +1,53 @@ + + + + + + + + + + WMTS from capabilities example + + + + + +
+ +
+
+
+
+
+ +
+ +
+

WMTS from capabilities example

+

Example of a WMTS source built from a WMTS getCapabilities response.

+
+

See the wmts-from-capabilities.js source to see how this is done.

+
+
wmts
+
+ +
+ +
+ + + + + + diff --git a/examples/wmts-from-capabilities.js b/examples/wmts-from-capabilities.js new file mode 100644 index 0000000000..766e64e015 --- /dev/null +++ b/examples/wmts-from-capabilities.js @@ -0,0 +1,66 @@ +goog.require('ol.Attribution'); +goog.require('ol.Coordinate'); +goog.require('ol.Extent'); +goog.require('ol.Map'); +goog.require('ol.RendererHint'); +goog.require('ol.View2D'); +goog.require('ol.layer.ImageLayer'); +goog.require('ol.layer.TileLayer'); +goog.require('ol.parser.ogc.WMTSCapabilities'); +goog.require('ol.projection'); +goog.require('ol.source.SingleImageWMS'); +goog.require('ol.source.WMTS'); + + +Proj4js['defs']['EPSG:21781'] = + '+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 ' + + '+k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' + + '+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs'; +var projection = ol.projection.configureProj4jsProjection({ + code: 'EPSG:21781', + extent: new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864) +}); + +var map, capabilities; +var parser = new ol.parser.ogc.WMTSCapabilities(); + +var xhr = new XMLHttpRequest(); +xhr.open('GET', 'http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml', true); + + +/** + * onload handler for the XHR request. + */ +xhr.onload = function() { + if (xhr.status == 200) { + capabilities = parser.read(xhr.responseXML); + map = new ol.Map({ + layers: [ + new ol.layer.TileLayer({ + source: ol.source.WMTS.createFromCapabilities( + capabilities, 'ch.swisstopo.pixelkarte-farbe', null) + }), + new ol.layer.ImageLayer({ + source: new ol.source.SingleImageWMS({ + url: 'http://wms.geo.admin.ch/', + attributions: [new ol.Attribution( + '© ' + + 'National parks / geo.admin.ch')], + params: { + 'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung' + } + }) + }) + ], + renderer: ol.RendererHint.CANVAS, + target: 'map', + view: new ol.View2D({ + center: projection.getExtent().getCenter(), + projection: projection, + zoom: 1 + }) + }); + } +}; +xhr.send();