Skip to content

Commit

Permalink
fix(viewer.js): Avoid rounding zoom factors that are too close to avo…
Browse files Browse the repository at this point in the history
…id duplicated resolution errors (#107)

* Avoid repeated resolutions caused by rounded zoom factors

* Add logs

* Lint
  • Loading branch information
igoroctaviano authored Dec 16, 2024
1 parent a676d22 commit 3fe1dda
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pyramid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3fe1dda

Please sign in to comment.