diff --git a/src/ol/source/WMTS.js b/src/ol/source/WMTS.js index d035d041d5..099578a843 100644 --- a/src/ol/source/WMTS.js +++ b/src/ol/source/WMTS.js @@ -9,7 +9,7 @@ import {assign} from '../obj.js'; import {containsExtent} from '../extent.js'; import {createFromCapabilitiesMatrixSet} from '../tilegrid/WMTS.js'; import {createFromTileUrlFunctions, expandUrl} from '../tileurlfunction.js'; -import {equivalent, get as getProjection} from '../proj.js'; +import {equivalent, get as getProjection, transformExtent} from '../proj.js'; import {find, findIndex, includes} from '../array.js'; /** @@ -497,9 +497,21 @@ export function optionsFromCapabilities(wmtsCap, config) { const wgs84BoundingBox = l['WGS84BoundingBox']; const wgs84ProjectionExtent = getProjection('EPSG:4326').getExtent(); extent = matrixSetExtent; - wrapX = - wgs84BoundingBox[0] === wgs84ProjectionExtent[0] && - wgs84BoundingBox[2] === wgs84ProjectionExtent[2]; + if (wgs84BoundingBox) { + wrapX = + wgs84BoundingBox[0] === wgs84ProjectionExtent[0] && + wgs84BoundingBox[2] === wgs84ProjectionExtent[2]; + } else { + const wgs84MatrixSetExtent = transformExtent( + matrixSetExtent, + matrixSetObj['SupportedCRS'], + 'EPSG:4326' + ); + // Ignore slight deviation from the correct x limits + wrapX = + wgs84MatrixSetExtent[0] - 1e-10 <= wgs84ProjectionExtent[0] && + wgs84MatrixSetExtent[2] + 1e-10 >= wgs84ProjectionExtent[2]; + } } const tileGrid = createFromCapabilitiesMatrixSet( diff --git a/test/browser/spec/ol/format/wmts/capabilities_wrapx.xml b/test/browser/spec/ol/format/wmts/capabilities_wrapx.xml new file mode 100644 index 0000000000..195939ea8f --- /dev/null +++ b/test/browser/spec/ol/format/wmts/capabilities_wrapx.xml @@ -0,0 +1,1101 @@ + + + + OGC WMTS + 1.0.0 + + + + + + + + + + + + + + KVP + + + + + + + + + + + + + KVP + + + + + + + + + + + + + KVP + + + + + + + + + + no-bb + no-bb + + image/png; mode=8bit + + wrap + + + wrap:0 + 0 + 0 + 0 + 0 + + + wrap:1 + 0 + 1 + 0 + 1 + + + wrap:2 + 0 + 3 + 0 + 3 + + + wrap:3 + 0 + 7 + 0 + 7 + + + wrap:4 + 0 + 15 + 0 + 15 + + + wrap:5 + 0 + 31 + 0 + 31 + + + wrap:6 + 0 + 63 + 0 + 63 + + + wrap:7 + 0 + 127 + 0 + 127 + + + wrap:8 + 0 + 255 + 0 + 255 + + + wrap:9 + 0 + 511 + 0 + 511 + + + wrap:10 + 0 + 1023 + 0 + 1023 + + + wrap:11 + 0 + 2047 + 0 + 2047 + + + wrap:12 + 0 + 4095 + 0 + 4095 + + + wrap:13 + 0 + 8191 + 0 + 8191 + + + wrap:14 + 0 + 16383 + 0 + 16383 + + + wrap:15 + 0 + 32767 + 0 + 32767 + + + wrap:16 + 0 + 65535 + 0 + 65535 + + + wrap:17 + 0 + 131071 + 0 + 131071 + + + wrap:18 + 0 + 262143 + 0 + 262143 + + + wrap:19 + 0 + 524287 + 0 + 524287 + + + wrap:20 + 0 + 1048575 + 0 + 1048575 + + + + + + + only-wgs84-bb + only-wgs84-bb + + -180.0 -90.0 + 180.0 90.0 + + + image/png; mode=8bit + + wrap + + + wrap:0 + 0 + 0 + 0 + 0 + + + wrap:1 + 0 + 1 + 0 + 1 + + + wrap:2 + 0 + 3 + 0 + 3 + + + wrap:3 + 0 + 7 + 0 + 7 + + + wrap:4 + 0 + 15 + 0 + 15 + + + wrap:5 + 0 + 31 + 0 + 31 + + + wrap:6 + 0 + 63 + 0 + 63 + + + wrap:7 + 0 + 127 + 0 + 127 + + + wrap:8 + 0 + 255 + 0 + 255 + + + wrap:9 + 0 + 511 + 0 + 511 + + + wrap:10 + 0 + 1023 + 0 + 1023 + + + wrap:11 + 0 + 2047 + 0 + 2047 + + + wrap:12 + 0 + 4095 + 0 + 4095 + + + wrap:13 + 0 + 8191 + 0 + 8191 + + + wrap:14 + 0 + 16383 + 0 + 16383 + + + wrap:15 + 0 + 32767 + 0 + 32767 + + + wrap:16 + 0 + 65535 + 0 + 65535 + + + wrap:17 + 0 + 131071 + 0 + 131071 + + + wrap:18 + 0 + 262143 + 0 + 262143 + + + wrap:19 + 0 + 524287 + 0 + 524287 + + + wrap:20 + 0 + 1048575 + 0 + 1048575 + + + + + + + no-wrap-wgs84-bb + no-wrap-wgs84-bb + + -179.9 -90.0 + 180.0 90.0 + + + image/png; mode=8bit + + wrap + + + wrap:0 + 0 + 0 + 0 + 0 + + + wrap:1 + 0 + 1 + 0 + 1 + + + wrap:2 + 0 + 3 + 0 + 3 + + + wrap:3 + 0 + 7 + 0 + 7 + + + wrap:4 + 0 + 15 + 0 + 15 + + + wrap:5 + 0 + 31 + 0 + 31 + + + wrap:6 + 0 + 63 + 0 + 63 + + + wrap:7 + 0 + 127 + 0 + 127 + + + wrap:8 + 0 + 255 + 0 + 255 + + + wrap:9 + 0 + 511 + 0 + 511 + + + wrap:10 + 0 + 1023 + 0 + 1023 + + + wrap:11 + 0 + 2047 + 0 + 2047 + + + wrap:12 + 0 + 4095 + 0 + 4095 + + + wrap:13 + 0 + 8191 + 0 + 8191 + + + wrap:14 + 0 + 16383 + 0 + 16383 + + + wrap:15 + 0 + 32767 + 0 + 32767 + + + wrap:16 + 0 + 65535 + 0 + 65535 + + + wrap:17 + 0 + 131071 + 0 + 131071 + + + wrap:18 + 0 + 262143 + 0 + 262143 + + + wrap:19 + 0 + 524287 + 0 + 524287 + + + wrap:20 + 0 + 1048575 + 0 + 1048575 + + + + + + + no-wrap-tm + no-wrap-tm + + image/png; mode=8bit + + no-wrap + + + no-wrap:0 + 0 + 0 + 0 + 0 + + + no-wrap:1 + 0 + 1 + 0 + 1 + + + no-wrap:2 + 0 + 3 + 0 + 3 + + + no-wrap:3 + 0 + 7 + 0 + 7 + + + no-wrap:4 + 0 + 15 + 0 + 15 + + + no-wrap:5 + 0 + 31 + 0 + 31 + + + no-wrap:6 + 0 + 63 + 0 + 63 + + + no-wrap:7 + 0 + 127 + 0 + 127 + + + no-wrap:8 + 0 + 255 + 0 + 255 + + + no-wrap:9 + 0 + 511 + 0 + 511 + + + no-wrap:10 + 0 + 1023 + 0 + 1023 + + + no-wrap:11 + 0 + 2047 + 0 + 2047 + + + no-wrap:12 + 0 + 4095 + 0 + 4095 + + + no-wrap:13 + 0 + 8191 + 0 + 8191 + + + no-wrap:14 + 0 + 16383 + 0 + 16383 + + + no-wrap:15 + 0 + 32767 + 0 + 32767 + + + no-wrap:16 + 0 + 65535 + 0 + 65535 + + + no-wrap:17 + 0 + 131071 + 0 + 131071 + + + no-wrap:18 + 0 + 262143 + 0 + 262143 + + + no-wrap:19 + 0 + 524287 + 0 + 524287 + + + no-wrap:20 + 0 + 1048575 + 0 + 1048575 + + + + + + + wrap + + -20037508.342789 -20037508.342789 + 20037508.342789 20037508.342789 + + urn:ogc:def:crs:EPSG:6.3:3857 + + 0 + 559082264.02871787548065185547 + -20037508.342789 20037508.342789 + 256 + 256 + 1 + 1 + + + 1 + 279541132.01435893774032592773 + -20037508.342789 20037508.342789 + 256 + 256 + 2 + 2 + + + 2 + 139770566.00717946887016296387 + -20037508.342789 20037508.342789 + 256 + 256 + 4 + 4 + + + 3 + 69885283.00358973443508148193 + -20037508.342789 20037508.342789 + 256 + 256 + 8 + 8 + + + 4 + 34942641.50179486721754074097 + -20037508.342789 20037508.342789 + 256 + 256 + 16 + 16 + + + 5 + 17471320.75089743360877037048 + -20037508.342789 20037508.342789 + 256 + 256 + 32 + 32 + + + 6 + 8735660.37544871680438518524 + -20037508.342789 20037508.342789 + 256 + 256 + 64 + 64 + + + 7 + 4367830.18772435840219259262 + -20037508.342789 20037508.342789 + 256 + 256 + 128 + 128 + + + 8 + 2183915.09386217920109629631 + -20037508.342789 20037508.342789 + 256 + 256 + 256 + 256 + + + 9 + 1091957.54693108960054814816 + -20037508.342789 20037508.342789 + 256 + 256 + 512 + 512 + + + 10 + 545978.77346554480027407408 + -20037508.342789 20037508.342789 + 256 + 256 + 1024 + 1024 + + + 11 + 272989.38673277240013703704 + -20037508.342789 20037508.342789 + 256 + 256 + 2048 + 2048 + + + 12 + 136494.69336638620006851852 + -20037508.342789 20037508.342789 + 256 + 256 + 4096 + 4096 + + + 13 + 68247.34668319310003425926 + -20037508.342789 20037508.342789 + 256 + 256 + 8192 + 8192 + + + 14 + 34123.67334159655001712963 + -20037508.342789 20037508.342789 + 256 + 256 + 16384 + 16384 + + + 15 + 17061.83667079827500856481 + -20037508.342789 20037508.342789 + 256 + 256 + 32768 + 32768 + + + 16 + 8530.91833539913750428241 + -20037508.342789 20037508.342789 + 256 + 256 + 65536 + 65536 + + + 17 + 4265.45916769956875214120 + -20037508.342789 20037508.342789 + 256 + 256 + 131072 + 131072 + + + 18 + 2132.72958384978437607060 + -20037508.342789 20037508.342789 + 256 + 256 + 262144 + 262144 + + + 19 + 1066.36479192489218803530 + -20037508.342789 20037508.342789 + 256 + 256 + 524288 + 524288 + + + 20 + 533.18239596244609401765 + -20037508.342789 20037508.342789 + 256 + 256 + 1048576 + 1048576 + + + + no-wrap + + -19037508.342789 -20037508.342789 + 20037508.342789 20037508.342789 + + urn:ogc:def:crs:EPSG:6.3:3857 + + 0 + 559082264.02871787548065185547 + -20037508.342789 20037508.342789 + 256 + 256 + 1 + 1 + + + 1 + 279541132.01435893774032592773 + -20037508.342789 20037508.342789 + 256 + 256 + 2 + 2 + + + 2 + 139770566.00717946887016296387 + -20037508.342789 20037508.342789 + 256 + 256 + 4 + 4 + + + 3 + 69885283.00358973443508148193 + -20037508.342789 20037508.342789 + 256 + 256 + 8 + 8 + + + 4 + 34942641.50179486721754074097 + -20037508.342789 20037508.342789 + 256 + 256 + 16 + 16 + + + 5 + 17471320.75089743360877037048 + -20037508.342789 20037508.342789 + 256 + 256 + 32 + 32 + + + 6 + 8735660.37544871680438518524 + -20037508.342789 20037508.342789 + 256 + 256 + 64 + 64 + + + 7 + 4367830.18772435840219259262 + -20037508.342789 20037508.342789 + 256 + 256 + 128 + 128 + + + 8 + 2183915.09386217920109629631 + -20037508.342789 20037508.342789 + 256 + 256 + 256 + 256 + + + 9 + 1091957.54693108960054814816 + -20037508.342789 20037508.342789 + 256 + 256 + 512 + 512 + + + 10 + 545978.77346554480027407408 + -20037508.342789 20037508.342789 + 256 + 256 + 1024 + 1024 + + + 11 + 272989.38673277240013703704 + -20037508.342789 20037508.342789 + 256 + 256 + 2048 + 2048 + + + 12 + 136494.69336638620006851852 + -20037508.342789 20037508.342789 + 256 + 256 + 4096 + 4096 + + + 13 + 68247.34668319310003425926 + -20037508.342789 20037508.342789 + 256 + 256 + 8192 + 8192 + + + 14 + 34123.67334159655001712963 + -20037508.342789 20037508.342789 + 256 + 256 + 16384 + 16384 + + + 15 + 17061.83667079827500856481 + -20037508.342789 20037508.342789 + 256 + 256 + 32768 + 32768 + + + 16 + 8530.91833539913750428241 + -20037508.342789 20037508.342789 + 256 + 256 + 65536 + 65536 + + + 17 + 4265.45916769956875214120 + -20037508.342789 20037508.342789 + 256 + 256 + 131072 + 131072 + + + 18 + 2132.72958384978437607060 + -20037508.342789 20037508.342789 + 256 + 256 + 262144 + 262144 + + + 19 + 1066.36479192489218803530 + -20037508.342789 20037508.342789 + 256 + 256 + 524288 + 524288 + + + 20 + 533.18239596244609401765 + -20037508.342789 20037508.342789 + 256 + 256 + 1048576 + 1048576 + + + + diff --git a/test/browser/spec/ol/source/wmts.test.js b/test/browser/spec/ol/source/wmts.test.js index 69c4599ea2..516b30eb7c 100644 --- a/test/browser/spec/ol/source/wmts.test.js +++ b/test/browser/spec/ol/source/wmts.test.js @@ -458,6 +458,56 @@ describe('ol.source.WMTS', function () { expectDelta(extent[3], expectedMatrixSetExtend[3]); }); }); + describe('set wrap x by bounding box if available', function () { + const parser = new WMTSCapabilities(); + let capabilities; + before(function (done) { + afterLoadText( + 'spec/ol/format/wmts/capabilities_wrapx.xml', + function (xml) { + try { + capabilities = parser.read(xml); + } catch (e) { + done(e); + } + done(); + } + ); + }); + + it('sets wrapx when no bounding box is set', function () { + const options = optionsFromCapabilities(capabilities, { + layer: 'no-bb', + matrixSet: 'EPSG:3857', + crossOrigin: 'anonymous', + }); + expect(options.wrapX).to.be(true); + }); + it('sets wrapx when only wgs 84 bb is set', function () { + const options = optionsFromCapabilities(capabilities, { + layer: 'only-wgs84-bb', + matrixSet: 'EPSG:3857', + crossOrigin: 'anonymous', + }); + expect(options.wrapX).to.be(true); + }); + it('does not set wrapx when wgs84 bb is set', function () { + const options = optionsFromCapabilities(capabilities, { + layer: 'no-wrap-wgs84-bb', + matrixSet: 'EPSG:3857', + crossOrigin: 'anonymous', + }); + expect(options.wrapX).to.be(false); + }); + it('does not set wrapx when tile matrix does not wrap', function () { + const options = optionsFromCapabilities(capabilities, { + layer: 'no-wrap-tm', + matrixSet: 'EPSG:3857', + crossOrigin: 'anonymous', + }); + expect(options.wrapX).to.be(false); + }); + }); describe('when creating options from capabilities with TileMatrixSetLink', function () { const parser = new WMTSCapabilities(); let capabilities;