Commit a number of improvements to grid handling from #449. This adds
support for buffer:0 on grids, and includes changes to Remove extra rows and columns from the grid in _initTiles when reusing an existing grid, which is a fix to #357 and #436. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2091 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -107,21 +107,33 @@ OpenLayers.Layer.Grid.prototype =
|
||||
|| !this.getGridBounds().containsBounds(bounds, true)) {
|
||||
this._initTiles();
|
||||
} else {
|
||||
var buffer = (this.buffer) ? this.buffer*1.5 : 1;
|
||||
while (true) {
|
||||
var tlLayer = this.grid[0][0].position;
|
||||
var tlViewPort =
|
||||
this.map.getViewPortPxFromLayerPx(tlLayer);
|
||||
if (tlViewPort.x > -this.tileSize.w * (this.buffer - 1)) {
|
||||
if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) {
|
||||
this.shiftColumn(true);
|
||||
} else if (tlViewPort.x < -this.tileSize.w * this.buffer) {
|
||||
} else if (tlViewPort.x < -this.tileSize.w * buffer) {
|
||||
this.shiftColumn(false);
|
||||
} else if (tlViewPort.y > -this.tileSize.h * (this.buffer - 1)) {
|
||||
} else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) {
|
||||
this.shiftRow(true);
|
||||
} else if (tlViewPort.y < -this.tileSize.h * this.buffer) {
|
||||
} else if (tlViewPort.y < -this.tileSize.h * buffer) {
|
||||
this.shiftRow(false);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
};
|
||||
if (this.buffer == 0) {
|
||||
for (var r=0, rl=this.grid.length; r<rl; r++) {
|
||||
var row = this.grid[r];
|
||||
for (var c=0, cl=row.length; c<cl; c++) {
|
||||
var tile = row[c];
|
||||
if (!tile.drawn && tile.bounds.intersectsBounds(bounds, false)) {
|
||||
tile.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +165,13 @@ OpenLayers.Layer.Grid.prototype =
|
||||
* @private
|
||||
*/
|
||||
_initTiles:function() {
|
||||
|
||||
// work out mininum number of rows and columns; this is the number of
|
||||
// tiles required to cover the viewport plus one for panning
|
||||
var viewSize = this.map.getSize();
|
||||
var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 1;
|
||||
var minCols = Math.ceil(viewSize.w/this.tileSize.w) + 1;
|
||||
|
||||
var bounds = this.map.getExtent();
|
||||
var extent = this.map.getMaxExtent();
|
||||
var resolution = this.map.getResolution();
|
||||
@@ -216,12 +234,31 @@ OpenLayers.Layer.Grid.prototype =
|
||||
|
||||
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)
|
||||
|
||||
// remove extra rows
|
||||
while (this.grid.length > rowidx) {
|
||||
var row = this.grid.pop();
|
||||
for (var i=0, l=row.length; i<l; i++) {
|
||||
row[i].destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// remove extra columns
|
||||
while (this.grid[0].length > colidx) {
|
||||
for (var i=0, l=this.grid.length; i<l; i++) {
|
||||
var row = this.grid[i];
|
||||
var tile = row.pop();
|
||||
tile.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
//now actually draw the tiles
|
||||
this.spiralTileLoad();
|
||||
},
|
||||
@@ -325,8 +362,9 @@ OpenLayers.Layer.Grid.prototype =
|
||||
for(var iRow=0; iRow < this.grid.length; iRow++) {
|
||||
var row = this.grid[iRow];
|
||||
for(var iCol=0; iCol < row.length; iCol++) {
|
||||
OpenLayers.Util.clearArray(row[iCol]);
|
||||
row[iCol].destroy();
|
||||
}
|
||||
this.grid = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user