Fix the requestEncoding automatic selection
If the `requestEncoding` parameter was not provided, the function used `KVP` but without checking if it was supported.
This commit is contained in:
@@ -30,7 +30,6 @@ fetch(capabilitiesUrl).then(function(response) {
|
||||
var options = ol.source.WMTS.optionsFromCapabilities(result, {
|
||||
layer: layer,
|
||||
matrixSet: 'google3857',
|
||||
requestEncoding: 'REST',
|
||||
style: 'normal'
|
||||
});
|
||||
options.tilePixelRatio = tilePixelRatio;
|
||||
|
||||
@@ -428,32 +428,39 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
|
||||
'requestEncoding (%s) is one of "REST", "RESTful", "KVP" or ""',
|
||||
requestEncoding);
|
||||
|
||||
if (!wmtsCap.hasOwnProperty('OperationsMetadata') ||
|
||||
!wmtsCap['OperationsMetadata'].hasOwnProperty('GetTile') ||
|
||||
requestEncoding.indexOf('REST') === 0) {
|
||||
// Add REST tile resource url
|
||||
requestEncoding = ol.source.WMTSRequestEncoding.REST;
|
||||
l['ResourceURL'].forEach(function(elt, index, array) {
|
||||
if (elt['resourceType'] == 'tile') {
|
||||
format = elt['format'];
|
||||
urls.push(/** @type {string} */ (elt['template']));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if ('OperationsMetadata' in wmtsCap && 'GetTile' in wmtsCap['OperationsMetadata']) {
|
||||
var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
|
||||
goog.asserts.assert(gets.length >= 1);
|
||||
|
||||
for (var i = 0, ii = gets.length; i < ii; ++i) {
|
||||
var constraint = ol.array.find(gets[i]['Constraint'],
|
||||
function(elt, index, array) {
|
||||
return elt['name'] == 'GetEncoding';
|
||||
});
|
||||
var constraint = ol.array.find(gets[i]['Constraint'], function(element) {
|
||||
return element['name'] == 'GetEncoding';
|
||||
});
|
||||
var encodings = constraint['AllowedValues']['Value'];
|
||||
if (encodings.length > 0 && ol.array.includes(encodings, 'KVP')) {
|
||||
requestEncoding = ol.source.WMTSRequestEncoding.KVP;
|
||||
urls.push(/** @type {string} */ (gets[i]['href']));
|
||||
goog.asserts.assert(encodings.length >= 1);
|
||||
|
||||
if (requestEncoding === '') {
|
||||
// requestEncoding not provided, use the first encoding from the list
|
||||
requestEncoding = encodings[0];
|
||||
}
|
||||
if (requestEncoding === ol.source.WMTSRequestEncoding.KVP) {
|
||||
if (ol.array.includes(encodings, ol.source.WMTSRequestEncoding.KVP)) {
|
||||
urls.push(/** @type {string} */ (gets[i]['href']));
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (urls.length === 0) {
|
||||
requestEncoding = ol.source.WMTSRequestEncoding.REST;
|
||||
l['ResourceURL'].forEach(function(element) {
|
||||
if (element['resourceType'] === 'tile') {
|
||||
format = element['format'];
|
||||
urls.push(/** @type {string} */ (element['template']));
|
||||
}
|
||||
});
|
||||
}
|
||||
goog.asserts.assert(urls.length > 0, 'At least one URL found');
|
||||
|
||||
return {
|
||||
|
||||
@@ -162,6 +162,7 @@ describe('ol.source.WMTS', function() {
|
||||
var options = ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
requestEncoding: 'KVP',
|
||||
matrixSet: 'default028mm'
|
||||
});
|
||||
|
||||
@@ -171,6 +172,23 @@ describe('ol.source.WMTS', function() {
|
||||
'http://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS?');
|
||||
});
|
||||
|
||||
it('can create REST options from spec/ol/format/wmts/arcgis.xml',
|
||||
function() {
|
||||
var options = ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, {
|
||||
layer: 'Demographics_USA_Population_Density',
|
||||
matrixSet: 'default028mm'
|
||||
});
|
||||
|
||||
expect(options.urls).to.be.an('array');
|
||||
expect(options.urls).to.have.length(1);
|
||||
expect(options.urls[0]).to.be.eql(
|
||||
'http://services.arcgisonline.com/arcgis/rest/services/' +
|
||||
'Demographics/USA_Population_Density/MapServer/WMTS/' +
|
||||
'tile/1.0.0/Demographics_USA_Population_Density/' +
|
||||
'{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUrls', function() {
|
||||
|
||||
Reference in New Issue
Block a user