From 48b79cf7d1c369d39959c561a61915bc3408e1de Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 30 Mar 2020 14:51:27 +0100 Subject: [PATCH] only use one extent if two are passed --- src/ol/layer/Graticule.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ol/layer/Graticule.js b/src/ol/layer/Graticule.js index e16cc7d955..7a991858dc 100644 --- a/src/ol/layer/Graticule.js +++ b/src/ol/layer/Graticule.js @@ -479,11 +479,25 @@ class Graticule extends VectorLayer { * @return {Array} Extents. */ strategyFunction(extent, resolution) { - if (this.loadedExtent_ && !equals(this.loadedExtent_, extent)) { + // extents may be passed in different worlds, to avoid endless loop we use only one + const realExtent = extent.slice(); + if (this.projection_) { + const center = getCenter(extent); + const projectionExtent = this.projection_.getExtent(); + const worldWidth = getWidth(projectionExtent); + if (this.getSource().getWrapX() && this.projection_.canWrapX() && !containsExtent(projectionExtent, extent)) { + const worldsAway = Math.floor((center[0] - projectionExtent[0]) / worldWidth); + realExtent[0] -= (worldsAway * worldWidth); + realExtent[2] -= (worldsAway * worldWidth); + } + realExtent[0] = Math.round(realExtent[0] * 1e6) / 1e6; + realExtent[2] = Math.round(realExtent[2] * 1e6) / 1e6; + } + if (this.loadedExtent_ && !equals(this.loadedExtent_, realExtent)) { // we should not keep track of loaded extents this.getSource().removeLoadedExtent(this.loadedExtent_); } - return [extent]; + return [realExtent]; } /**