diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index 51273db0b1..569d6c08b0 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -451,7 +451,7 @@ export function optionsFromCapabilities(wmtsCap, config) { const wrapX = false; const matrix0 = matrixSetObj.TileMatrix[0]; - const resolution = matrix0.ScaleDenominator * 0.00028; // WMTS 1.0.0: standardized rendering pixel size + const resolution = (matrix0.ScaleDenominator * 0.00028) / projection.getMetersPerUnit(); // WMTS 1.0.0: standardized rendering pixel size const origin = projection === getProjection('EPSG:4326') ? [matrix0.TopLeftCorner[1], matrix0.TopLeftCorner[0]] diff --git a/test/spec/ol/format/wmts/capabilities_wgs84.xml b/test/spec/ol/format/wmts/capabilities_wgs84.xml new file mode 100644 index 0000000000..489ff5f5c8 --- /dev/null +++ b/test/spec/ol/format/wmts/capabilities_wgs84.xml @@ -0,0 +1,263 @@ + + + + Sample WMTS + OGC WMTS + 1.0.0 + None + none + + + + + + + + + + + + + + + + + + Baselayer + Baselayer + baselayer + + -180.0 -90.0 + 180.0 90.0 + + + -90.0 -180.0 + 90.0 180.0 + + + image/png + + inspire_quad + + + 0 + 0 + 1 + 0 + 2 + + + 1 + 0 + 2 + 0 + 4 + + + 2 + 0 + 4 + 0 + 8 + + + 3 + 0 + 8 + 0 + 16 + + + 4 + 0 + 16 + 0 + 32 + + + 5 + 0 + 32 + 0 + 64 + + + 6 + 0 + 64 + 0 + 128 + + + 7 + 0 + 128 + 0 + 256 + + + 8 + 0 + 256 + 0 + 512 + + + 9 + 0 + 512 + 0 + 1024 + + + 10 + 0 + 1024 + 0 + 2048 + + + 11 + 0 + 2048 + 0 + 4096 + + + 12 + 0 + 4096 + 0 + 8192 + + + + + + + InspireCRS84Quad + inspire_quad + urn:ogc:def:crs:EPSG::4326 + + 0 + 279541132.014357 + 90.0 -180.0 + 256 + 256 + 2 + 1 + + + 1 + 1.3977056600717938E8 + 90.0 -180.0 + 256 + 256 + 4 + 2 + + + 2 + 6.988528300358969E7 + 90.0 -180.0 + 256 + 256 + 8 + 4 + + + 3 + 3.4942641501794845E7 + 90.0 -180.0 + 256 + 256 + 16 + 8 + + + 4 + 1.7471320750897422E7 + 90.0 -180.0 + 256 + 256 + 32 + 16 + + + 5 + 8735660.375448711 + 90.0 -180.0 + 256 + 256 + 64 + 32 + + + 6 + 4367830.187724356 + 90.0 -180.0 + 256 + 256 + 128 + 64 + + + 7 + 2183915.093862178 + 90.0 -180.0 + 256 + 256 + 256 + 128 + + + 8 + 1091957.546931089 + 90.0 -180.0 + 256 + 256 + 512 + 256 + + + 9 + 545978.7734655445 + 90.0 -180.0 + 256 + 256 + 1024 + 512 + + + 10 + 272989.3867327722 + 90.0 -180.0 + 256 + 256 + 2048 + 1024 + + + 11 + 136494.6933663861 + 90.0 -180.0 + 256 + 256 + 4096 + 2048 + + + 12 + 68247.34668319306 + 90.0 -180.0 + 256 + 256 + 8192 + 4096 + + + + + diff --git a/test/spec/ol/source/wmts.test.js b/test/spec/ol/source/wmts.test.js index 442280fdf8..97daf8e4b6 100644 --- a/test/spec/ol/source/wmts.test.js +++ b/test/spec/ol/source/wmts.test.js @@ -349,6 +349,61 @@ describe('ol.source.WMTS', function () { ); }); }); + + describe('when creating options from wgs84 capabilities', function () { + const parser = new WMTSCapabilities(); + let capabilities, content; + before(function (done) { + afterLoadText('spec/ol/format/wmts/capabilities_wgs84.xml', function (xml) { + try { + content = xml; + capabilities = parser.read(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + + it('returns correct bounding box', function () { + const options = optionsFromCapabilities(capabilities, { + layer: 'baselayer', + matrixSet: 'inspire_quad', + requestEncoding: 'REST', + }); + + expect(options.urls).to.be.an('array'); + expect(options.urls).to.have.length(1); + expect(options.urls[0]).to.be.eql( + 'https://example.com/wmts/baselayer/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png' + ); + + expect(options.layer).to.be.eql('baselayer'); + + expect(options.matrixSet).to.be.eql('inspire_quad'); + + expect(options.format).to.be.eql('image/png'); + + expect(options.projection).to.be.a(Projection); + expect(options.projection).to.be.eql(getProjection('EPSG:4326')); + + expect(options.requestEncoding).to.be.eql('REST'); + + expect(options.tileGrid).to.be.a(WMTSTileGrid); + expect(options.style).to.be.eql('default'); + + const extent = options.tileGrid.getExtent(); + + // compare with delta, due to rounding not the exact bounding box is returned... + const expectDelta = (value, expected) => expect(Math.abs(value - expected)).to.below(1e-10); + + expectDelta(extent[0], -180); + expectDelta(extent[1], -90); + expectDelta(extent[2], 180); + expectDelta(extent[3], 90); + }); + }); describe('#setUrls()', function () { it('sets the URL for the source', function () { @@ -478,5 +533,6 @@ describe('ol.source.WMTS', function () { const requestEncoding = source.getRequestEncoding(); expect(requestEncoding).to.be.eql('REST'); }); - }); + }); + });