From c01a6d4a4fb82aebf854686ed9c1bc2d713c9054 Mon Sep 17 00:00:00 2001 From: Igor Octaviano Date: Tue, 31 Oct 2023 10:29:49 -0300 Subject: [PATCH] Avoid repeated resolutions caused by rounded zoom factors --- src/pyramid.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pyramid.js b/src/pyramid.js index 4ae2abba..36218c1d 100644 --- a/src/pyramid.js +++ b/src/pyramid.js @@ -204,13 +204,18 @@ function _computeImagePyramid ({ metadata }) { (totalPixelMatrixColumns * pixelSpacing[1]).toFixed(4), (totalPixelMatrixRows * pixelSpacing[0]).toFixed(4) ]) + let zoomFactor = baseTotalPixelMatrixColumns / totalPixelMatrixColumns + const roundedZoomFactor = Math.round(zoomFactor) /* * Compute the resolution at each pyramid level, since the zoom * factor may not be the same between adjacent pyramid levels. + * + * Round is conditional to avoid openlayers resolutions error. + * The resolutions array should be composed of unique values in descending order. */ - const zoomFactor = Math.round( - baseTotalPixelMatrixColumns / totalPixelMatrixColumns - ) + zoomFactor = pyramidResolutions.includes(roundedZoomFactor) + ? zoomFactor.toFixed(3) + : roundedZoomFactor pyramidResolutions.push(zoomFactor) pyramidOrigins.push(offset)