Fix #6835: doesn't break if Constraint does not exist
This commit is contained in:
+18
-13
@@ -419,21 +419,26 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
|
|||||||
var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
|
var gets = wmtsCap['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'];
|
||||||
|
|
||||||
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'], function(element) {
|
if (gets[i]['Constraint']) {
|
||||||
return element['name'] == 'GetEncoding';
|
var constraint = ol.array.find(gets[i]['Constraint'], function(element) {
|
||||||
});
|
return element['name'] == 'GetEncoding';
|
||||||
var encodings = constraint['AllowedValues']['Value'];
|
});
|
||||||
|
var encodings = constraint['AllowedValues']['Value'];
|
||||||
|
|
||||||
if (requestEncoding === '') {
|
if (requestEncoding === '') {
|
||||||
// requestEncoding not provided, use the first encoding from the list
|
// requestEncoding not provided, use the first encoding from the list
|
||||||
requestEncoding = encodings[0];
|
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 {
|
if (requestEncoding === ol.source.WMTSRequestEncoding.KVP) {
|
||||||
break;
|
if (ol.array.includes(encodings, ol.source.WMTSRequestEncoding.KVP)) {
|
||||||
|
urls.push(/** @type {string} */ (gets[i]['href']));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (gets[i]['href']) {
|
||||||
|
requestEncoding = ol.source.WMTSRequestEncoding.KVP;
|
||||||
|
urls.push(/** @type {string} */ (gets[i]['href']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,9 +92,8 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_exten
|
|||||||
var tileWidthPropName = 'TileWidth';
|
var tileWidthPropName = 'TileWidth';
|
||||||
var tileHeightPropName = 'TileHeight';
|
var tileHeightPropName = 'TileHeight';
|
||||||
|
|
||||||
var projection;
|
|
||||||
var code = matrixSet[supportedCRSPropName];
|
var code = matrixSet[supportedCRSPropName];
|
||||||
projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
|
var projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
|
||||||
ol.proj.get(code);
|
ol.proj.get(code);
|
||||||
var metersPerUnit = projection.getMetersPerUnit();
|
var metersPerUnit = projection.getMetersPerUnit();
|
||||||
// swap origin x and y coordinates if axis orientation is lat/long
|
// swap origin x and y coordinates if axis orientation is lat/long
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ describe('ol.source.WMTS', function() {
|
|||||||
|
|
||||||
describe('when creating options from capabilities', function() {
|
describe('when creating options from capabilities', function() {
|
||||||
var parser = new ol.format.WMTSCapabilities();
|
var parser = new ol.format.WMTSCapabilities();
|
||||||
var capabilities;
|
var capabilities, content;
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function(xml) {
|
afterLoadText('spec/ol/format/wmts/ogcsample.xml', function(xml) {
|
||||||
try {
|
try {
|
||||||
|
content = xml;
|
||||||
capabilities = parser.read(xml);
|
capabilities = parser.read(xml);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
@@ -149,6 +150,32 @@ describe('ol.source.WMTS', function() {
|
|||||||
expect(options.matrixSet).to.be.eql('BigWorldPixel');
|
expect(options.matrixSet).to.be.eql('BigWorldPixel');
|
||||||
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
|
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('doesn\'t fail if the GetCap doesn\'t contains Constraint tags', function() {
|
||||||
|
var tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, '');
|
||||||
|
var tmpCapabilities = parser.read(tmpXml);
|
||||||
|
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
|
||||||
|
var options = ol.source.WMTS.optionsFromCapabilities(tmpCapabilities,
|
||||||
|
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
|
||||||
|
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||||
|
expect(options.matrixSet).to.be.eql('google3857');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('set KVP as default request encoding if the GetCap doesn\'t contains Constraint and ResourceUrl tags', function() {
|
||||||
|
var tmpXml = content.replace(/<ows:Constraint[\s\S]*?<\/ows:Constraint>/g, '');
|
||||||
|
tmpXml = tmpXml.replace(/<ResourceURL[\s\S]*?"\/>/g, '');
|
||||||
|
|
||||||
|
var tmpCapabilities = parser.read(tmpXml);
|
||||||
|
expect(tmpCapabilities['OperationsMetadata']['GetTile']['DCP']['HTTP']['Get'][0]['Constraint']).to.be(undefined);
|
||||||
|
expect(tmpCapabilities['Contents']['Layer'][0]['ResourceURL']).to.be(undefined);
|
||||||
|
var options = ol.source.WMTS.optionsFromCapabilities(tmpCapabilities,
|
||||||
|
{layer: 'BlueMarbleNextGeneration', matrixSet: 'google3857'});
|
||||||
|
expect(options.layer).to.be.eql('BlueMarbleNextGeneration');
|
||||||
|
expect(options.matrixSet).to.be.eql('google3857');
|
||||||
|
expect(options.urls).to.be.an('array');
|
||||||
|
expect(options.urls).to.have.length(1);
|
||||||
|
expect(options.urls[0]).to.be.eql('http://www.maps.bob/cgi-bin/MiraMon5_0.cgi?');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when creating tileUrlFunction', function() {
|
describe('when creating tileUrlFunction', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user