From 40c1a6d11286309555c5938bd38a8266d224d754 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 28 Oct 2015 23:58:00 +0100 Subject: [PATCH] Check view extent within image extent --- src/ol/source/imagewmssource.js | 17 +++++++++-------- test/spec/ol/source/imagewmssource.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index 72eabf98fb..1d63972269 100644 --- a/src/ol/source/imagewmssource.js +++ b/src/ol/source/imagewmssource.js @@ -201,14 +201,6 @@ ol.source.ImageWMS.prototype.getImageInternal = extent = extent.slice(); var centerX = (extent[0] + extent[2]) / 2; var centerY = (extent[1] + extent[3]) / 2; - if (this.ratio_ != 1) { - var halfWidth = this.ratio_ * ol.extent.getWidth(extent) / 2; - var halfHeight = this.ratio_ * ol.extent.getHeight(extent) / 2; - extent[0] = centerX - halfWidth; - extent[1] = centerY - halfHeight; - extent[2] = centerX + halfWidth; - extent[3] = centerY + halfHeight; - } var imageResolution = resolution / pixelRatio; @@ -231,6 +223,15 @@ ol.source.ImageWMS.prototype.getImageInternal = return image; } + if (this.ratio_ != 1) { + var halfWidth = this.ratio_ * ol.extent.getWidth(extent) / 2; + var halfHeight = this.ratio_ * ol.extent.getHeight(extent) / 2; + extent[0] = centerX - halfWidth; + extent[1] = centerY - halfHeight; + extent[2] = centerX + halfWidth; + extent[3] = centerY + halfHeight; + } + var params = { 'SERVICE': 'WMS', 'VERSION': ol.DEFAULT_WMS_VERSION, diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js index 556f487286..d082dca698 100644 --- a/test/spec/ol/source/imagewmssource.test.js +++ b/test/spec/ol/source/imagewmssource.test.js @@ -163,6 +163,16 @@ describe('ol.source.ImageWMS', function() { expect(image1).to.equal(image2); }); + it('returns same image for calls with similar extents', function() { + options.ratio = 1.5; + var source = new ol.source.ImageWMS(options); + var extent = [10.01, 20, 30.01, 40]; + var image1 = source.getImage(extent, resolution, pixelRatio, projection); + extent = [10.01, 20.1, 30.01, 40.1]; + var image2 = source.getImage(extent, resolution, pixelRatio, projection); + expect(image1).to.equal(image2); + }); + }); describe('#getGetFeatureInfo', function() {