From 0f588688305f78b51264b7eb063bb14889a62abf Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 20 Aug 2012 18:50:12 +0200 Subject: [PATCH 1/2] When using a buffer, the grid lacks rows/columns at the top/left. This is because the threshold used for deciding when a column or row is shifted is too far to the bottom right. A tiny fix, but effective. A new test makes sure that we don't shift columns more than necessary when the layer is dragged. --- lib/OpenLayers/Layer/Grid.js | 2 +- tests/Layer/Grid.html | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index b1d45eebd8..45b6b733ba 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -1193,7 +1193,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { ); return; } - var buffer = this.buffer || 1; + var buffer = this.buffer + 1; var scale = this.getResolutionScale(); while(true) { var tlViewPort = { diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 50464f3cd8..956b12f812 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -239,6 +239,23 @@ t.eq( zoom, 2, "getZoomForExtent() returns correct value"); } + function test_moveGriddedTiles(t) { + t.plan(1); + var map = new OpenLayers.Map('map'); + layer = new OpenLayers.Layer.WMS(name, url, params, {buffer: 2}); + map.addLayer(layer); + map.setCenter([0, 0], 5); + var count = 0; + layer.shiftColumn = function(prepend) { + ++count; + OpenLayers.Layer.WMS.prototype.shiftColumn.apply(this, arguments); + } + map.moveTo([15, 0]); + t.delay_call(.5, function() { + t.eq(count, 1, "column shifted once"); + }); + } + function test_Layer_Grid_moveTo(t) { t.plan(17); From 26d4fe3ce83513604704b4d48c56ab9e5db80297 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 21 Aug 2012 13:34:49 +0200 Subject: [PATCH 2/2] Making row and column size consistent, as suggested by @bartvde. --- lib/OpenLayers/Layer/Grid.js | 4 ++-- tests/Layer/Grid.html | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 45b6b733ba..38ee3cb77e 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -983,9 +983,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { var viewSize = this.map.getSize(); var minRows = Math.ceil(viewSize.h/this.tileSize.h) + - Math.max(1, 2 * this.buffer); + 2 * this.buffer + 1; var minCols = Math.ceil(viewSize.w/this.tileSize.w) + - Math.max(1, 2 * this.buffer); + 2 * this.buffer + 1; var origin = this.getTileOrigin(); var resolution = this.getServerResolution(); diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 956b12f812..18d616edce 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -76,8 +76,8 @@ layer = new OpenLayers.Layer.WMS(name, url, params, {buffer:2}); map.addLayer(layer); map.setCenter(new OpenLayers.LonLat(0,0),5); - t.eq( layer.grid.length, 7, "Grid rows is correct." ); - t.eq( layer.grid[0].length, 6, "Grid cols is correct." ); + t.eq( layer.grid.length, 8, "Grid rows is correct." ); + t.eq( layer.grid[0].length, 7, "Grid cols is correct." ); } @@ -712,17 +712,17 @@ map.setCenter(new OpenLayers.LonLat(0, 0), 4); t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" ); map.setBaseLayer(layer1); - t.eq( layer1.grid.length, 4, "Grid rows with buffer:1" ); + t.eq( layer1.grid.length, 5, "Grid rows with buffer:1" ); map.setBaseLayer(layer2); - t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" ); + t.eq( layer2.grid.length, 7, "Grid rows with buffer:2" ); // zooming in on Greenland exercises the bug from pre-r4313 map.setCenter(new OpenLayers.LonLat(0, 90), 4); t.eq( layer0.grid.length, 3, "Grid rows with buffer:0" ); map.setBaseLayer(layer1); - t.eq( layer1.grid.length, 4, "Grid rows with buffer:1" ); + t.eq( layer1.grid.length, 5, "Grid rows with buffer:1" ); map.setBaseLayer(layer2); - t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" ); + t.eq( layer2.grid.length, 7, "Grid rows with buffer:2" ); } function test_Layer_Grid_destroy (t) {