Correctly size Layer.Grid and Layer.KaMap in rows/cols for all values of Grid.buffer.
Closes bug #928. Thanks a mil to bartvde for identifying the solution. git-svn-id: http://svn.openlayers.org/trunk/openlayers@4317 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -306,10 +306,13 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
initGriddedTiles:function(bounds) {
|
initGriddedTiles:function(bounds) {
|
||||||
|
|
||||||
// work out mininum number of rows and columns; this is the number of
|
// work out mininum number of rows and columns; this is the number of
|
||||||
// tiles required to cover the viewport plus one for panning
|
// tiles required to cover the viewport plus at least one for panning
|
||||||
|
|
||||||
var viewSize = this.map.getSize();
|
var viewSize = this.map.getSize();
|
||||||
var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 1;
|
var minRows = Math.ceil(viewSize.h/this.tileSize.h) +
|
||||||
var minCols = Math.ceil(viewSize.w/this.tileSize.w) + 1;
|
Math.max(1, 2 * this.buffer);
|
||||||
|
var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
|
||||||
|
Math.max(1, 2 * this.buffer);
|
||||||
|
|
||||||
var extent = this.map.getMaxExtent();
|
var extent = this.map.getMaxExtent();
|
||||||
var resolution = this.map.getResolution();
|
var resolution = this.map.getResolution();
|
||||||
@@ -528,7 +531,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
|||||||
* bounds - {<OpenLayers.Bounds>}
|
* bounds - {<OpenLayers.Bounds>}
|
||||||
*/
|
*/
|
||||||
moveGriddedTiles: function(bounds) {
|
moveGriddedTiles: function(bounds) {
|
||||||
var buffer = (this.buffer) ? this.buffer*1.5 : 1;
|
var buffer = this.buffer || 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
var tlLayer = this.grid[0][0].position;
|
var tlLayer = this.grid[0][0].position;
|
||||||
var tlViewPort =
|
var tlViewPort =
|
||||||
|
|||||||
@@ -114,23 +114,25 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
/**
|
/**
|
||||||
* Method: initGriddedTiles
|
* Method: initGriddedTiles
|
||||||
*/
|
*/
|
||||||
initGriddedTiles:function() {
|
initGriddedTiles:function(bounds) {
|
||||||
|
|
||||||
var viewSize = this.map.getSize();
|
var viewSize = this.map.getSize();
|
||||||
var bounds = this.map.getExtent();
|
var minRows = Math.ceil(viewSize.h/this.tileSize.h) + Math.max(1, 2*this.buffer);
|
||||||
|
var minCols = Math.ceil(viewSize.w/this.tileSize.w) + Math.max(1, 2*this.buffer);
|
||||||
|
|
||||||
var extent = this.map.getMaxExtent();
|
var extent = this.map.getMaxExtent();
|
||||||
var resolution = this.map.getResolution();
|
var resolution = this.map.getResolution();
|
||||||
var tilelon = resolution*this.tileSize.w;
|
var tilelon = resolution*this.tileSize.w;
|
||||||
var tilelat = resolution*this.tileSize.h;
|
var tilelat = resolution*this.tileSize.h;
|
||||||
|
|
||||||
var offsetlon = bounds.left;
|
var offsetlon = bounds.left;
|
||||||
var tilecol = Math.floor(offsetlon/tilelon);
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
var tilecolremain = offsetlon/tilelon - tilecol;
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
||||||
var tileoffsetlon = tilecol * tilelon;
|
var tileoffsetlon = tilecol * tilelon;
|
||||||
|
|
||||||
var offsetlat = bounds.top;
|
var offsetlat = bounds.top;
|
||||||
var tilerow = Math.ceil(offsetlat/tilelat);
|
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
var tilerowremain = tilerow - offsetlat/tilelat;
|
||||||
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
||||||
var tileoffsetlat = tilerow * tilelat;
|
var tileoffsetlat = tilerow * tilelat;
|
||||||
@@ -146,9 +148,7 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
var rowidx = 0;
|
var rowidx = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var row;
|
var row = this.grid[rowidx++];
|
||||||
|
|
||||||
row = this.grid[rowidx++];
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
row = [];
|
row = [];
|
||||||
this.grid.push(row);
|
this.grid.push(row);
|
||||||
@@ -160,10 +160,11 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
var colidx = 0;
|
var colidx = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var tileBounds = new OpenLayers.Bounds(tileoffsetlon,
|
var tileBounds =
|
||||||
tileoffsetlat,
|
new OpenLayers.Bounds(tileoffsetlon,
|
||||||
tileoffsetlon + tilelon,
|
tileoffsetlat,
|
||||||
tileoffsetlat + tilelat);
|
tileoffsetlon + tilelon,
|
||||||
|
tileoffsetlat + tilelat);
|
||||||
|
|
||||||
var x = tileoffsetx;
|
var x = tileoffsetx;
|
||||||
x -= parseInt(this.map.layerContainerDiv.style.left);
|
x -= parseInt(this.map.layerContainerDiv.style.left);
|
||||||
@@ -172,11 +173,10 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
y -= parseInt(this.map.layerContainerDiv.style.top);
|
y -= parseInt(this.map.layerContainerDiv.style.top);
|
||||||
|
|
||||||
var px = new OpenLayers.Pixel(x, y);
|
var px = new OpenLayers.Pixel(x, y);
|
||||||
var tile;
|
var tile = row[colidx++];
|
||||||
|
|
||||||
tile = row[colidx++];
|
|
||||||
if (!tile) {
|
if (!tile) {
|
||||||
tile = this.addTile(tileBounds, px);
|
tile = this.addTile(tileBounds, px);
|
||||||
|
this.addTileMonitoringHooks(tile);
|
||||||
row.push(tile);
|
row.push(tile);
|
||||||
} else {
|
} else {
|
||||||
tile.moveTo(tileBounds, px, false);
|
tile.moveTo(tileBounds, px, false);
|
||||||
@@ -184,12 +184,18 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
|
|
||||||
tileoffsetlon += tilelon;
|
tileoffsetlon += tilelon;
|
||||||
tileoffsetx += this.tileSize.w;
|
tileoffsetx += this.tileSize.w;
|
||||||
} while (tileoffsetlon <= bounds.right + tilelon * this.buffer)
|
} while (tileoffsetlon <= bounds.right + tilelon * this.buffer
|
||||||
|
|| colidx < minCols)
|
||||||
|
|
||||||
tileoffsetlat -= tilelat;
|
tileoffsetlat -= tilelat;
|
||||||
tileoffsety += this.tileSize.h;
|
tileoffsety += this.tileSize.h;
|
||||||
} while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
|
} while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer
|
||||||
|
|| rowidx < minRows)
|
||||||
|
|
||||||
|
//shave off exceess rows and colums
|
||||||
|
this.removeExcessTiles(rowidx, colidx);
|
||||||
|
|
||||||
|
//now actually draw the tiles
|
||||||
this.spiralTileLoad();
|
this.spiralTileLoad();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -547,6 +547,41 @@
|
|||||||
t.eq(bounds.toBBOX(), "0,-90,180,90", "get tile bounds returns correct bounds after pan");
|
t.eq(bounds.toBBOX(), "0,-90,180,90", "get tile bounds returns correct bounds after pan");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Layer_Grid_moveTo_buffer_calculation (t) {
|
||||||
|
t.plan(6);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map( 'map3' ); // odd map size
|
||||||
|
var layer0 = new OpenLayers.Layer.WMS( "0 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':0} );
|
||||||
|
map.addLayer(layer0);
|
||||||
|
|
||||||
|
var layer1 = new OpenLayers.Layer.WMS( "1 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':1} );
|
||||||
|
map.addLayer(layer1);
|
||||||
|
|
||||||
|
var layer2 = new OpenLayers.Layer.WMS( "2 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':2} );
|
||||||
|
map.addLayer(layer2);
|
||||||
|
|
||||||
|
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" );
|
||||||
|
map.setBaseLayer(layer2);
|
||||||
|
t.eq( layer2.grid.length, 6, "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" );
|
||||||
|
map.setBaseLayer(layer2);
|
||||||
|
t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" );
|
||||||
|
}
|
||||||
|
|
||||||
function test_99_Layer_Grid_destroy (t) {
|
function test_99_Layer_Grid_destroy (t) {
|
||||||
|
|
||||||
t.plan( 5 );
|
t.plan( 5 );
|
||||||
@@ -582,5 +617,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map" style="width:499px;height:549px;display:none"></div>
|
<div id="map" style="width:499px;height:549px;display:none"></div>
|
||||||
<div id="map2" style="width:500px;height:550px;display:none"></div>
|
<div id="map2" style="width:500px;height:550px;display:none"></div>
|
||||||
|
<div id="map3" style="width:594px;height:464px;display:none"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -23,6 +23,40 @@
|
|||||||
t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
|
t.ok( layer instanceof OpenLayers.Layer.KaMap, "returns OpenLayers.Layer.KaMap object" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Layer_Grid_moveTo_buffer_calculation (t) {
|
||||||
|
t.plan(6);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map( 'map3' ); // odd map size
|
||||||
|
var layer0 = new OpenLayers.Layer.KaMap( "0 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':0} );
|
||||||
|
map.addLayer(layer0);
|
||||||
|
|
||||||
|
var layer1 = new OpenLayers.Layer.KaMap( "1 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':1} );
|
||||||
|
map.addLayer(layer1);
|
||||||
|
|
||||||
|
var layer2 = new OpenLayers.Layer.KaMap( "2 buffer: OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0",
|
||||||
|
{layers: 'basic'}, {'buffer':2} );
|
||||||
|
map.addLayer(layer2);
|
||||||
|
|
||||||
|
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" );
|
||||||
|
map.setBaseLayer(layer2);
|
||||||
|
t.eq( layer2.grid.length, 6, "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" );
|
||||||
|
map.setBaseLayer(layer2);
|
||||||
|
t.eq( layer2.grid.length, 6, "Grid rows with buffer:2" );
|
||||||
|
}
|
||||||
|
|
||||||
function test_02_Layer_KaMap_inittiles (t) {
|
function test_02_Layer_KaMap_inittiles (t) {
|
||||||
t.plan( 2 );
|
t.plan( 2 );
|
||||||
@@ -30,8 +64,8 @@
|
|||||||
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
|
layer = new OpenLayers.Layer.KaMap(name, url, params, units);
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
map.setCenter(new OpenLayers.LonLat(0,0),5);
|
map.setCenter(new OpenLayers.LonLat(0,0),5);
|
||||||
t.eq( layer.grid.length, 6, "KaMap rows is correct." );
|
t.eq( layer.grid.length, 8, "KaMap rows is correct." );
|
||||||
t.eq( layer.grid[0].length, 4, "KaMap cols is correct." );
|
t.eq( layer.grid[0].length, 6, "KaMap cols is correct." );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,5 +271,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map" style="width:500px;height:550px;display:none"></div>
|
<div id="map" style="width:500px;height:550px;display:none"></div>
|
||||||
|
<div id="map2" style="width:500px;height:550px;display:none"></div>
|
||||||
|
<div id="map3" style="width:594px;height:464px;display:none"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user