From 3fe1dda032eba6498d8e67cd4d8d1408103438bc Mon Sep 17 00:00:00 2001 From: Igor Octaviano Date: Mon, 16 Dec 2024 16:11:58 -0500 Subject: [PATCH] fix(viewer.js): Avoid rounding zoom factors that are too close to avoid duplicated resolution errors (#107) * Avoid repeated resolutions caused by rounded zoom factors * Add logs * Lint --- src/pyramid.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pyramid.js b/src/pyramid.js index 4ae2abba..035f0f30 100644 --- a/src/pyramid.js +++ b/src/pyramid.js @@ -204,15 +204,22 @@ 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 - ) + if (pyramidResolutions.includes(roundedZoomFactor)) { + console.warn('resolution conflict rounding zoom factor (baseTotalPixelMatrixColumns / totalPixelMatrixColumns): ', zoomFactor) + zoomFactor = parseFloat(zoomFactor.toFixed(2)) + } else { + zoomFactor = roundedZoomFactor + } pyramidResolutions.push(zoomFactor) - pyramidOrigins.push(offset) } pyramidResolutions.reverse()