Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(viewer.js): Avoid rounding zoom factors that are too close to avoid duplicated resolution errors #107

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading