diff --git a/src/ol/source/zoomify.js b/src/ol/source/zoomify.js index 2e9db75821..74b7a63ed2 100644 --- a/src/ol/source/zoomify.js +++ b/src/ol/source/zoomify.js @@ -11,62 +11,6 @@ goog.require('ol.source.TileImage'); goog.require('ol.tilegrid.TileGrid'); -/** - * @constructor - * @extends {ol.ImageTile} - * @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to. - * @param {ol.TileCoord} tileCoord Tile coordinate. - * @param {ol.TileState} state State. - * @param {string} src Image source URI. - * @param {?string} crossOrigin Cross origin. - * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. - * @param {olx.TileOptions=} opt_options Tile options. - * @private - */ -var ZoomifyTileClass = function( - tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { - - ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options); - - /** - * @private - * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} - */ - this.zoomifyImage_ = null; - - /** - * @private - * @type {ol.Size|number} - */ - this.tileSize_ = tileGrid.getTileSize(tileCoord[0]); -}; -ol.inherits(ZoomifyTileClass, ol.ImageTile); - - -/** - * @inheritDoc - */ -ZoomifyTileClass.prototype.getImage = function() { - if (this.zoomifyImage_) { - return this.zoomifyImage_; - } - var tileSize = (Array.isArray(this.tileSize_) ? this.tileSize_[0] : this.tileSize_); - var image = ol.ImageTile.prototype.getImage.call(this); - if (this.state == ol.TileState.LOADED) { - if (image.width == tileSize && image.height == tileSize) { - this.zoomifyImage_ = image; - return image; - } else { - var context = ol.dom.createCanvasContext2D(tileSize, tileSize); - context.drawImage(image, 0, 0); - this.zoomifyImage_ = context.canvas; - return context.canvas; - } - } else { - return image; - } -}; - /** * @classdesc * Layer source for tile data in Zoomify format (both Zoomify and Internet @@ -189,7 +133,7 @@ ol.source.Zoomify = function(opt_options) { var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate)); - ol.source.Zoomify.Tile_ = ZoomifyTileClass.bind(null, tileGrid); + var ZoomifyTileClass = ol.source.Zoomify.Tile_.bind(null, tileGrid); ol.source.TileImage.call(this, { attributions: options.attributions, @@ -198,7 +142,7 @@ ol.source.Zoomify = function(opt_options) { logo: options.logo, projection: options.projection, reprojectionErrorThreshold: options.reprojectionErrorThreshold, - tileClass: ol.source.Zoomify.Tile_, + tileClass: ZoomifyTileClass, tileGrid: tileGrid, tileUrlFunction: tileUrlFunction, transition: options.transition @@ -207,6 +151,61 @@ ol.source.Zoomify = function(opt_options) { }; ol.inherits(ol.source.Zoomify, ol.source.TileImage); +/** + * @constructor + * @extends {ol.ImageTile} + * @param {ol.tilegrid.TileGrid} tileGrid TileGrid that the tile belongs to. + * @param {ol.TileCoord} tileCoord Tile coordinate. + * @param {ol.TileState} state State. + * @param {string} src Image source URI. + * @param {?string} crossOrigin Cross origin. + * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function. + * @param {olx.TileOptions=} opt_options Tile options. + * @private + */ +ol.source.Zoomify.Tile_ = function( + tileGrid, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { + + ol.ImageTile.call(this, tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options); + + /** + * @private + * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} + */ + this.zoomifyImage_ = null; + + /** + * @private + * @type {ol.Size|number} + */ + this.tileSize_ = tileGrid.getTileSize(tileCoord[0]); +}; +ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile); + + +/** + * @inheritDoc + */ +ol.source.Zoomify.Tile_.prototype.getImage = function() { + if (this.zoomifyImage_) { + return this.zoomifyImage_; + } + var tileSize = (Array.isArray(this.tileSize_) ? this.tileSize_[0] : this.tileSize_); + var image = ol.ImageTile.prototype.getImage.call(this); + if (this.state == ol.TileState.LOADED) { + if (image.width == tileSize && image.height == tileSize) { + this.zoomifyImage_ = image; + return image; + } else { + var context = ol.dom.createCanvasContext2D(tileSize, tileSize); + context.drawImage(image, 0, 0); + this.zoomifyImage_ = context.canvas; + return context.canvas; + } + } else { + return image; + } +}; /** * @enum {string} diff --git a/test/spec/ol/source/zoomify.test.js b/test/spec/ol/source/zoomify.test.js index 4b202e0164..72cde203db 100644 --- a/test/spec/ol/source/zoomify.test.js +++ b/test/spec/ol/source/zoomify.test.js @@ -248,11 +248,6 @@ describe('ol.source.Zoomify', function() { describe('uses a custom tileClass', function() { - it('uses "ol.source.Zoomify.Tile_" as tileClass', function() { - var source = getZoomifySource(); - expect(source.tileClass).to.be(ol.source.Zoomify.Tile_); - }); - it('returns expected tileClass instances via "getTile"', function() { var source = getZoomifySource(); var tile = source.getTile(0, 0, -1, 1, proj);