Use TileMatrixSetLimit for extent calculation when available.

This commit is contained in:
Niels Meijer
2020-04-29 16:03:33 +02:00
parent 88ffc559cc
commit 9cab1215c0
3 changed files with 134 additions and 49 deletions
+29 -10
View File
@@ -451,20 +451,39 @@ export function optionsFromCapabilities(wmtsCap, config) {
const wrapX = false; const wrapX = false;
const switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne'; const switchOriginXY = projection.getAxisOrientation().substr(0, 2) == 'ne';
const matrix0 = matrixSetObj.TileMatrix[0]; let matrix = matrixSetObj.TileMatrix[0];
// create default matrixLimit
let selectedMatrixLimit = {
MinTileCol: 0,
MinTileRow: 0,
// substract one to end up at tile top left
MaxTileCol: matrix.MatrixWidth - 1,
MaxTileRow: matrix.MatrixHeight - 1,
};
//in case of matrix limits, use matrix limits to calculate extent
if (matrixLimits) {
selectedMatrixLimit = matrixLimits[matrixLimits.length - 1];
matrix = matrixSetObj.TileMatrix.find(
(value) => value.Identifier === selectedMatrixLimit.TileMatrix
);
}
const resolution = const resolution =
(matrix0.ScaleDenominator * 0.00028) / projection.getMetersPerUnit(); // WMTS 1.0.0: standardized rendering pixel size (matrix.ScaleDenominator * 0.00028) / projection.getMetersPerUnit(); // WMTS 1.0.0: standardized rendering pixel size
const origin = switchOriginXY const origin = switchOriginXY
? [matrix0.TopLeftCorner[1], matrix0.TopLeftCorner[0]] ? [matrix.TopLeftCorner[1], matrix.TopLeftCorner[0]]
: matrix0.TopLeftCorner; : matrix.TopLeftCorner;
const tileSpanX = matrix0.TileWidth * resolution; const tileSpanX = matrix.TileWidth * resolution;
const tileSpanY = matrix0.TileHeight * resolution; const tileSpanY = matrix.TileHeight * resolution;
const extent = [ const extent = [
origin[0], origin[0] + tileSpanX * selectedMatrixLimit.MinTileCol,
origin[1] - tileSpanY * matrix0.MatrixHeight, // add one to get proper bottom/right coordinate
origin[0] + tileSpanX * matrix0.MatrixWidth, origin[1] - tileSpanY * (1 + selectedMatrixLimit.MaxTileRow),
origin[1], origin[0] + tileSpanX * (1 + selectedMatrixLimit.MaxTileCol),
origin[1] - tileSpanY * selectedMatrixLimit.MinTileRow,
]; ];
if (projection.getExtent() === null) { if (projection.getExtent() === null) {
+60 -39
View File
@@ -38,103 +38,124 @@
<ows:Identifier>default</ows:Identifier> <ows:Identifier>default</ows:Identifier>
</Style> </Style>
<Format>image/png</Format> <Format>image/png</Format>
<TileMatrixSetLink>
<TileMatrixSet>inspire_quad</TileMatrixSet>
</TileMatrixSetLink>
<ResourceURL format="image/png" resourceType="tile" template="https://example.com/wmts/baselayer/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png"/>
</Layer>
<Layer>
<ows:Title>Mean depth full coverage with land coverage</ows:Title>
<ows:Abstract></ows:Abstract>
<ows:Identifier>mean_atlas_land</ows:Identifier>
<ows:WGS84BoundingBox>
<ows:LowerCorner>-36.0 15.0</ows:LowerCorner>
<ows:UpperCorner>43.0 90.0</ows:UpperCorner>
</ows:WGS84BoundingBox>
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::4326">
<ows:LowerCorner>14.999942759061003 -36.0</ows:LowerCorner>
<ows:UpperCorner>90.0 42.999938986416</ows:UpperCorner>
</ows:BoundingBox>
<Style>
<ows:Identifier>default</ows:Identifier>
</Style>
<Format>image/png</Format>
<TileMatrixSetLink> <TileMatrixSetLink>
<TileMatrixSet>inspire_quad</TileMatrixSet> <TileMatrixSet>inspire_quad</TileMatrixSet>
<TileMatrixSetLimits> <TileMatrixSetLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>0</TileMatrix> <TileMatrix>0</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>1</MaxTileRow> <MaxTileRow>0</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>0</MinTileCol>
<MaxTileCol>2</MaxTileCol> <MaxTileCol>1</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>1</TileMatrix> <TileMatrix>1</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>2</MaxTileRow> <MaxTileRow>0</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>1</MinTileCol>
<MaxTileCol>4</MaxTileCol> <MaxTileCol>2</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>2</TileMatrix> <TileMatrix>2</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>4</MaxTileRow> <MaxTileRow>1</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>3</MinTileCol>
<MaxTileCol>8</MaxTileCol> <MaxTileCol>4</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>3</TileMatrix> <TileMatrix>3</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>8</MaxTileRow> <MaxTileRow>3</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>6</MinTileCol>
<MaxTileCol>16</MaxTileCol> <MaxTileCol>9</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>4</TileMatrix> <TileMatrix>4</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>16</MaxTileRow> <MaxTileRow>6</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>12</MinTileCol>
<MaxTileCol>32</MaxTileCol> <MaxTileCol>19</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>5</TileMatrix> <TileMatrix>5</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>32</MaxTileRow> <MaxTileRow>13</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>25</MinTileCol>
<MaxTileCol>64</MaxTileCol> <MaxTileCol>39</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>6</TileMatrix> <TileMatrix>6</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>64</MaxTileRow> <MaxTileRow>26</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>51</MinTileCol>
<MaxTileCol>128</MaxTileCol> <MaxTileCol>79</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>7</TileMatrix> <TileMatrix>7</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>128</MaxTileRow> <MaxTileRow>53</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>102</MinTileCol>
<MaxTileCol>256</MaxTileCol> <MaxTileCol>158</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>8</TileMatrix> <TileMatrix>8</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>256</MaxTileRow> <MaxTileRow>106</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>204</MinTileCol>
<MaxTileCol>512</MaxTileCol> <MaxTileCol>317</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>9</TileMatrix> <TileMatrix>9</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>512</MaxTileRow> <MaxTileRow>213</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>409</MinTileCol>
<MaxTileCol>1024</MaxTileCol> <MaxTileCol>634</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>10</TileMatrix> <TileMatrix>10</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>1024</MaxTileRow> <MaxTileRow>426</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>819</MinTileCol>
<MaxTileCol>2048</MaxTileCol> <MaxTileCol>1268</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>11</TileMatrix> <TileMatrix>11</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>2048</MaxTileRow> <MaxTileRow>853</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>1638</MinTileCol>
<MaxTileCol>4096</MaxTileCol> <MaxTileCol>2537</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
<TileMatrixLimits> <TileMatrixLimits>
<TileMatrix>12</TileMatrix> <TileMatrix>12</TileMatrix>
<MinTileRow>0</MinTileRow> <MinTileRow>0</MinTileRow>
<MaxTileRow>4096</MaxTileRow> <MaxTileRow>1706</MaxTileRow>
<MinTileCol>0</MinTileCol> <MinTileCol>3276</MinTileCol>
<MaxTileCol>8192</MaxTileCol> <MaxTileCol>5074</MaxTileCol>
</TileMatrixLimits> </TileMatrixLimits>
</TileMatrixSetLimits> </TileMatrixSetLimits>
</TileMatrixSetLink> </TileMatrixSetLink>
<ResourceURL format="image/png" resourceType="tile" template="https://example.com/wmts/baselayer/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png"/> <ResourceURL format="image/png" resourceType="tile" template="https://example.com/wmts/mean_atlas_land/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png"/>
</Layer> </Layer>
<TileMatrixSet> <TileMatrixSet>
<ows:Title>InspireCRS84Quad</ows:Title> <ows:Title>InspireCRS84Quad</ows:Title>
+45
View File
@@ -404,6 +404,51 @@ describe('ol.source.WMTS', function () {
expectDelta(extent[2], 180); expectDelta(extent[2], 180);
expectDelta(extent[3], 90); expectDelta(extent[3], 90);
}); });
it('returns correct bounding box for a layer restricted by TileMatrixSetLink', function () {
const options = optionsFromCapabilities(capabilities, {
layer: 'mean_atlas_land',
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/mean_atlas_land/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png'
);
expect(options.layer).to.be.eql('mean_atlas_land');
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();
// calculate with of one tile, this will be used as tolerance for result extent
const tile_width =
((68247.34668319306 * 0.00028) /
getProjection('EPSG:4326').getMetersPerUnit()) *
256;
// compare with delta, due to rounding not the exact bounding box is returned...
const expectDelta = (value, expected) =>
expect(Math.abs(value - expected)).to.below(tile_width + 1e-10);
expectDelta(extent[0], -36);
expectDelta(extent[1], 15);
expectDelta(extent[2], 43);
expectDelta(extent[3], 90);
});
}); });
describe('#setUrls()', function () { describe('#setUrls()', function () {