Merge pull request #87 from ahocevar/retile
getTilesBounds fixes and no unnecessary retiling. r=@bartvde
This commit is contained in:
@@ -319,14 +319,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
if(resolution !== serverResolution) {
|
||||||
bounds = this.map.calculateBounds(null, serverResolution);
|
bounds = this.map.calculateBounds(null, serverResolution);
|
||||||
if(forceReTile) {
|
if(forceReTile) {
|
||||||
@@ -583,18 +575,16 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
getTilesBounds: function() {
|
getTilesBounds: function() {
|
||||||
var bounds = null;
|
var bounds = null;
|
||||||
|
|
||||||
if (this.grid.length) {
|
var length = this.grid.length;
|
||||||
var bottom = this.grid.length - 1;
|
if (length) {
|
||||||
var bottomLeftTile = this.grid[bottom][0];
|
var bottomLeftTileBounds = this.grid[length - 1][0].bounds,
|
||||||
|
width = this.grid[0].length * bottomLeftTileBounds.getWidth(),
|
||||||
var right = this.grid[0].length - 1;
|
height = this.grid.length * bottomLeftTileBounds.getHeight();
|
||||||
var topRightTile = this.grid[0][right];
|
|
||||||
|
|
||||||
bounds = new OpenLayers.Bounds(bottomLeftTile.bounds.left,
|
|
||||||
bottomLeftTile.bounds.bottom,
|
|
||||||
topRightTile.bounds.right,
|
|
||||||
topRightTile.bounds.top);
|
|
||||||
|
|
||||||
|
bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left,
|
||||||
|
bottomLeftTileBounds.bottom,
|
||||||
|
bottomLeftTileBounds.left + width,
|
||||||
|
bottomLeftTileBounds.bottom + height);
|
||||||
}
|
}
|
||||||
return bounds;
|
return bounds;
|
||||||
},
|
},
|
||||||
@@ -658,10 +648,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
*/
|
*/
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
calculateGridLayout: function(bounds, origin, resolution) {
|
||||||
bounds = bounds.clone();
|
bounds = bounds.clone();
|
||||||
var map = this.map;
|
|
||||||
if (map.wrapDateLine) {
|
|
||||||
bounds = bounds.wrapDateLine(map.getMaxExtent());
|
|
||||||
}
|
|
||||||
|
|
||||||
var tilelon = resolution * this.tileSize.w;
|
var tilelon = resolution * this.tileSize.w;
|
||||||
var tilelat = resolution * this.tileSize.h;
|
var tilelat = resolution * this.tileSize.h;
|
||||||
|
|||||||
+14
-11
@@ -94,14 +94,14 @@
|
|||||||
|
|
||||||
|
|
||||||
function test_Layer_Grid_getTilesBounds(t) {
|
function test_Layer_Grid_getTilesBounds(t) {
|
||||||
t.plan(3);
|
t.plan(4);
|
||||||
|
|
||||||
layer = new OpenLayers.Layer.WMS(name, url, params);
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||||
|
|
||||||
|
|
||||||
//normal grid
|
//normal grid
|
||||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer.grid = [ [6, tr],
|
layer.grid = [ [6, tr],
|
||||||
[bl, 7]];
|
[bl, 7]];
|
||||||
|
|
||||||
@@ -124,6 +124,16 @@
|
|||||||
|
|
||||||
t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds");
|
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();
|
||||||
|
var testBounds = new OpenLayers.Bounds(0,-90,360,90);
|
||||||
|
|
||||||
|
t.ok( bounds.equals(testBounds), "getTilesBounds() returns correct bounds");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Layer_Grid_getResolution(t) {
|
function test_Layer_Grid_getResolution(t) {
|
||||||
@@ -159,7 +169,7 @@
|
|||||||
|
|
||||||
function test_Layer_Grid_moveTo(t) {
|
function test_Layer_Grid_moveTo(t) {
|
||||||
|
|
||||||
t.plan(14);
|
t.plan(12);
|
||||||
|
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
layer = new OpenLayers.Layer.WMS(name, url, params);
|
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||||
@@ -280,13 +290,6 @@
|
|||||||
layer.grid = [ [ {} ] ];
|
layer.grid = [ [ {} ] ];
|
||||||
layer.singleTile = false;
|
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
|
//regular move
|
||||||
clearTestBounds();
|
clearTestBounds();
|
||||||
tilesBounds = new OpenLayers.Bounds(10,10,120,120);
|
tilesBounds = new OpenLayers.Bounds(10,10,120,120);
|
||||||
|
|||||||
@@ -94,8 +94,8 @@
|
|||||||
|
|
||||||
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
|
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
|
||||||
|
|
||||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer.grid = [ [6, tr],
|
layer.grid = [ [6, tr],
|
||||||
[bl, 7]];
|
[bl, 7]];
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@
|
|||||||
|
|
||||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||||
|
|
||||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer.grid = [ [6, tr],
|
layer.grid = [ [6, tr],
|
||||||
[bl, 7]];
|
[bl, 7]];
|
||||||
|
|
||||||
|
|||||||
@@ -66,8 +66,8 @@
|
|||||||
var options = {'type':'png'};
|
var options = {'type':'png'};
|
||||||
var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
|
var layer = new OpenLayers.Layer.TileCache(name, url, layername, options);
|
||||||
|
|
||||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer.grid = [ [6, tr],
|
layer.grid = [ [6, tr],
|
||||||
[bl, 7]];
|
[bl, 7]];
|
||||||
|
|
||||||
|
|||||||
@@ -119,8 +119,8 @@
|
|||||||
tileSize: new OpenLayers.Size(512, 512),
|
tileSize: new OpenLayers.Size(512, 512),
|
||||||
requestEncoding: "REST"
|
requestEncoding: "REST"
|
||||||
});
|
});
|
||||||
var bl = {bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = {bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = {bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = {bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer1.grid = [[6, tr],[bl, 7]];
|
layer1.grid = [[6, tr],[bl, 7]];
|
||||||
var bounds = layer1.getTilesBounds();
|
var bounds = layer1.getTilesBounds();
|
||||||
var testBounds = new OpenLayers.Bounds(1,2,3,4);
|
var testBounds = new OpenLayers.Bounds(1,2,3,4);
|
||||||
|
|||||||
@@ -41,8 +41,8 @@
|
|||||||
|
|
||||||
layer = new OpenLayers.Layer.XYZ(name, url, options);
|
layer = new OpenLayers.Layer.XYZ(name, url, options);
|
||||||
|
|
||||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
var bl = { bounds: new OpenLayers.Bounds(1,2,2,3)};
|
||||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
var tr = { bounds: new OpenLayers.Bounds(2,3,3,4)};
|
||||||
layer.grid = [ [6, tr],
|
layer.grid = [ [6, tr],
|
||||||
[bl, 7]];
|
[bl, 7]];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user