Add example for WMTS source

This commit is contained in:
Bruno Binet
2013-03-07 19:40:39 +01:00
parent 877ce3adcf
commit 56ffb6146d
2 changed files with 106 additions and 0 deletions

52
examples/wmts.html Normal file
View File

@@ -0,0 +1,52 @@
<!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 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 example</h4>
<p id="shortdesc">Example of a WMTS source.</p>
<div id="docs">
<p>See the <a href="wmts.js" target="_blank">wmts.js source</a> to see how this is done.</p>
</div>
<div id="tags">wmts</div>
</div>
</div>
</div>
<script src="loader.js?id=wmts" type="text/javascript"></script>
</body>
</html>

54
examples/wmts.js Normal file
View File

@@ -0,0 +1,54 @@
goog.require('ol.Coordinate');
goog.require('ol.Extent');
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.layer.TileLayer');
goog.require('ol.projection');
goog.require('ol.source.OpenStreetMap');
goog.require('ol.source.WMTS');
goog.require('ol.tilegrid.WMTS');
var projection = ol.projection.get('EPSG:900913');
var projectionExtent = projection.getExtent();
var size = projectionExtent.getWidth() / 256;
var resolutions = new Array(26);
var matrixIds = new Array(26);
for (var z = 0; z < 26; ++z) {
// generate resolutions and matrixIds arrays for this WMTS
resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = 'EPSG:900913:' + z;
}
var map = new ol.Map({
layers: [
new ol.layer.TileLayer({
source: new ol.source.OpenStreetMap(),
opacity: 0.7
}),
new ol.layer.TileLayer({
source: new ol.source.WMTS({
url: 'http://v2.suite.opengeo.org/geoserver/gwc/service/wmts/',
layer: 'medford:buildings',
matrixSet: 'EPSG:900913',
format: 'image/png',
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: projectionExtent.getTopLeft(),
resolutions: resolutions,
matrixIds: matrixIds
}),
style: '_null',
crossOrigin: null, // FIXME: this should be the default
extent: new ol.Extent(-13682835, 5204068, -13667473, 5221690)
})
})
],
renderer: ol.RendererHint.CANVAS,
target: 'map',
view: new ol.View2D({
center: new ol.Coordinate(-13677832, 5213272),
zoom: 13
})
});