Add wmts-from-capabilities example
it demonstrates how to create a wmts source by retrieving its configuration from a wmts getCapabilities.
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||||
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||||
|
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="examples.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||||
|
<title>WMTS from capabilities example</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||||
|
<div class="navbar-inner">
|
||||||
|
<div class="container">
|
||||||
|
<a class="brand" href="example-list.html">OpenLayers 3 Examples</a>
|
||||||
|
<ul class="nav pull-right">
|
||||||
|
<li><a href="https://github.com/openlayers/ol3"><i class="icon-github"></i></a></li>
|
||||||
|
<li><a href="https://twitter.com/openlayers"><i class="icon-twitter"></i></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="map" class="map"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row-fluid">
|
||||||
|
|
||||||
|
<div class="span4">
|
||||||
|
<h4 id="title">WMTS from capabilities example</h4>
|
||||||
|
<p id="shortdesc">Example of a WMTS source built from a WMTS getCapabilities response.</p>
|
||||||
|
<div id="docs">
|
||||||
|
<p>See the <a href="wmts-from-capabilities.js" target="_blank">wmts-from-capabilities.js source</a> to see how this is done.</p>
|
||||||
|
</div>
|
||||||
|
<div id="tags">wmts</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js" type="text/javascript"></script>
|
||||||
|
<script src="loader.js?id=wmts-from-capabilities" type="text/javascript"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -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(
|
||||||
|
'© <a href="' +
|
||||||
|
'http://www.geo.admin.ch/internet/geoportal/en/home.html">' +
|
||||||
|
'National parks / geo.admin.ch</a>')],
|
||||||
|
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();
|
||||||
Reference in New Issue
Block a user