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:
Schuyler Erle
2007-09-15 14:48:22 +00:00
parent 121a5553f4
commit c941651e72
4 changed files with 103 additions and 22 deletions

View File

@@ -114,23 +114,25 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* Method: initGriddedTiles
*/
initGriddedTiles:function() {
initGriddedTiles:function(bounds) {
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 resolution = this.map.getResolution();
var tilelon = resolution*this.tileSize.w;
var tilelat = resolution*this.tileSize.h;
var offsetlon = bounds.left;
var tilecol = Math.floor(offsetlon/tilelon);
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
var tilecolremain = offsetlon/tilelon - tilecol;
var tileoffsetx = -tilecolremain * this.tileSize.w;
var tileoffsetlon = tilecol * tilelon;
var offsetlat = bounds.top;
var tilerow = Math.ceil(offsetlat/tilelat);
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
var tilerowremain = tilerow - offsetlat/tilelat;
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
var tileoffsetlat = tilerow * tilelat;
@@ -146,9 +148,7 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
var rowidx = 0;
do {
var row;
row = this.grid[rowidx++];
var row = this.grid[rowidx++];
if (!row) {
row = [];
this.grid.push(row);
@@ -160,10 +160,11 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
var colidx = 0;
do {
var tileBounds = new OpenLayers.Bounds(tileoffsetlon,
tileoffsetlat,
tileoffsetlon + tilelon,
tileoffsetlat + tilelat);
var tileBounds =
new OpenLayers.Bounds(tileoffsetlon,
tileoffsetlat,
tileoffsetlon + tilelon,
tileoffsetlat + tilelat);
var x = tileoffsetx;
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);
var px = new OpenLayers.Pixel(x, y);
var tile;
tile = row[colidx++];
var tile = row[colidx++];
if (!tile) {
tile = this.addTile(tileBounds, px);
this.addTileMonitoringHooks(tile);
row.push(tile);
} else {
tile.moveTo(tileBounds, px, false);
@@ -184,12 +184,18 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
tileoffsetlon += tilelon;
tileoffsetx += this.tileSize.w;
} while (tileoffsetlon <= bounds.right + tilelon * this.buffer)
} while (tileoffsetlon <= bounds.right + tilelon * this.buffer
|| colidx < minCols)
tileoffsetlat -= tilelat;
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();
},