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:
crschmidt
2006-12-22 18:35:04 +00:00
parent b46a513077
commit 7e9eef8d07
5 changed files with 80 additions and 41 deletions
+45 -7
View File
@@ -107,21 +107,33 @@ OpenLayers.Layer.Grid.prototype =
|| !this.getGridBounds().containsBounds(bounds, true)) { || !this.getGridBounds().containsBounds(bounds, true)) {
this._initTiles(); this._initTiles();
} else { } else {
var buffer = (this.buffer) ? this.buffer*1.5 : 1;
while (true) { while (true) {
var tlLayer = this.grid[0][0].position; var tlLayer = this.grid[0][0].position;
var tlViewPort = var tlViewPort =
this.map.getViewPortPxFromLayerPx(tlLayer); this.map.getViewPortPxFromLayerPx(tlLayer);
if (tlViewPort.x > -this.tileSize.w * (this.buffer - 1)) { if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) {
this.shiftColumn(true); this.shiftColumn(true);
} else if (tlViewPort.x < -this.tileSize.w * this.buffer) { } else if (tlViewPort.x < -this.tileSize.w * buffer) {
this.shiftColumn(false); 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); this.shiftRow(true);
} else if (tlViewPort.y < -this.tileSize.h * this.buffer) { } else if (tlViewPort.y < -this.tileSize.h * buffer) {
this.shiftRow(false); this.shiftRow(false);
} else { } else {
break; 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 * @private
*/ */
_initTiles:function() { _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 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 bounds = this.map.getExtent();
var extent = this.map.getMaxExtent(); var extent = this.map.getMaxExtent();
var resolution = this.map.getResolution(); var resolution = this.map.getResolution();
@@ -216,11 +234,30 @@ OpenLayers.Layer.Grid.prototype =
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)
// 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 //now actually draw the tiles
this.spiralTileLoad(); this.spiralTileLoad();
@@ -325,8 +362,9 @@ OpenLayers.Layer.Grid.prototype =
for(var iRow=0; iRow < this.grid.length; iRow++) { for(var iRow=0; iRow < this.grid.length; iRow++) {
var row = this.grid[iRow]; var row = this.grid[iRow];
for(var iCol=0; iCol < row.length; iCol++) { for(var iCol=0; iCol < row.length; iCol++) {
OpenLayers.Util.clearArray(row[iCol]); row[iCol].destroy();
} }
this.grid = [];
} }
} }
}, },
+6 -1
View File
@@ -69,7 +69,12 @@ OpenLayers.Tile.prototype = {
/** /**
*/ */
draw:function() { draw:function() {
this.drawn = true; this.clear();
return ((this.layer.displayOutsideMaxExtent
|| (this.layer.maxExtent
&& this.bounds.intersectsBounds(this.layer.maxExtent, false)))
&& !(this.layer.buffer == 0
&& !this.bounds.intersectsBounds(this.layer.map.getExtent(), false)));
}, },
/** /**
+16 -17
View File
@@ -43,29 +43,28 @@ OpenLayers.Tile.Image.prototype =
* *
*/ */
draw:function() { draw:function() {
OpenLayers.Tile.prototype.draw.apply(this, arguments);
if (this.imgDiv == null) {
this.initImgDiv();
}
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
this.bounds = this.getBoundsFromBaseLayer(this.position); this.bounds = this.getBoundsFromBaseLayer(this.position);
} }
if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
return false;
}
if (this.imgDiv == null) {
this.initImgDiv();
}
this.url = this.layer.getURL(this.bounds); this.url = this.layer.getURL(this.bounds);
this.imgDiv.style.display = "none";
if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent && if (this.layer.alpha) {
(this.bounds.intersectsBounds(this.layer.maxExtent,false)) OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
)) { null, this.position, this.size, this.url);
if (this.layer.alpha) { } else {
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, this.imgDiv.src = this.url;
null, this.position, this.size, this.url); OpenLayers.Util.modifyDOMElement(this.imgDiv,
} else { null, this.position, this.size) ;
this.imgDiv.src = this.url;
OpenLayers.Util.modifyDOMElement(this.imgDiv,
null, this.position, this.size) ;
}
} }
this.drawn = true;
return true;
}, },
/** Clear the tile of any bounds/position-related data so that it can /** Clear the tile of any bounds/position-related data so that it can
+5 -7
View File
@@ -57,14 +57,12 @@ OpenLayers.Tile.WFS.prototype =
* *
*/ */
draw:function() { draw:function() {
if (this.drawn) { if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
this.clear(); return false;
}
OpenLayers.Tile.prototype.draw.apply(this, arguments);
if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent &&
this.layer.maxExtent.intersectsBounds(this.bounds, false))) {
this.loadFeaturesForRegion(this.requestSuccess);
} }
this.loadFeaturesForRegion(this.requestSuccess);
this.drawn = true;
return true;
}, },
/** get the full request string from the ds and the tile params /** get the full request string from the ds and the tile params
+4 -5
View File
@@ -73,7 +73,7 @@
map.addLayer(layer); map.addLayer(layer);
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size); tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size);
tile.draw() tile.draw()
t.eq(tile.imgDiv.src, "", "Images against side of maxextent don't load"); t.eq(tile.imgDiv, null, "Images against side of maxextent don't load");
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-181,-91,180,90), url, size); tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-181,-91,180,90), url, size);
tile.draw() tile.draw()
var tParams = { var tParams = {
@@ -144,7 +144,7 @@
"Image covering more than all of extent loads"); "Image covering more than all of extent loads");
} }
function test_04_Tile_Image_Display_After_Move(t) { function test_04_Tile_Image_Display_After_Move(t) {
t.plan(3); t.plan(2);
var position = new OpenLayers.Pixel(20,30); var position = new OpenLayers.Pixel(20,30);
var bounds = new OpenLayers.Bounds(1,2,3,4); var bounds = new OpenLayers.Bounds(1,2,3,4);
var url = "http://www.openlayers.org/dev/tests/tileimage"; var url = "http://www.openlayers.org/dev/tests/tileimage";
@@ -157,15 +157,14 @@
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size); tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size);
tile.draw(); tile.draw();
tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true); tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true);
t.delay_call( 1, function() { t.eq(tile.imgDiv.style.display, 'none', "Tile display is set to none.") } ); t.delay_call( 1, function() { t.eq(tile.imgDiv, null, "Tile imgDiv is null.") } );
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {'alpha':true}); "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {'alpha':true});
map.addLayer(layer); map.addLayer(layer);
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size); tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size);
tile.draw(); tile.draw();
tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true) tile.moveTo(new OpenLayers.Bounds(-185,-90,-180,-80), new OpenLayers.Pixel(-180,-85), true)
t.ok(tile.imgDiv.firstChild.src != tile.url, "Check to make sure that the alpha image URL really is different"); t.delay_call( 1, function() { t.eq(tile.imgDiv, null, "Alpha tile imgDiv is null.") } );
t.delay_call( 1, function() { t.eq(tile.imgDiv.style.display, 'none', "Alpha tile display is set to none.") } );
} }
// --> // -->