From 4ddcfcc0375fab0c45cd67941042c96cfdec1d34 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 18 Jul 2012 23:37:39 +0200 Subject: [PATCH] Add context argument to Tile.getImage to support re-use in DOM renderer --- src/ol/tile.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ol/tile.js b/src/ol/tile.js index 322e234f8a..6ab24d6244 100644 --- a/src/ol/tile.js +++ b/src/ol/tile.js @@ -56,6 +56,12 @@ ol.Tile = function(tileCoord, src, opt_crossOrigin) { this.image_.crossOrigin = opt_crossOrigin; } + /** + * @private + * @type {Object.} + */ + this.imageByContext_ = {}; + /** * @private * @type {Array.} @@ -75,10 +81,25 @@ ol.Tile.prototype.dispatchChangeEvent = function() { /** + * @param {Object=} opt_context Object. * @return {Image} Image. */ -ol.Tile.prototype.getImage = function() { - return this.image_; +ol.Tile.prototype.getImage = function(opt_context) { + if (goog.isDef(opt_context)) { + var image; + var key = goog.getUid(opt_context); + if (key in this.imageByContext_) { + return this.imageByContext_[key]; + } else if (goog.object.isEmpty(this.imageByContext_)) { + image = this.image_; + } else { + image = /** @type {Image} */ this.image_.cloneNode(false); + } + this.imageByContext_[key] = image; + return image; + } else { + return this.image_; + } };