Reproject image sources only if actually needed
This commit is contained in:
@@ -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_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user