From bd89d1f22718716132f89444b8951b97e2a16b9b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 31 Aug 2016 08:59:47 -0600 Subject: [PATCH] Remove unused context arg for tile.getImage() --- src/ol/imagetile.js | 19 ++------------- src/ol/reproj/tile.js | 25 ++----------------- src/ol/source/tiledebug.js | 17 +++++-------- src/ol/source/tileutfgrid.js | 4 +-- src/ol/source/zoomify.js | 38 +++++++++++++---------------- src/ol/tile.js | 3 +-- test/spec/ol/source/zoomify.test.js | 28 ++------------------- 7 files changed, 31 insertions(+), 103 deletions(-) diff --git a/src/ol/imagetile.js b/src/ol/imagetile.js index a78f61619c..883bfe071b 100644 --- a/src/ol/imagetile.js +++ b/src/ol/imagetile.js @@ -4,7 +4,6 @@ goog.require('ol'); goog.require('ol.Tile'); goog.require('ol.events'); goog.require('ol.events.EventType'); -goog.require('ol.obj'); /** @@ -80,22 +79,8 @@ ol.ImageTile.prototype.disposeInternal = function() { * @inheritDoc * @api */ -ol.ImageTile.prototype.getImage = function(opt_context) { - if (opt_context !== undefined) { - var image; - var key = ol.getUid(opt_context); - if (key in this.imageByContext_) { - return this.imageByContext_[key]; - } else if (ol.obj.isEmpty(this.imageByContext_)) { - image = this.image_; - } else { - image = /** @type {Image} */ (this.image_.cloneNode(false)); - } - this.imageByContext_[key] = image; - return image; - } else { - return this.image_; - } +ol.ImageTile.prototype.getImage = function() { + return this.image_; }; diff --git a/src/ol/reproj/tile.js b/src/ol/reproj/tile.js index 5b6ff75ae6..b62493ed33 100644 --- a/src/ol/reproj/tile.js +++ b/src/ol/reproj/tile.js @@ -6,7 +6,6 @@ goog.require('ol.events'); goog.require('ol.events.EventType'); goog.require('ol.extent'); goog.require('ol.math'); -goog.require('ol.obj'); goog.require('ol.reproj'); goog.require('ol.reproj.Triangulation'); @@ -62,12 +61,6 @@ ol.reproj.Tile = function(sourceProj, sourceTileGrid, */ this.canvas_ = null; - /** - * @private - * @type {Object.} - */ - this.canvasByContext_ = {}; - /** * @private * @type {ol.tilegrid.TileGrid} @@ -216,22 +209,8 @@ ol.reproj.Tile.prototype.disposeInternal = function() { /** * @inheritDoc */ -ol.reproj.Tile.prototype.getImage = function(opt_context) { - if (opt_context !== undefined) { - var image; - var key = ol.getUid(opt_context); - if (key in this.canvasByContext_) { - return this.canvasByContext_[key]; - } else if (ol.obj.isEmpty(this.canvasByContext_)) { - image = this.canvas_; - } else { - image = /** @type {HTMLCanvasElement} */ (this.canvas_.cloneNode(false)); - } - this.canvasByContext_[key] = image; - return image; - } else { - return this.canvas_; - } +ol.reproj.Tile.prototype.getImage = function() { + return this.canvas_; }; diff --git a/src/ol/source/tiledebug.js b/src/ol/source/tiledebug.js index 0ef9e0439c..108461c63e 100644 --- a/src/ol/source/tiledebug.js +++ b/src/ol/source/tiledebug.js @@ -79,9 +79,9 @@ ol.source.TileDebug.Tile_ = function(tileCoord, tileSize, text) { /** * @private - * @type {Object.} + * @type {HTMLCanvasElement} */ - this.canvasByContext_ = {}; + this.canvas_ = null; }; ol.inherits(ol.source.TileDebug.Tile_, ol.Tile); @@ -89,16 +89,12 @@ ol.inherits(ol.source.TileDebug.Tile_, ol.Tile); /** * Get the image element for this tile. - * @param {Object=} opt_context Optional context. Only used by the DOM - * renderer. * @return {HTMLCanvasElement} Image. */ -ol.source.TileDebug.Tile_.prototype.getImage = function(opt_context) { - var key = opt_context !== undefined ? ol.getUid(opt_context) : -1; - if (key in this.canvasByContext_) { - return this.canvasByContext_[key]; +ol.source.TileDebug.Tile_.prototype.getImage = function() { + if (this.canvas_) { + return this.canvas_; } else { - var tileSize = this.tileSize_; var context = ol.dom.createCanvasContext2D(tileSize[0], tileSize[1]); @@ -111,8 +107,7 @@ ol.source.TileDebug.Tile_.prototype.getImage = function(opt_context) { context.font = '24px sans-serif'; context.fillText(this.text_, tileSize[0] / 2, tileSize[1] / 2); - this.canvasByContext_[key] = context.canvas; + this.canvas_ = context.canvas; return context.canvas; - } }; diff --git a/src/ol/source/tileutfgrid.js b/src/ol/source/tileutfgrid.js index 5bef4b55db..0e897d3763 100644 --- a/src/ol/source/tileutfgrid.js +++ b/src/ol/source/tileutfgrid.js @@ -322,11 +322,9 @@ ol.inherits(ol.source.TileUTFGrid.Tile_, ol.Tile); /** * Get the image element for this tile. - * @param {Object=} opt_context Optional context. Only used for the DOM - * renderer. * @return {Image} Image. */ -ol.source.TileUTFGrid.Tile_.prototype.getImage = function(opt_context) { +ol.source.TileUTFGrid.Tile_.prototype.getImage = function() { return null; }; diff --git a/src/ol/source/zoomify.js b/src/ol/source/zoomify.js index 932ffc9a61..b5f62ea3f8 100644 --- a/src/ol/source/zoomify.js +++ b/src/ol/source/zoomify.js @@ -140,10 +140,9 @@ ol.source.Zoomify.Tile_ = function( /** * @private - * @type {Object.} + * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} */ - this.zoomifyImageByContext_ = {}; + this.zoomifyImage_ = null; }; ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile); @@ -152,27 +151,24 @@ ol.inherits(ol.source.Zoomify.Tile_, ol.ImageTile); /** * @inheritDoc */ -ol.source.Zoomify.Tile_.prototype.getImage = function(opt_context) { +ol.source.Zoomify.Tile_.prototype.getImage = function() { + if (this.zoomifyImage_) { + return this.zoomifyImage_; + } var tileSize = ol.DEFAULT_TILE_SIZE; - var key = opt_context !== undefined ? - ol.getUid(opt_context).toString() : ''; - if (key in this.zoomifyImageByContext_) { - return this.zoomifyImageByContext_[key]; - } else { - var image = ol.ImageTile.prototype.getImage.call(this, opt_context); - if (this.state == ol.Tile.State.LOADED) { - if (image.width == tileSize && image.height == tileSize) { - this.zoomifyImageByContext_[key] = image; - return image; - } else { - var context = ol.dom.createCanvasContext2D(tileSize, tileSize); - context.drawImage(image, 0, 0); - this.zoomifyImageByContext_[key] = context.canvas; - return context.canvas; - } - } else { + var image = ol.ImageTile.prototype.getImage.call(this); + if (this.state == ol.Tile.State.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; } }; diff --git a/src/ol/tile.js b/src/ol/tile.js index 6f7bf34084..55e34f0842 100644 --- a/src/ol/tile.js +++ b/src/ol/tile.js @@ -60,10 +60,9 @@ ol.Tile.prototype.changed = function() { /** * Get the HTML image element for this tile (may be a Canvas, Image, or Video). * @abstract - * @param {Object=} opt_context Object. * @return {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement} Image. */ -ol.Tile.prototype.getImage = function(opt_context) {}; +ol.Tile.prototype.getImage = function() {}; /** diff --git a/test/spec/ol/source/zoomify.test.js b/test/spec/ol/source/zoomify.test.js index 44b4b36e71..9bd4ae9597 100644 --- a/test/spec/ol/source/zoomify.test.js +++ b/test/spec/ol/source/zoomify.test.js @@ -216,20 +216,18 @@ describe('ol.source.Zoomify', function() { }); it('"tile.getImage" returns and caches a loaded canvas', function(done) { - // It'll only cache if the same context is passed, see below - var context = ol.dom.createCanvasContext2D(256, 256); var source = getZoomifySource(); var tile = source.getTile(0, 0, -1, 1, proj); ol.events.listen(tile, 'change', function() { if (tile.getState() == 2) { // LOADED - var img = tile.getImage(context); + var img = tile.getImage(); expect(img).to.be.a(HTMLCanvasElement); var tile2 = source.getTile(0, 0, -1, 1, proj); expect(tile2.getState()).to.be(2); // LOADED - var img2 = tile2.getImage(context); + var img2 = tile2.getImage(); expect(img).to.be(img2); done(); } @@ -237,28 +235,6 @@ describe('ol.source.Zoomify', function() { tile.load(); }); - it('"tile.getImage" returns and caches an image only for same context', function() { - var source = getZoomifySource(); - - var tile = source.getTile(0, 0, -1, 1, proj); - var img = tile.getImage(ol.dom.createCanvasContext2D(256, 256)); - - var tile2 = source.getTile(0, 0, -1, 1, proj); - var img2 = tile2.getImage(ol.dom.createCanvasContext2D(256, 256)); - - expect(img).to.be.a(HTMLImageElement); - expect(img).to.not.be(img2); - }); - - it('passing the context to "tile.getImage" is optional', function() { - var source = getZoomifySource(); - - var tile = source.getTile(0, 0, -1, 1, proj); - var img = tile.getImage(); - - expect(img).to.be.a(HTMLImageElement); - }); - }); });