Skip to content

Commit 3fe1dda

Browse files
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
1 parent a676d22 commit 3fe1dda

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/pyramid.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,22 @@ function _computeImagePyramid ({ metadata }) {
204204
(totalPixelMatrixColumns * pixelSpacing[1]).toFixed(4),
205205
(totalPixelMatrixRows * pixelSpacing[0]).toFixed(4)
206206
])
207+
let zoomFactor = baseTotalPixelMatrixColumns / totalPixelMatrixColumns
208+
const roundedZoomFactor = Math.round(zoomFactor)
207209
/*
208210
* Compute the resolution at each pyramid level, since the zoom
209211
* factor may not be the same between adjacent pyramid levels.
212+
*
213+
* Round is conditional to avoid openlayers resolutions error.
214+
* The resolutions array should be composed of unique values in descending order.
210215
*/
211-
const zoomFactor = Math.round(
212-
baseTotalPixelMatrixColumns / totalPixelMatrixColumns
213-
)
216+
if (pyramidResolutions.includes(roundedZoomFactor)) {
217+
console.warn('resolution conflict rounding zoom factor (baseTotalPixelMatrixColumns / totalPixelMatrixColumns): ', zoomFactor)
218+
zoomFactor = parseFloat(zoomFactor.toFixed(2))
219+
} else {
220+
zoomFactor = roundedZoomFactor
221+
}
214222
pyramidResolutions.push(zoomFactor)
215-
216223
pyramidOrigins.push(offset)
217224
}
218225
pyramidResolutions.reverse()

0 commit comments

Comments
 (0)