Reproject image sources only if actually needed

This commit is contained in:
Petr Sloup
2015-09-09 11:49:00 +02:00
parent 3353eeb0c3
commit 5388f96551
2 changed files with 45 additions and 3 deletions

View File

@@ -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_;
}
};