diff --git a/src/ol/reproj/image.js b/src/ol/reproj/image.js index c68fdcee1e..ac0ea5d403 100644 --- a/src/ol/reproj/image.js +++ b/src/ol/reproj/image.js @@ -30,6 +30,12 @@ goog.require('ol.reproj.Triangulation'); ol.reproj.Image = function(sourceProj, targetProj, targetExtent, targetResolution, pixelRatio, getImageFunction) { + /** + * @private + * @type {ol.proj.Projection} + */ + this.targetProj_ = targetProj; + /** * @private * @type {ol.Extent} @@ -127,6 +133,14 @@ ol.reproj.Image.prototype.getImage = function(opt_context) { }; +/** + * @return {ol.proj.Projection} Projection. + */ +ol.reproj.Image.prototype.getProjection = function() { + return this.targetProj_; +}; + + /** * @private */ diff --git a/src/ol/source/imagesource.js b/src/ol/source/imagesource.js index d4fad482b1..e0ac8486a2 100644 --- a/src/ol/source/imagesource.js +++ b/src/ol/source/imagesource.js @@ -5,9 +5,9 @@ goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.events.Event'); goog.require('ol.Attribution'); -goog.require('ol.Extent'); goog.require('ol.ImageState'); goog.require('ol.array'); +goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.reproj.Image'); goog.require('ol.source.Source'); @@ -58,6 +58,20 @@ ol.source.Image = function(options) { return b - a; }, true), 'resolutions must be null or sorted in descending order'); + + /** + * @private + * @type {ol.reproj.Image} + */ + this.reprojectedImage_ = null; + + + /** + * @private + * @type {number} + */ + this.reprojectedRevision_ = 0; + }; goog.inherits(ol.source.Image, ol.source.Source); @@ -104,14 +118,28 @@ ol.source.Image.prototype.getImage = } return this.getImageInternal(extent, resolution, pixelRatio, projection); } else { - var image = new ol.reproj.Image( + if (!goog.isNull(this.reprojectedImage_)) { + if (this.reprojectedRevision_ == this.getRevision() && + ol.proj.equivalent( + this.reprojectedImage_.getProjection(), projection) && + this.reprojectedImage_.getResolution() == resolution && + this.reprojectedImage_.getPixelRatio() == pixelRatio && + ol.extent.equals(this.reprojectedImage_.getExtent(), extent)) { + return this.reprojectedImage_; + } + this.reprojectedImage_.dispose(); + this.reprojectedImage_ = null; + } + + this.reprojectedImage_ = new ol.reproj.Image( sourceProjection, projection, extent, resolution, pixelRatio, goog.bind(function(extent, resolution, pixelRatio) { return this.getImageInternal(extent, resolution, pixelRatio, sourceProjection); }, this)); + this.reprojectedRevision_ = this.getRevision(); - return image; + return this.reprojectedImage_; } };