From 7b4a954c40f4c28381f87079553f9ff11e46b272 Mon Sep 17 00:00:00 2001 From: Ryan Curry Date: Tue, 30 Jun 2015 11:09:20 -0700 Subject: [PATCH 1/4] graticule.js now uses vectorContext.extent_ When creating the graticule use the extent from the vectorContext instead of the frameState to determine what parallels and meridians should be created. This will allow the graticule to be drawn correctly on views that wrap across the dateline. --- src/ol/graticule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/graticule.js b/src/ol/graticule.js index 89adadad5e..9d4a1f3e69 100644 --- a/src/ol/graticule.js +++ b/src/ol/graticule.js @@ -356,7 +356,7 @@ ol.Graticule.prototype.getParallels = function() { ol.Graticule.prototype.handlePostCompose_ = function(e) { var vectorContext = e.vectorContext; var frameState = e.frameState; - var extent = frameState.extent; + var extent = vectorContext.extent_; var viewState = frameState.viewState; var center = viewState.center; var projection = viewState.projection; From de6ecb22a8e89e60d2cc1ef3190f0a6b7ab30337 Mon Sep 17 00:00:00 2001 From: Ryan Curry Date: Thu, 2 Jul 2015 12:20:05 -0700 Subject: [PATCH 2/4] graticule.js - Fixed build. No functional change. viewContext.extent_ is private, so we can't use it directly. Instead, re-calculate the corrected wrapped extent. --- src/ol/graticule.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ol/graticule.js b/src/ol/graticule.js index 9d4a1f3e69..2ee6ecc1a5 100644 --- a/src/ol/graticule.js +++ b/src/ol/graticule.js @@ -356,7 +356,7 @@ ol.Graticule.prototype.getParallels = function() { ol.Graticule.prototype.handlePostCompose_ = function(e) { var vectorContext = e.vectorContext; var frameState = e.frameState; - var extent = vectorContext.extent_; + var extent = framteState.extent; var viewState = frameState.viewState; var center = viewState.center; var projection = viewState.projection; @@ -372,6 +372,21 @@ ol.Graticule.prototype.handlePostCompose_ = function(e) { this.updateProjectionInfo_(projection); } + //Fix the extent if wrapped (note: this is the same extent as vectorContext.extent_) + var offsetX = 0; + if (projection.canWrapX()) { + var projectionExtent = projection.getExtent(); + var worldWidth = ol.extent.getWidth(projectionExtent); + var x = frameState.focus[0]; + if (x < projectionExtent[0] || x > projectionExtent[2]) { + var worldsAway = Math.ceil((projectionExtent[0] - x) / worldWidth); + extent = [ + extent[0] + offsetX, extent[1], + extent[2] + offsetX, extent[3] + ]; + } + } + this.createGraticule_(extent, center, resolution, squaredTolerance); // Draw the lines From 56e871f8b59d32980bd8dba441cbee1ed6cdc0a1 Mon Sep 17 00:00:00 2001 From: Ryan Curry Date: Thu, 2 Jul 2015 12:23:05 -0700 Subject: [PATCH 3/4] Update graticule.js - fixed typo/build error Corrected reference to variable frameState - it was misspelled by the previous commit. --- src/ol/graticule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/graticule.js b/src/ol/graticule.js index 2ee6ecc1a5..e3585a1ea4 100644 --- a/src/ol/graticule.js +++ b/src/ol/graticule.js @@ -356,7 +356,7 @@ ol.Graticule.prototype.getParallels = function() { ol.Graticule.prototype.handlePostCompose_ = function(e) { var vectorContext = e.vectorContext; var frameState = e.frameState; - var extent = framteState.extent; + var extent = frameState.extent; var viewState = frameState.viewState; var center = viewState.center; var projection = viewState.projection; From 9a44895d41249ab7e4dd6c75c2161f6141eb3ee0 Mon Sep 17 00:00:00 2001 From: Ryan Curry Date: Thu, 2 Jul 2015 12:35:38 -0700 Subject: [PATCH 4/4] Update graticule.js - fixed style / missing line My comment on line 375 was too long, so I broke it up into multiple lines. Also I accidentally left a line out of the commit (line 384) when transcribing my changes into the web based editor. --- src/ol/graticule.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/graticule.js b/src/ol/graticule.js index e3585a1ea4..57caa01537 100644 --- a/src/ol/graticule.js +++ b/src/ol/graticule.js @@ -372,7 +372,8 @@ ol.Graticule.prototype.handlePostCompose_ = function(e) { this.updateProjectionInfo_(projection); } - //Fix the extent if wrapped (note: this is the same extent as vectorContext.extent_) + //Fix the extent if wrapped. + //(note: this is the same extent as vectorContext.extent_) var offsetX = 0; if (projection.canWrapX()) { var projectionExtent = projection.getExtent(); @@ -380,6 +381,7 @@ ol.Graticule.prototype.handlePostCompose_ = function(e) { var x = frameState.focus[0]; if (x < projectionExtent[0] || x > projectionExtent[2]) { var worldsAway = Math.ceil((projectionExtent[0] - x) / worldWidth); + offsetX = worldWidth * worldsAway; extent = [ extent[0] + offsetX, extent[1], extent[2] + offsetX, extent[3]