Add context argument to Tile.getImage to support re-use in DOM renderer

This commit is contained in:
Tom Payne
2012-07-18 23:37:39 +02:00
parent eb43cf14c1
commit 4ddcfcc037

View File

@@ -56,6 +56,12 @@ ol.Tile = function(tileCoord, src, opt_crossOrigin) {
this.image_.crossOrigin = opt_crossOrigin;
}
/**
* @private
* @type {Object.<number, Image>}
*/
this.imageByContext_ = {};
/**
* @private
* @type {Array.<number>}
@@ -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_;
}
};