mapfish / mapfish-print

A component of MapFish for printing templated cartographic maps. This module is the Java serverside module.
http://mapfish.github.io/mapfish-print-doc/
BSD 2-Clause "Simplified" License
183 stars 417 forks source link

WMTS tile out of bound #3255

Open ltshb opened 3 months ago

ltshb commented 3 months ago

Context

Describe the bug

When printing a WMTS layer where the layer bounds is smaller than the printing view, mapfish make HTTP requests to non existing tiles (negative row/column or row/column out of the layer bounds). This is especially an issue when using the flag FailOnError on the layer.

How to reproduce

{"attributes":{"map":{"center":[2560791.0814865665,1193225.5567907495],"dpi":96,"projection":"EPSG:2056","rotation":0,"scale":2500000,"layers":[{"type":"wmts","baseURL":"https://sys-wmts.dev.bgdi.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/2056/{TileMatrix}/{TileCol}/{TileRow}.jpeg","dimensions":["Time"],"dimensionParams":{"Time":"current"},"imageFormat":"jpeg","layer":"ch.swisstopo.pixelkarte-farbe","matrices":[{"identifier":0,"scaleDenominator":14285714.285714287,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":1,"scaleDenominator":13392857.142857144,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":2,"scaleDenominator":12500000.000000002,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":3,"scaleDenominator":11607142.857142858,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":4,"scaleDenominator":10714285.714285715,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":5,"scaleDenominator":9821428.571428573,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":6,"scaleDenominator":8928571.42857143,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":7,"scaleDenominator":8035714.285714286,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":8,"scaleDenominator":7142857.142857144,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1,1]},{"identifier":9,"scaleDenominator":6250000.000000001,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[2,1]},{"identifier":10,"scaleDenominator":5357142.857142857,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[2,1]},{"identifier":11,"scaleDenominator":4464285.714285715,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[2,1]},{"identifier":12,"scaleDenominator":3571428.571428572,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[2,2]},{"identifier":13,"scaleDenominator":2678571.4285714286,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[3,2]},{"identifier":14,"scaleDenominator":2321428.571428572,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[3,2]},{"identifier":15,"scaleDenominator":1785714.285714286,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[4,3]},{"identifier":16,"scaleDenominator":892857.142857143,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[8,5]},{"identifier":17,"scaleDenominator":357142.85714285716,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[19,13]},{"identifier":18,"scaleDenominator":178571.42857142858,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[38,25]},{"identifier":19,"scaleDenominator":71428.57142857143,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[94,63]},{"identifier":20,"scaleDenominator":35714.28571428572,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[188,125]},{"identifier":21,"scaleDenominator":17857.14285714286,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[375,250]},{"identifier":22,"scaleDenominator":8928.57142857143,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[750,500]},{"identifier":23,"scaleDenominator":7142.857142857143,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[938,625]},{"identifier":24,"scaleDenominator":5357.142857142858,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1250,834]},{"identifier":25,"scaleDenominator":3571.4285714285716,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[1875,1250]},{"identifier":26,"scaleDenominator":1785.7142857142858,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[3750,2500]},{"identifier":27,"scaleDenominator":892.8571428571429,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[7500,5000]},{"identifier":28,"scaleDenominator":357.14285714285717,"tileSize":[256,256],"topLeftCorner":[2420000,1350000],"matrixSize":[18750,12500]}],"matrixSet":"EPSG:2056","opacity":1,"requestEncoding":"REST","version":"1.0.0","failOnError":true}]},"copyright":"","url":"https://sys-s.dev.bgdi.ch/8zkquzu0sbkp","qrimage":"https://sys-map.dev.bgdi.ch/api/qrcode/generate?url=https%3A%2F%2Fsys-s.dev.bgdi.ch%2F8zkquzu0sbkp","printLegend":0},"format":"pdf","layout":"3. A3 landscape","lang":"de","outputFilename":"sys-map.dev.bgdi.ch_${yyyy-MM-dd'T'HH-mm-ss'Z'}"}

Actual results

Although the tile matrix for zoom 14 specifies that the service has max 3 column and 2 rows, it seems to try to get the tile col 3, see log below

"stack_trace": "java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Error making tile request: https://sys-wmts.dev.bgdi.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/2056/14/3/0.jpeg\n\tStatus: 400 BAD_REQUEST\n\tStatus message: Bad Request\n\tat java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)

Logs mapfishprint-log.txt

Expected results

From what I've seen and understand in the code, mapfish don't check if the tile is in the bound provided by the matrixSize of the payload. It would be good that it does the check and avoid calling tile outside of the matrixSize provided in the payload.

NOTE: This issue has been found while integrating mapfish with the new web mapviewer for map.geo.admin.ch (see https://github.com/geoadmin/web-mapviewer)