Reproject image sources only if actually needed
This commit is contained in:
@@ -30,6 +30,12 @@ goog.require('ol.reproj.Triangulation');
|
|||||||
ol.reproj.Image = function(sourceProj, targetProj,
|
ol.reproj.Image = function(sourceProj, targetProj,
|
||||||
targetExtent, targetResolution, pixelRatio, getImageFunction) {
|
targetExtent, targetResolution, pixelRatio, getImageFunction) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.proj.Projection}
|
||||||
|
*/
|
||||||
|
this.targetProj_ = targetProj;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Extent}
|
* @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
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ goog.require('goog.array');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.events.Event');
|
goog.require('goog.events.Event');
|
||||||
goog.require('ol.Attribution');
|
goog.require('ol.Attribution');
|
||||||
goog.require('ol.Extent');
|
|
||||||
goog.require('ol.ImageState');
|
goog.require('ol.ImageState');
|
||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
|
goog.require('ol.extent');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.reproj.Image');
|
goog.require('ol.reproj.Image');
|
||||||
goog.require('ol.source.Source');
|
goog.require('ol.source.Source');
|
||||||
@@ -58,6 +58,20 @@ ol.source.Image = function(options) {
|
|||||||
return b - a;
|
return b - a;
|
||||||
}, true), 'resolutions must be null or sorted in descending order');
|
}, 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);
|
goog.inherits(ol.source.Image, ol.source.Source);
|
||||||
|
|
||||||
@@ -104,14 +118,28 @@ ol.source.Image.prototype.getImage =
|
|||||||
}
|
}
|
||||||
return this.getImageInternal(extent, resolution, pixelRatio, projection);
|
return this.getImageInternal(extent, resolution, pixelRatio, projection);
|
||||||
} else {
|
} 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,
|
sourceProjection, projection, extent, resolution, pixelRatio,
|
||||||
goog.bind(function(extent, resolution, pixelRatio) {
|
goog.bind(function(extent, resolution, pixelRatio) {
|
||||||
return this.getImageInternal(extent, resolution,
|
return this.getImageInternal(extent, resolution,
|
||||||
pixelRatio, sourceProjection);
|
pixelRatio, sourceProjection);
|
||||||
}, this));
|
}, this));
|
||||||
|
this.reprojectedRevision_ = this.getRevision();
|
||||||
|
|
||||||
return image;
|
return this.reprojectedImage_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user