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, {
|
var options = ol.source.WMTS.optionsFromCapabilities(result, {
|
||||||
layer: layer,
|
layer: layer,
|
||||||
matrixSet: 'google3857',
|
matrixSet: 'google3857',
|
||||||
requestEncoding: 'REST',
|
|
||||||
style: 'normal'
|
style: 'normal'
|
||||||
});
|
});
|
||||||
options.tilePixelRatio = tilePixelRatio;
|
options.tilePixelRatio = tilePixelRatio;
|
||||||
|
|||||||
+26
-19
@@ -428,32 +428,39 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
|
|||||||
'requestEncoding (%s) is one of "REST", "RESTful", "KVP" or ""',
|
'requestEncoding (%s) is one of "REST", "RESTful", "KVP" or ""',
|
||||||
requestEncoding);
|
requestEncoding);
|
||||||
|
|
||||||
if (!wmtsCap.hasOwnProperty('OperationsMetadata') ||
|
if ('OperationsMetadata' in wmtsCap && 'GetTile' in wmtsCap['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 {
|
|
||||||
var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
|
var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
|
||||||
|
goog.asserts.assert(gets.length >= 1);
|
||||||
|
|
||||||
for (var i = 0, ii = gets.length; i < ii; ++i) {
|
for (var i = 0, ii = gets.length; i < ii; ++i) {
|
||||||
var constraint = ol.array.find(gets[i]['Constraint'],
|
var constraint = ol.array.find(gets[i]['Constraint'], function(element) {
|
||||||
function(elt, index, array) {
|
return element['name'] == 'GetEncoding';
|
||||||
return elt['name'] == 'GetEncoding';
|
});
|
||||||
});
|
|
||||||
var encodings = constraint['AllowedValues']['Value'];
|
var encodings = constraint['AllowedValues']['Value'];
|
||||||
if (encodings.length > 0 && ol.array.includes(encodings, 'KVP')) {
|
goog.asserts.assert(encodings.length >= 1);
|
||||||
requestEncoding = ol.source.WMTSRequestEncoding.KVP;
|
|
||||||
urls.push(/** @type {string} */ (gets[i]['href']));
|
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');
|
goog.asserts.assert(urls.length > 0, 'At least one URL found');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ describe('ol.source.WMTS', function() {
|
|||||||
var options = ol.source.WMTS.optionsFromCapabilities(
|
var options = ol.source.WMTS.optionsFromCapabilities(
|
||||||
capabilities, {
|
capabilities, {
|
||||||
layer: 'Demographics_USA_Population_Density',
|
layer: 'Demographics_USA_Population_Density',
|
||||||
|
requestEncoding: 'KVP',
|
||||||
matrixSet: 'default028mm'
|
matrixSet: 'default028mm'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -171,6 +172,23 @@ describe('ol.source.WMTS', function() {
|
|||||||
'http://services.arcgisonline.com/arcgis/rest/services/' +
|
'http://services.arcgisonline.com/arcgis/rest/services/' +
|
||||||
'Demographics/USA_Population_Density/MapServer/WMTS?');
|
'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() {
|
describe('#getUrls', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user