From c15631ae3e8f5c08574798019f411c95b66ba44f Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 2 Dec 2011 23:57:39 +0100 Subject: [PATCH 1/6] Remove code that never gets called. OpenLayers.Map has no wrapDateLine property. --- lib/OpenLayers/Layer/Grid.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index be35eb26fe..7709510d31 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -658,10 +658,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { */ calculateGridLayout: function(bounds, origin, resolution) { bounds = bounds.clone(); - var map = this.map; - if (map.wrapDateLine) { - bounds = bounds.wrapDateLine(map.getMaxExtent()); - } var tilelon = resolution * this.tileSize.w; var tilelat = resolution * this.tileSize.h; From 84b30d36995785307a53992ca2686cabf785bc58 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 3 Dec 2011 00:05:26 +0100 Subject: [PATCH 2/6] Don't rely on the bounds of the top-right tile. When the grid crosses the dateline, the top-right tile is in a different world than the bottom-left one. Instead, use the grid size and tile width/height to calculate the top-right coordinate. --- lib/OpenLayers/Layer/Grid.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 7709510d31..5e23c828fb 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -583,18 +583,16 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { getTilesBounds: function() { var bounds = null; - if (this.grid.length) { - var bottom = this.grid.length - 1; - var bottomLeftTile = this.grid[bottom][0]; - - var right = this.grid[0].length - 1; - var topRightTile = this.grid[0][right]; - - bounds = new OpenLayers.Bounds(bottomLeftTile.bounds.left, - bottomLeftTile.bounds.bottom, - topRightTile.bounds.right, - topRightTile.bounds.top); + var length = this.grid.length; + if (length) { + var bottomLeftTileBounds = this.grid[length - 1][0].bounds, + width = this.grid[0].length * bottomLeftTileBounds.getWidth(), + height = this.grid.length * bottomLeftTileBounds.getHeight(); + bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, + bottomLeftTileBounds.bottom, + bottomLeftTileBounds.left + width, + bottomLeftTileBounds.bottom + height); } return bounds; }, From b70ea9e8c1db648bcc8586a64a0ff77a829daab8 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 3 Dec 2011 00:07:04 +0100 Subject: [PATCH 3/6] Use valid tile bounds and test grid crossing the dateline. --- tests/Layer/Grid.html | 26 +++++++++++++++----------- tests/Layer/KaMap.html | 4 ++-- tests/Layer/TMS.html | 4 ++-- tests/Layer/TileCache.html | 4 ++-- tests/Layer/WMTS.html | 4 ++-- tests/Layer/XYZ.html | 4 ++-- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index cd773bb268..8dbcbcc3ec 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -94,14 +94,14 @@ function test_Layer_Grid_getTilesBounds(t) { - t.plan(3); + t.plan(4); layer = new OpenLayers.Layer.WMS(name, url, params); //normal grid - var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)}; layer.grid = [ [6, tr], [bl, 7]]; @@ -123,6 +123,17 @@ bounds = layer.getTilesBounds(); t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); + + //world wrapped around the dateline + var bl = { bounds: new OpenLayers.Bounds(0,-90,180,90)}; + var tr = { bounds: new OpenLayers.Bounds(-180,-90,0,90)}; + layer.grid = [[bl, tr]]; + + var bounds = layer.getTilesBounds(); + console.log(bounds); + var testBounds = new OpenLayers.Bounds(0,-90,360,90); + + t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); } @@ -159,7 +170,7 @@ function test_Layer_Grid_moveTo(t) { - t.plan(14); + t.plan(12); var map = new OpenLayers.Map('map'); layer = new OpenLayers.Layer.WMS(name, url, params); @@ -280,13 +291,6 @@ layer.grid = [ [ {} ] ]; layer.singleTile = false; - // drastic pan - clearTestBounds(); - tilesBounds = new OpenLayers.Bounds(-150,-150,-120,-120); - layer.moveTo(null, zoomChanged); - t.ok(g_WhichFunc == "InitGridded", "if tiles drastically out of bounds, we call initGriddedTile()"); - t.ok(g_Bounds.equals(b), "if tiles drastically out of bounds, we call initGriddedTile() with correct bounds"); - //regular move clearTestBounds(); tilesBounds = new OpenLayers.Bounds(10,10,120,120); diff --git a/tests/Layer/KaMap.html b/tests/Layer/KaMap.html index af2003a1d2..b22917fda0 100644 --- a/tests/Layer/KaMap.html +++ b/tests/Layer/KaMap.html @@ -94,8 +94,8 @@ layer = new OpenLayers.Layer.KaMap(name, url, params, units); - var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)}; layer.grid = [ [6, tr], [bl, 7]]; diff --git a/tests/Layer/TMS.html b/tests/Layer/TMS.html index c55d02bda7..74e75dac5b 100644 --- a/tests/Layer/TMS.html +++ b/tests/Layer/TMS.html @@ -42,8 +42,8 @@ layer = new OpenLayers.Layer.TMS(name, url, options); - var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)}; layer.grid = [ [6, tr], [bl, 7]]; diff --git a/tests/Layer/TileCache.html b/tests/Layer/TileCache.html index 1a70200901..2bb88f5b13 100644 --- a/tests/Layer/TileCache.html +++ b/tests/Layer/TileCache.html @@ -66,8 +66,8 @@ var options = {'type':'png'}; var layer = new OpenLayers.Layer.TileCache(name, url, layername, options); - var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)}; layer.grid = [ [6, tr], [bl, 7]]; diff --git a/tests/Layer/WMTS.html b/tests/Layer/WMTS.html index 079e87876d..e2b64f2604 100644 --- a/tests/Layer/WMTS.html +++ b/tests/Layer/WMTS.html @@ -119,8 +119,8 @@ tileSize: new OpenLayers.Size(512, 512), requestEncoding: "REST" }); - var bl = {bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = {bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = {bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = {bounds: new OpenLayers.Bounds(2,3,3,4)}; layer1.grid = [[6, tr],[bl, 7]]; var bounds = layer1.getTilesBounds(); var testBounds = new OpenLayers.Bounds(1,2,3,4); diff --git a/tests/Layer/XYZ.html b/tests/Layer/XYZ.html index a13ee845c3..d6685c05b5 100644 --- a/tests/Layer/XYZ.html +++ b/tests/Layer/XYZ.html @@ -41,8 +41,8 @@ layer = new OpenLayers.Layer.XYZ(name, url, options); - var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)}; - var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)}; + var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)}; + var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)}; layer.grid = [ [6, tr], [bl, 7]]; From 08af94cf84656df508c72218badef43734da50a1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 3 Dec 2011 00:13:44 +0100 Subject: [PATCH 4/6] We never need to retile when the zoom didn't change. --- lib/OpenLayers/Layer/Grid.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 5e23c828fb..3379813d9a 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -319,14 +319,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { } } else { - // if the bounds have changed such that they are not even - // *partially* contained by our tiles (IE user has - // programmatically panned to the other side of the earth) - // then we want to reTile (thus, partial true). - - forceReTile = forceReTile || - !tilesBounds.containsBounds(bounds, true); - if(resolution !== serverResolution) { bounds = this.map.calculateBounds(null, serverResolution); if(forceReTile) { From d20e6f7c7acab4764f3bbcef230b497eb42ff3cd Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 3 Dec 2011 01:36:11 +0100 Subject: [PATCH 5/6] removing console.log --- tests/Layer/Grid.html | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 8dbcbcc3ec..76e3162be1 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -130,7 +130,6 @@ layer.grid = [[bl, tr]]; var bounds = layer.getTilesBounds(); - console.log(bounds); var testBounds = new OpenLayers.Bounds(0,-90,360,90); t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); From 7aa7b98285f2b04b9bb8c6fd6f5f33670aa96adb Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 3 Dec 2011 01:37:42 +0100 Subject: [PATCH 6/6] fixing indentation --- tests/Layer/Grid.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 76e3162be1..462a04560f 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -125,14 +125,14 @@ t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); //world wrapped around the dateline - var bl = { bounds: new OpenLayers.Bounds(0,-90,180,90)}; - var tr = { bounds: new OpenLayers.Bounds(-180,-90,0,90)}; - layer.grid = [[bl, tr]]; + var bl = { bounds: new OpenLayers.Bounds(0,-90,180,90)}; + var tr = { bounds: new OpenLayers.Bounds(-180,-90,0,90)}; + layer.grid = [[bl, tr]]; - var bounds = layer.getTilesBounds(); - var testBounds = new OpenLayers.Bounds(0,-90,360,90); + var bounds = layer.getTilesBounds(); + var testBounds = new OpenLayers.Bounds(0,-90,360,90); - t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); + t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds"); }