From 4b76ad60d28c4e52b7de03858cd06194a3782e9e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 19 Apr 2018 10:53:10 +0200 Subject: [PATCH 1/2] Remove unused variable --- src/ol/tilegrid/WMTS.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ol/tilegrid/WMTS.js b/src/ol/tilegrid/WMTS.js index 2f20824b29..5f455ad730 100644 --- a/src/ol/tilegrid/WMTS.js +++ b/src/ol/tilegrid/WMTS.js @@ -143,16 +143,15 @@ export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matri return b[scaleDenominatorPropName] - a[scaleDenominatorPropName]; }); - matrixSet[matrixIdsPropName].forEach(function(elt, index, array) { + matrixSet[matrixIdsPropName].forEach(function(elt) { let matrixAvailable; // use of matrixLimits to filter TileMatrices from GetCapabilities // TileMatrixSet from unavailable matrix levels. if (matrixLimits.length > 0) { - matrixAvailable = find(matrixLimits, - function(elt_ml, index_ml, array_ml) { - return elt[identifierPropName] == elt_ml[matrixIdsPropName]; - }); + matrixAvailable = find(matrixLimits, function(elt_ml) { + return elt[identifierPropName] == elt_ml[matrixIdsPropName]; + }); } else { matrixAvailable = true; } From 6006a9d9b5429142e27f30d07668b57dddb8ac5e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 19 Apr 2018 10:57:11 +0200 Subject: [PATCH 2/2] Allow unprefixed WMTS tileMatrix identifiers `ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet` fails when tileMatrix identifiers are not prefixed by their tileMatrixSet identifier. Original code by @filipheymans --- src/ol/tilegrid/WMTS.js | 10 ++++- test/spec/ol/format/wmts/ign.xml | 41 ++++++++++++++++++++ test/spec/ol/format/wmtscapabilities.test.js | 29 +++++++------- test/spec/ol/tilegrid/wmts.test.js | 25 ++++++++++++ 4 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/ol/tilegrid/WMTS.js b/src/ol/tilegrid/WMTS.js index 5f455ad730..782fe3eec9 100644 --- a/src/ol/tilegrid/WMTS.js +++ b/src/ol/tilegrid/WMTS.js @@ -150,7 +150,15 @@ export function createFromCapabilitiesMatrixSet(matrixSet, opt_extent, opt_matri // TileMatrixSet from unavailable matrix levels. if (matrixLimits.length > 0) { matrixAvailable = find(matrixLimits, function(elt_ml) { - return elt[identifierPropName] == elt_ml[matrixIdsPropName]; + if (elt[identifierPropName] == elt_ml[matrixIdsPropName]) { + return true; + } + // Fallback for tileMatrix identifiers that don't get prefixed + // by their tileMatrixSet identifiers. + if (elt[identifierPropName].indexOf(':') === -1) { + return matrixSet[identifierPropName] + ':' + elt[identifierPropName] === elt_ml[matrixIdsPropName]; + } + return false; }); } else { matrixAvailable = true; diff --git a/test/spec/ol/format/wmts/ign.xml b/test/spec/ol/format/wmts/ign.xml index 083c685976..6191195816 100644 --- a/test/spec/ol/format/wmts/ign.xml +++ b/test/spec/ol/format/wmts/ign.xml @@ -248,6 +248,25 @@ Conditions Générales d'Utilisation disponibles ici : http://professionnels.ign + + Prefixed + + + Prefixed:0 + 0 + 1 + 0 + 1 + + + Prefixed:1 + 0 + 2 + 0 + 2 + + + PM @@ -451,5 +470,27 @@ Conditions Générales d'Utilisation disponibles ici : http://professionnels.ign 512 + + Prefixed + EPSG:3857 + + 0 + 559082264.0287178958533332 + -20037508 20037508 + 256 + 256 + 1 + 1 + + + 1 + 279541132.0143588959472254 + -20037508 20037508 + 256 + 256 + 2 + 2 + + diff --git a/test/spec/ol/format/wmtscapabilities.test.js b/test/spec/ol/format/wmtscapabilities.test.js index 44ba44f807..72b907cb3f 100644 --- a/test/spec/ol/format/wmtscapabilities.test.js +++ b/test/spec/ol/format/wmtscapabilities.test.js @@ -136,21 +136,24 @@ describe('ol.format.WMTSCapabilities', function() { const layer = capabilities.Contents.Layer[0]; expect(layer.TileMatrixSetLink).to.be.an('array'); - expect(layer.TileMatrixSetLink).to.have.length(1); - expect(layer.TileMatrixSetLink[0].TileMatrixSet).to.be - .eql('PM'); + expect(layer.TileMatrixSetLink).to.have.length(2); + expect(layer.TileMatrixSetLink[0].TileMatrixSet).to.be.eql('PM'); expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits).to.be.an('array'); expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits).to.have.length(20); - expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].TileMatrix) - .to.be.eql('0'); - expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileRow) - .to.be.eql(0); - expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileRow) - .to.be.eql(1); - expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileCol) - .to.be.eql(0); - expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileCol) - .to.be.eql(1); + expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].TileMatrix).to.be.eql('0'); + expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileRow).to.be.eql(0); + expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileRow).to.be.eql(1); + expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MinTileCol).to.be.eql(0); + expect(layer.TileMatrixSetLink[0].TileMatrixSetLimits[0].MaxTileCol).to.be.eql(1); + + expect(layer.TileMatrixSetLink[1].TileMatrixSet).to.be.eql('Prefixed'); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits).to.be.an('array'); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits).to.have.length(2); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].TileMatrix).to.be.eql('Prefixed:0'); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileRow).to.be.eql(0); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileRow).to.be.eql(1); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MinTileCol).to.be.eql(0); + expect(layer.TileMatrixSetLink[1].TileMatrixSetLimits[0].MaxTileCol).to.be.eql(1); }); diff --git a/test/spec/ol/tilegrid/wmts.test.js b/test/spec/ol/tilegrid/wmts.test.js index 94cb00bc67..d4215c4875 100644 --- a/test/spec/ol/tilegrid/wmts.test.js +++ b/test/spec/ol/tilegrid/wmts.test.js @@ -145,5 +145,30 @@ describe('ol.tilegrid.WMTS', function() { Array.apply(null, Array(20)).map(Number.prototype.valueOf, 256)); }); + + it('can use prefixed matrixLimits', function() { + const matrixSetObj = capabilities.Contents.TileMatrixSet[1]; + const matrixLimitArray = capabilities.Contents.Layer[0].TileMatrixSetLink[1].TileMatrixSetLimits; + const tileGrid = createFromCapabilitiesMatrixSet(matrixSetObj, undefined, matrixLimitArray); + expect(tileGrid.matrixIds_).to.be.an('array'); + expect(tileGrid.matrixIds_).to.have.length(2); + expect(tileGrid.matrixIds_).to.eql(['0', '1']); + + expect(tileGrid.resolutions_).to.be.an('array'); + expect(tileGrid.resolutions_).to.have.length(2); + expect(tileGrid.resolutions_).to.eql([156543.033928041, 78271.51696402048]); + + expect(tileGrid.origins_).to.be.an('array'); + expect(tileGrid.origins_).to.have.length(2); + expect(tileGrid.origins_).to.eql( + Array.apply(null, Array(2)).map(Array.prototype.valueOf, [-20037508, 20037508]) + ); + + expect(tileGrid.tileSizes_).to.be.an('array'); + expect(tileGrid.tileSizes_).to.have.length(2); + expect(tileGrid.tileSizes_).to.eql( + Array.apply(null, Array(2)).map(Number.prototype.valueOf, 256) + ); + }); }); });