diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index 0df69e3c19..be67d86b89 100644 --- a/src/ol/source/imagewmssource.js +++ b/src/ol/source/imagewmssource.js @@ -92,6 +92,12 @@ ol.source.ImageWMS = function(opt_options) { */ this.image_ = null; + /** + * @private + * @type {ol.Extent} + */ + this.imageExtent_ = null; + /** * @private * @type {ol.Size} @@ -203,7 +209,7 @@ ol.source.ImageWMS.prototype.getImage = this.renderedRevision_ == this.getRevision() && image.getResolution() == resolution && image.getPixelRatio() == pixelRatio && - ol.extent.containsExtent(image.getExtent(), extent)) { + ol.extent.containsExtent(image.getExtent(), this.imageExtent_)) { return image; } @@ -240,6 +246,8 @@ ol.source.ImageWMS.prototype.getImage = extent[1] = centerY - imageResolution * height / 2; extent[3] = centerY + imageResolution * height / 2; + this.imageExtent_ = extent; + this.imageSize_[0] = width; this.imageSize_[1] = height; @@ -362,6 +370,7 @@ ol.source.ImageWMS.prototype.setUrl = function(url) { if (url != this.url_) { this.url_ = url; this.image_ = null; + this.imageExtent_ = null; this.changed(); } }; @@ -376,6 +385,7 @@ ol.source.ImageWMS.prototype.updateParams = function(params) { goog.object.extend(this.params_, params); this.updateV13_(); this.image_ = null; + this.imageExtent_ = null; this.changed(); }; diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js index 0230edd9ea..556f487286 100644 --- a/test/spec/ol/source/imagewmssource.test.js +++ b/test/spec/ol/source/imagewmssource.test.js @@ -155,6 +155,14 @@ describe('ol.source.ImageWMS', function() { expect(imageLoadFunction.calledWith(image, image.src_)).to.be(true); }); + it('returns same image for consecutive calls with same args', function() { + var extent = [10.01, 20, 30.01, 40]; + var source = new ol.source.ImageWMS(options); + var image1 = source.getImage(extent, resolution, pixelRatio, projection); + var image2 = source.getImage(extent, resolution, pixelRatio, projection); + expect(image1).to.equal(image2); + }); + }); describe('#getGetFeatureInfo', function() {