From 2836f9511f2b79434f4ebeada12f9c1458f5df81 Mon Sep 17 00:00:00 2001 From: Lasse Laakkonen Date: Tue, 31 Oct 2017 09:31:38 +0200 Subject: [PATCH] Remove unnecessary changes to Tile and ImageTile for changing Zoomify source tile size. --- src/ol/imagetile.js | 9 ---- src/ol/source/tile.js | 5 +- src/ol/source/zoomify.js | 109 +++++++++++++++++++++------------------ 3 files changed, 59 insertions(+), 64 deletions(-) diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index 89c60e62fd..139d5b0e46 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -19,7 +19,6 @@ goog.require('ol.events.EventType'); * @param {olx.TileOptions=} opt_options Tile options. */ ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, opt_options) { - var options = opt_options || {}; ol.Tile.call(this, tileCoord, state, opt_options); @@ -52,14 +51,6 @@ ol.ImageTile = function(tileCoord, state, src, crossOrigin, tileLoadFunction, op */ this.tileLoadFunction_ = tileLoadFunction; - var tileCoordZ = tileCoord[0]; - var tileGridTileSize = (options.tileGrid ? options.tileGrid.getTileSize(tileCoordZ) : undefined); - - /** - * @protected - * @type {number} - */ - this.tileSize_ = tileGridTileSize || ol.DEFAULT_TILE_SIZE; }; ol.inherits(ol.ImageTile, ol.Tile); diff --git a/src/ol/source/tile.js b/src/ol/source/tile.js index e110ef9353..ddc39273c3 100644 --- a/src/ol/source/tile.js +++ b/src/ol/source/tile.js @@ -75,10 +75,7 @@ ol.source.Tile = function(options) { * @protected * @type {olx.TileOptions} */ - this.tileOptions = { - transition: options.transition, - tileGrid: this.tileGrid - }; + this.tileOptions = {transition: options.transition}; }; ol.inherits(ol.source.Tile, ol.source.Source); diff --git a/src/ol/source/zoomify.js b/src/ol/source/zoomify.js index e763d00342..2e9db75821 100644 --- a/src/ol/source/zoomify.js +++ b/src/ol/source/zoomify.js @@ -11,6 +11,62 @@ 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 @@ -133,6 +189,8 @@ ol.source.Zoomify = function(opt_options) { var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(urls.map(createFromTemplate)); + ol.source.Zoomify.Tile_ = ZoomifyTileClass.bind(null, tileGrid); + ol.source.TileImage.call(this, { attributions: options.attributions, cacheSize: options.cacheSize, @@ -150,57 +208,6 @@ ol.source.Zoomify = function(opt_options) { ol.inherits(ol.source.Zoomify, ol.source.TileImage); -/** - * @constructor - * @extends {ol.ImageTile} - * @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( - 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; - -}; -ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile); - - -/** - * @inheritDoc - */ -ol.source.Zoomify.Tile_.prototype.getImage = function() { - if (this.zoomifyImage_) { - return this.zoomifyImage_; - } - var tileSize = 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} * @private