From adcf57ef20d03df255b2d1ec45c469d7cc48878c Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Tue, 25 Feb 2020 13:47:02 +0000 Subject: [PATCH] Better validation to handle polar projections For some projections (e.g. polar) the maximum or minimum values may be at the center. To improve the display for polar projections take validated center values into account when calculating max and min. --- src/ol/layer/Graticule.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ol/layer/Graticule.js b/src/ol/layer/Graticule.js index b7002c247b..42b5c380fa 100644 --- a/src/ol/layer/Graticule.js +++ b/src/ol/layer/Graticule.js @@ -679,8 +679,8 @@ class Graticule extends VectorLayer { ]; const centerLonLat = this.toLonLatTransform_(validCenter); - let centerLon = centerLonLat[0]; - let centerLat = centerLonLat[1]; + let centerLon = clamp(centerLonLat[0], this.minLon_, this.maxLon_); + let centerLat = clamp(centerLonLat[1], this.minLat_, this.maxLat_); const maxLines = this.maxLines_; let cnt, idx, lat, lon; @@ -693,10 +693,10 @@ class Graticule extends VectorLayer { validExtent = applyTransform(validExtent, this.toLonLatTransform_, undefined, 8); - const maxLat = Math.min(validExtent[3], this.maxLat_); - const maxLon = Math.min(validExtent[2], this.maxLon_); - const minLat = Math.max(validExtent[1], this.minLat_); - const minLon = Math.max(validExtent[0], this.minLon_); + const maxLat = clamp(validExtent[3], centerLat, this.maxLat_); + const maxLon = clamp(validExtent[2], centerLon, this.maxLon_); + const minLat = clamp(validExtent[1], this.minLat_, centerLat); + const minLon = clamp(validExtent[0], this.minLon_, centerLon); // Create meridians