From ac785459da7e910cff6d13af16c2e45331b3724a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Girault?= Date: Thu, 20 Feb 2014 11:17:16 +0100 Subject: [PATCH] Add an alternative algorithm for zoomify tier size calculation Zoomify uses a different algorithm than ol3 to calculate the number of tiles per tier. These algorithms are compatible in most cases, but they will lead to different results with some particular image sizes. This update provides an option for the zoomify source to use one of these two algorithms. --- src/ol/source/zoomifysource.js | 35 +++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/ol/source/zoomifysource.js b/src/ol/source/zoomifysource.js index 011b8056ca..f2cb3dfbfa 100644 --- a/src/ol/source/zoomifysource.js +++ b/src/ol/source/zoomifysource.js @@ -24,18 +24,39 @@ ol.source.Zoomify = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; var size = options.size; + var tierSizeCalculation = 'default'; + + if (goog.isDef(options.tierSizeCalculation)) { + tierSizeCalculation = options.tierSizeCalculation; + } + var imageWidth = size[0]; var imageHeight = size[1]; - var tierSizeInTiles = []; var tileSize = ol.DEFAULT_TILE_SIZE; - while (imageWidth > tileSize || imageHeight > tileSize) { - tierSizeInTiles.push([ - Math.ceil(imageWidth / tileSize), - Math.ceil(imageHeight / tileSize) - ]); - tileSize += tileSize; + + if (tierSizeCalculation === 'truncated') { + var width = imageWidth; + var height = imageHeight; + + while (width > tileSize || height > tileSize) { + tierSizeInTiles.push([ + Math.ceil(width / tileSize), + Math.ceil(height / tileSize) + ]); + width = parseInt(width / 2, 10); + height = parseInt(height / 2, 10); + } + } else { + while (imageWidth > tileSize || imageHeight > tileSize) { + tierSizeInTiles.push([ + Math.ceil(imageWidth / tileSize), + Math.ceil(imageHeight / tileSize) + ]); + tileSize += tileSize; + } } + tierSizeInTiles.push([1, 1]); tierSizeInTiles.reverse();