From d0e97df348cd9d69a14abfe5f30a98f947d1a61d Mon Sep 17 00:00:00 2001 From: giohappy Date: Tue, 10 Jan 2017 14:25:35 +0100 Subject: [PATCH] Mitigate rounding errors in GetMap widht/height calculation Revert to Math.ceil and calculate extent from round image sizes Fix regression: test view extent against real extent, then apply ratio remove trailing spaces --- src/ol/source/imagewms.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ol/source/imagewms.js b/src/ol/source/imagewms.js index 54348ca22d..b2c0f3b1ca 100644 --- a/src/ol/source/imagewms.js +++ b/src/ol/source/imagewms.js @@ -194,8 +194,16 @@ ol.source.ImageWMS.prototype.getImageInternal = function(extent, resolution, pix var centerY = (extent[1] + extent[3]) / 2; var imageResolution = resolution / pixelRatio; - var imageWidth = ol.extent.getWidth(extent) / imageResolution; - var imageHeight = ol.extent.getHeight(extent) / imageResolution; + var imageWidth = Math.ceil(ol.extent.getWidth(extent) / imageResolution); + var imageHeight = Math.ceil(ol.extent.getHeight(extent) / imageResolution); + + var halfWidth = imageWidth * imageResolution / 2; + var halfHeight = imageHeight * imageResolution / 2; + + extent[0] = centerX - halfWidth; + extent[1] = centerY - halfHeight; + extent[2] = centerX + halfWidth; + extent[3] = centerY + halfHeight; var image = this.image_; if (image && @@ -207,8 +215,9 @@ ol.source.ImageWMS.prototype.getImageInternal = function(extent, resolution, pix } if (this.ratio_ != 1) { - var halfWidth = this.ratio_ * ol.extent.getWidth(extent) / 2; - var halfHeight = this.ratio_ * ol.extent.getHeight(extent) / 2; + halfWidth *= this.ratio_; + halfHeight *= this.ratio_; + extent[0] = centerX - halfWidth; extent[1] = centerY - halfHeight; extent[2] = centerX + halfWidth; @@ -224,8 +233,8 @@ ol.source.ImageWMS.prototype.getImageInternal = function(extent, resolution, pix }; ol.obj.assign(params, this.params_); - this.imageSize_[0] = Math.ceil(imageWidth * this.ratio_); - this.imageSize_[1] = Math.ceil(imageHeight * this.ratio_); + this.imageSize_[0] = imageWidth * this.ratio_; + this.imageSize_[1] = imageHeight * this.ratio_; var url = this.getRequestUrl_(extent, this.imageSize_, pixelRatio, projection, params);