Fix #7460: use the matrixSet projection by default

This commit is contained in:
oterral
2017-11-09 15:09:33 +01:00
parent a73170ca1d
commit 5a252e628b
3 changed files with 41 additions and 8 deletions

View File

@@ -314,8 +314,9 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
var tileMatrixSet = ol.array.find(tileMatrixSets, function(el) {
return el['Identifier'] == elt['TileMatrixSet'];
});
var supportedCRS = tileMatrixSet['SupportedCRS'].replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3');
var proj1 = ol.proj.get(supportedCRS);
var supportedCRS = tileMatrixSet['SupportedCRS'];
var proj1 = ol.proj.get(supportedCRS.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
ol.proj.get(supportedCRS);
var proj2 = ol.proj.get(config['projection']);
if (proj1 && proj2) {
return ol.proj.equivalent(proj1, proj2);
@@ -374,11 +375,18 @@ ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, config) {
});
var projection;
var code = matrixSetObj['SupportedCRS'];
if (code) {
projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
ol.proj.get(code);
}
if ('projection' in config) {
projection = ol.proj.get(config['projection']);
} else {
projection = ol.proj.get(matrixSetObj['SupportedCRS'].replace(
/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3'));
var projConfig = ol.proj.get(config['projection']);
if (projConfig) {
if (!projection || ol.proj.equivalent(projConfig, projection)) {
projection = projConfig;
}
}
}
var wgs84BoundingBox = l['WGS84BoundingBox'];

View File

@@ -93,8 +93,9 @@ ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet = function(matrixSet, opt_exten
var tileHeightPropName = 'TileHeight';
var projection;
projection = ol.proj.get(matrixSet[supportedCRSPropName].replace(
/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3'));
var code = matrixSet[supportedCRSPropName];
projection = ol.proj.get(code.replace(/urn:ogc:def:crs:(\w+):(.*:)?(\w+)$/, '$1:$3')) ||
ol.proj.get(code);
var metersPerUnit = projection.getMetersPerUnit();
// swap origin x and y coordinates if axis orientation is lat/long
var switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne';

View File

@@ -113,6 +113,7 @@ describe('ol.source.WMTS', function() {
});
expect(options.matrixSet).to.be.eql('google3857');
expect(options.projection.getCode()).to.be.eql('EPSG:3857');
});
it('can find a MatrixSet by equivalent SRS identifier', function() {
@@ -123,8 +124,31 @@ describe('ol.source.WMTS', function() {
});
expect(options.matrixSet).to.be.eql('google3857');
expect(options.projection.getCode()).to.be.eql('EPSG:900913');
});
it('can find the default MatrixSet', function() {
var options = ol.source.WMTS.optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration',
requestEncoding: 'REST'
});
expect(options.matrixSet).to.be.eql('BigWorldPixel');
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
});
it('uses the projection of the default MatrixSet if the config\'s projection is not supported', function() {
var options = ol.source.WMTS.optionsFromCapabilities(capabilities, {
layer: 'BlueMarbleNextGeneration',
projection: new ol.proj.Projection({
code: 'EPSG:2056',
units: 'm'
})
});
expect(options.matrixSet).to.be.eql('BigWorldPixel');
expect(options.projection.getCode()).to.be.eql('urn:ogc:def:crs:OGC:1.3:CRS84');
});
});
describe('when creating tileUrlFunction', function() {