From b3f14f09c484a4cb6745f9ad203532a4f0e1fcd7 Mon Sep 17 00:00:00 2001 From: rattai Date: Tue, 4 Aug 2015 17:25:47 -0400 Subject: [PATCH 1/3] Compute new image extent for comparison to existing image extent --- src/ol/source/imagewmssource.js | 36 +++++++++++----------- test/spec/ol/source/imagewmssource.test.js | 8 +++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index 0df69e3c19..e098af2960 100644 --- a/src/ol/source/imagewmssource.js +++ b/src/ol/source/imagewmssource.js @@ -198,24 +198,6 @@ ol.source.ImageWMS.prototype.getImage = pixelRatio = 1; } - var image = this.image_; - if (!goog.isNull(image) && - this.renderedRevision_ == this.getRevision() && - image.getResolution() == resolution && - image.getPixelRatio() == pixelRatio && - ol.extent.containsExtent(image.getExtent(), extent)) { - return image; - } - - var params = { - 'SERVICE': 'WMS', - 'VERSION': ol.DEFAULT_WMS_VERSION, - 'REQUEST': 'GetMap', - 'FORMAT': 'image/png', - 'TRANSPARENT': true - }; - goog.object.extend(params, this.params_); - extent = extent.slice(); var centerX = (extent[0] + extent[2]) / 2; var centerY = (extent[1] + extent[3]) / 2; @@ -240,6 +222,24 @@ ol.source.ImageWMS.prototype.getImage = extent[1] = centerY - imageResolution * height / 2; extent[3] = centerY + imageResolution * height / 2; + var image = this.image_; + if (!goog.isNull(image) && + this.renderedRevision_ == this.getRevision() && + image.getResolution() == resolution && + image.getPixelRatio() == pixelRatio && + ol.extent.containsExtent(image.getExtent(), extent)) { + return image; + } + + var params = { + 'SERVICE': 'WMS', + 'VERSION': ol.DEFAULT_WMS_VERSION, + 'REQUEST': 'GetMap', + 'FORMAT': 'image/png', + 'TRANSPARENT': true + }; + goog.object.extend(params, this.params_); + this.imageSize_[0] = width; this.imageSize_[1] = height; diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js index 0230edd9ea..7e697e9d4e 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 the same image for consecutive calls with the 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() { From e49ce543a4c4a4a5dfd19d462fd0ea91d1b2ca74 Mon Sep 17 00:00:00 2001 From: rattai Date: Tue, 4 Aug 2015 20:00:59 -0400 Subject: [PATCH 2/3] shorten long line --- test/spec/ol/source/imagewmssource.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js index 7e697e9d4e..556f487286 100644 --- a/test/spec/ol/source/imagewmssource.test.js +++ b/test/spec/ol/source/imagewmssource.test.js @@ -155,7 +155,7 @@ describe('ol.source.ImageWMS', function() { expect(imageLoadFunction.calledWith(image, image.src_)).to.be(true); }); - it('returns the same image for consecutive calls with the same args', function() { + 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); From eb2a30e46142394d3382ade61bfcedff62aef4f7 Mon Sep 17 00:00:00 2001 From: rattai Date: Wed, 5 Aug 2015 12:59:41 -0400 Subject: [PATCH 3/3] Cache the image extent --- src/ol/source/imagewmssource.js | 44 ++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index e098af2960..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} @@ -198,6 +204,24 @@ ol.source.ImageWMS.prototype.getImage = pixelRatio = 1; } + var image = this.image_; + if (!goog.isNull(image) && + this.renderedRevision_ == this.getRevision() && + image.getResolution() == resolution && + image.getPixelRatio() == pixelRatio && + ol.extent.containsExtent(image.getExtent(), this.imageExtent_)) { + return image; + } + + var params = { + 'SERVICE': 'WMS', + 'VERSION': ol.DEFAULT_WMS_VERSION, + 'REQUEST': 'GetMap', + 'FORMAT': 'image/png', + 'TRANSPARENT': true + }; + goog.object.extend(params, this.params_); + extent = extent.slice(); var centerX = (extent[0] + extent[2]) / 2; var centerY = (extent[1] + extent[3]) / 2; @@ -222,23 +246,7 @@ ol.source.ImageWMS.prototype.getImage = extent[1] = centerY - imageResolution * height / 2; extent[3] = centerY + imageResolution * height / 2; - var image = this.image_; - if (!goog.isNull(image) && - this.renderedRevision_ == this.getRevision() && - image.getResolution() == resolution && - image.getPixelRatio() == pixelRatio && - ol.extent.containsExtent(image.getExtent(), extent)) { - return image; - } - - var params = { - 'SERVICE': 'WMS', - 'VERSION': ol.DEFAULT_WMS_VERSION, - 'REQUEST': 'GetMap', - 'FORMAT': 'image/png', - 'TRANSPARENT': true - }; - goog.object.extend(params, this.params_); + 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(); };