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 = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -69,7 +69,12 @@ OpenLayers.Tile.prototype = {
|
||||
/**
|
||||
*/
|
||||
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)));
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,29 +43,28 @@ OpenLayers.Tile.Image.prototype =
|
||||
*
|
||||
*/
|
||||
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) {
|
||||
this.bounds = this.getBoundsFromBaseLayer(this.position);
|
||||
}
|
||||
|
||||
this.url = this.layer.getURL(this.bounds);
|
||||
this.imgDiv.style.display = "none";
|
||||
if (this.layer.displayOutsideMaxExtent || (this.layer.maxExtent &&
|
||||
(this.bounds.intersectsBounds(this.layer.maxExtent,false))
|
||||
)) {
|
||||
if (this.layer.alpha) {
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
|
||||
null, this.position, this.size, this.url);
|
||||
} else {
|
||||
this.imgDiv.src = this.url;
|
||||
OpenLayers.Util.modifyDOMElement(this.imgDiv,
|
||||
null, this.position, this.size) ;
|
||||
}
|
||||
if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
|
||||
return false;
|
||||
}
|
||||
if (this.imgDiv == null) {
|
||||
this.initImgDiv();
|
||||
}
|
||||
|
||||
this.url = this.layer.getURL(this.bounds);
|
||||
|
||||
if (this.layer.alpha) {
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
|
||||
null, this.position, this.size, this.url);
|
||||
} else {
|
||||
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
|
||||
|
||||
@@ -57,14 +57,12 @@ OpenLayers.Tile.WFS.prototype =
|
||||
*
|
||||
*/
|
||||
draw:function() {
|
||||
if (this.drawn) {
|
||||
this.clear();
|
||||
if (!OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
|
||||
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
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
map.addLayer(layer);
|
||||
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-185,-90,-180,90), url, size);
|
||||
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.draw()
|
||||
var tParams = {
|
||||
@@ -144,7 +144,7 @@
|
||||
"Image covering more than all of extent loads");
|
||||
}
|
||||
function test_04_Tile_Image_Display_After_Move(t) {
|
||||
t.plan(3);
|
||||
t.plan(2);
|
||||
var position = new OpenLayers.Pixel(20,30);
|
||||
var bounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
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.draw();
|
||||
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",
|
||||
"http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}, {'alpha':true});
|
||||
map.addLayer(layer);
|
||||
tile = new OpenLayers.Tile.Image(layer, position, new OpenLayers.Bounds(-90,-85,-90,85), url, size);
|
||||
tile.draw();
|
||||
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.style.display, 'none', "Alpha tile display is set to none.") } );
|
||||
t.delay_call( 1, function() { t.eq(tile.imgDiv, null, "Alpha tile imgDiv is null.") } );
|
||||
|
||||
}
|
||||
// -->
|
||||
|
||||
Reference in New Issue
Block a user