Merge pull request #354 from bbinet/fix-wmts-from-cap-example
wmts-from-capabilities example doesn't work because of referer check
This commit is contained in:
@@ -49,7 +49,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js" type="text/javascript"></script>
|
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js" type="text/javascript"></script>
|
||||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/defs/EPSG21781.js" type="text/javascript"></script>
|
|
||||||
<script src="loader.js?id=wmts-from-capabilities" type="text/javascript"></script>
|
<script src="loader.js?id=wmts-from-capabilities" type="text/javascript"></script>
|
||||||
<script src="social-links.js" type="text/javascript"></script>
|
<script src="social-links.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
goog.require('ol.Coordinate');
|
goog.require('ol.Coordinate');
|
||||||
goog.require('ol.Extent');
|
|
||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.RendererHints');
|
goog.require('ol.RendererHint');
|
||||||
goog.require('ol.View2D');
|
goog.require('ol.View2D');
|
||||||
goog.require('ol.layer.TileLayer');
|
goog.require('ol.layer.TileLayer');
|
||||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||||
goog.require('ol.projection');
|
|
||||||
goog.require('ol.source.WMTS');
|
goog.require('ol.source.WMTS');
|
||||||
|
|
||||||
|
|
||||||
|
// the getCapabilities document uses EPSG:31256 projection
|
||||||
|
Proj4js.defs['EPSG:31256'] = '+proj=tmerc +lat_0=0 ' +
|
||||||
|
'+lon_0=16.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel ' +
|
||||||
|
'+towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 ' +
|
||||||
|
'+units=m +no_defs';
|
||||||
|
|
||||||
var map, capabilities;
|
var map, capabilities;
|
||||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||||
var projection = ol.projection.configureProj4jsProjection({
|
|
||||||
code: 'EPSG:21781',
|
|
||||||
extent: new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864)
|
|
||||||
});
|
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', 'http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml', true);
|
xhr.open('GET', 'data/WMTSCapabilities.xml', true);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,21 +26,23 @@ xhr.open('GET', 'http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml', true);
|
|||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
capabilities = parser.read(xhr.responseXML);
|
capabilities = parser.read(xhr.responseXML);
|
||||||
var wmtsOptions = ol.source.WMTS.optionsFromCapabilities(
|
|
||||||
capabilities, 'ch.swisstopo.pixelkarte-farbe');
|
|
||||||
wmtsOptions.crossOrigin = 'anonymous';
|
|
||||||
map = new ol.Map({
|
map = new ol.Map({
|
||||||
layers: [
|
layers: [
|
||||||
new ol.layer.TileLayer({
|
new ol.layer.TileLayer({
|
||||||
source: new ol.source.WMTS(wmtsOptions)
|
source: new ol.source.WMTS(ol.source.WMTS.optionsFromCapabilities(
|
||||||
|
capabilities, 'fmzk'))
|
||||||
|
}),
|
||||||
|
new ol.layer.TileLayer({
|
||||||
|
source: new ol.source.WMTS(ol.source.WMTS.optionsFromCapabilities(
|
||||||
|
capabilities, 'beschriftung'))
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
renderers: ol.RendererHints.createFromQueryData(),
|
renderer: ol.RendererHint.CANVAS,
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new ol.View2D({
|
view: new ol.View2D({
|
||||||
center: projection.getExtent().getCenter(),
|
center: new ol.Coordinate(1823849, 6143760),
|
||||||
projection: projection,
|
projection: 'EPSG:3857',
|
||||||
zoom: 1
|
zoom: 11
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ ol.source.WMTS = function(wmtsOptions) {
|
|||||||
var context = {
|
var context = {
|
||||||
'Layer': wmtsOptions.layer,
|
'Layer': wmtsOptions.layer,
|
||||||
'style': wmtsOptions.style,
|
'style': wmtsOptions.style,
|
||||||
|
'Style': wmtsOptions.style,
|
||||||
'TileMatrixSet': wmtsOptions.matrixSet
|
'TileMatrixSet': wmtsOptions.matrixSet
|
||||||
};
|
};
|
||||||
goog.object.extend(context, dimensions);
|
goog.object.extend(context, dimensions);
|
||||||
@@ -204,21 +205,22 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, layer) {
|
|||||||
var encodings = goog.object.getKeys(
|
var encodings = goog.object.getKeys(
|
||||||
gets[0]['constraints']['GetEncoding']['allowedValues']);
|
gets[0]['constraints']['GetEncoding']['allowedValues']);
|
||||||
goog.asserts.assert(encodings.length > 0);
|
goog.asserts.assert(encodings.length > 0);
|
||||||
var requestEncoding = /** @type {ol.source.WMTSRequestEncoding} */
|
|
||||||
(encodings[0]);
|
|
||||||
// TODO: arcgis support, quote from ol2:
|
|
||||||
// The OGC documentation is not clear if we should use REST or RESTful,
|
|
||||||
// ArcGis use RESTful, and OpenLayers use REST.
|
|
||||||
|
|
||||||
var urls;
|
var urls;
|
||||||
switch (requestEncoding) {
|
var requestEncoding;
|
||||||
case ol.source.WMTSRequestEncoding.REST:
|
switch (encodings[0]) {
|
||||||
|
case 'REST':
|
||||||
|
case 'RESTful':
|
||||||
|
// The OGC documentation is not clear if we should use REST or RESTful,
|
||||||
|
// ArcGis use RESTful, and OpenLayers use REST.
|
||||||
|
requestEncoding = ol.source.WMTSRequestEncoding.REST;
|
||||||
goog.asserts.assert(l['resourceUrls'].hasOwnProperty('tile'));
|
goog.asserts.assert(l['resourceUrls'].hasOwnProperty('tile'));
|
||||||
goog.asserts.assert(l['resourceUrls']['tile'].hasOwnProperty(format));
|
goog.asserts.assert(l['resourceUrls']['tile'].hasOwnProperty(format));
|
||||||
urls = /** @type {Array.<string>} */
|
urls = /** @type {Array.<string>} */
|
||||||
(l['resourceUrls']['tile'][format]);
|
(l['resourceUrls']['tile'][format]);
|
||||||
break;
|
break;
|
||||||
case ol.source.WMTSRequestEncoding.KVP:
|
case 'KVP':
|
||||||
|
requestEncoding = ol.source.WMTSRequestEncoding.REST;
|
||||||
urls = [];
|
urls = [];
|
||||||
goog.array.forEach(gets, function(elt, index, array) {
|
goog.array.forEach(gets, function(elt, index, array) {
|
||||||
if (elt['constraints']['GetEncoding']['allowedValues'].hasOwnProperty(
|
if (elt['constraints']['GetEncoding']['allowedValues'].hasOwnProperty(
|
||||||
|
|||||||
Reference in New Issue
Block a user