From bf798ea76640d3db60360b440f5e4d11e6fbf475 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 20 Feb 2014 19:28:43 +0100 Subject: [PATCH 1/3] Document tierSizeCalculation property --- src/objectliterals.jsdoc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 3730f6e906..7d1c924048 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -930,6 +930,7 @@ * requests. * @property {string|undefined} logo Logo. * @property {!string} url Prefix of URL template. + * @property {string|undefined} tierSizeCalculation Tier size calculation method: `default` or `truncated`. * @property {ol.Size} size Size of the image. * @todo stability experimental */ From 00eff70ae631bbebb600b05cee7ac715303dea47 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 20 Feb 2014 19:29:56 +0100 Subject: [PATCH 2/3] Use an enum for Zoomify tier size calculation option --- src/ol/source/zoomifysource.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ol/source/zoomifysource.js b/src/ol/source/zoomifysource.js index 74aaaca90a..1854149a34 100644 --- a/src/ol/source/zoomifysource.js +++ b/src/ol/source/zoomifysource.js @@ -12,6 +12,15 @@ goog.require('ol.source.TileImage'); goog.require('ol.tilegrid.Zoomify'); +/** + * @enum {string} + */ +ol.source.ZoomifyTierSizeCalculation = { + DEFAULT: 'default', + TRUNCATED: 'truncated' +}; + + /** * @constructor @@ -24,11 +33,9 @@ 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 tierSizeCalculation = goog.isDef(options.tierSizeCalculation) ? + options.tierSizeCalculation : + ol.source.ZoomifyTierSizeCalculation.DEFAULT; var imageWidth = size[0]; var imageHeight = size[1]; From a773ab256c17d04e400a7d7f4089adecbec76891 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 20 Feb 2014 19:30:47 +0100 Subject: [PATCH 3/3] Use a switch to select tier size calculation --- src/ol/source/zoomifysource.js | 46 +++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/ol/source/zoomifysource.js b/src/ol/source/zoomifysource.js index 1854149a34..45cc6febdf 100644 --- a/src/ol/source/zoomifysource.js +++ b/src/ol/source/zoomifysource.js @@ -1,6 +1,7 @@ goog.provide('ol.source.Zoomify'); goog.require('goog.array'); +goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.TagName'); goog.require('ol.ImageTile'); @@ -42,26 +43,31 @@ ol.source.Zoomify = function(opt_options) { var tierSizeInTiles = []; var tileSize = ol.DEFAULT_TILE_SIZE; - 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 >>= 1; - height >>= 1; - } - } else { - while (imageWidth > tileSize || imageHeight > tileSize) { - tierSizeInTiles.push([ - Math.ceil(imageWidth / tileSize), - Math.ceil(imageHeight / tileSize) - ]); - tileSize += tileSize; - } + switch (tierSizeCalculation) { + case ol.source.ZoomifyTierSizeCalculation.DEFAULT: + while (imageWidth > tileSize || imageHeight > tileSize) { + tierSizeInTiles.push([ + Math.ceil(imageWidth / tileSize), + Math.ceil(imageHeight / tileSize) + ]); + tileSize += tileSize; + } + break; + case ol.source.ZoomifyTierSizeCalculation.TRUNCATED: + var width = imageWidth; + var height = imageHeight; + while (width > tileSize || height > tileSize) { + tierSizeInTiles.push([ + Math.ceil(width / tileSize), + Math.ceil(height / tileSize) + ]); + width >>= 1; + height >>= 1; + } + break; + default: + goog.asserts.fail(); + break; } tierSizeInTiles.push([1, 1]);