From 0f9065cd118bcf2b1ea8e2ce35314d60510a4264 Mon Sep 17 00:00:00 2001 From: euzuro Date: Sat, 12 Aug 2006 15:58:25 +0000 Subject: [PATCH] clean up code a wee lite bit in the initGrid() function... then remove the draw() call and change the moveTo() call to not trigger a redraw() on the tile. This way the initTiles() goes through and configures the tiles with everything they need... but without actually redrawing them. Then we add the spiralTileLoad() function which will go through and actually trigger the redraw on the tiles, but in that spiraling outwards way git-svn-id: http://svn.openlayers.org/trunk/openlayers@1199 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Grid.js | 74 +++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index c22e6e209f..a271bb1800 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -38,7 +38,7 @@ OpenLayers.Layer.Grid.prototype = }, /** on destroy, clear the grid. - * + * */ destroy: function() { this.clearGrid(); @@ -219,9 +219,7 @@ OpenLayers.Layer.Grid.prototype = var rowidx = 0; do { - var row; - - row = this.grid[rowidx++]; + var row = this.grid[rowidx++]; if (!row) { row = new Array(); this.grid.push(row); @@ -229,7 +227,6 @@ OpenLayers.Layer.Grid.prototype = tileoffsetlon = startLon; tileoffsetx = startX; - var colidx = 0; do { @@ -245,15 +242,12 @@ OpenLayers.Layer.Grid.prototype = 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); - tile.draw(); row.push(tile); } else { - tile.moveTo(tileBounds, px); + tile.moveTo(tileBounds, px, false); } tileoffsetlon += tilelon; @@ -264,8 +258,68 @@ OpenLayers.Layer.Grid.prototype = tileoffsety += this.tileSize.h; } while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer) + //now actually draw the tiles + this.spiralTileLoad(); }, + /** + * + */ + spiralTileLoad: function() { + var tileQueue = new Array(); + + var directions = ["right", "down", "left", "up"]; + + var iRow = 0; + var iCell = -1; + var direction = directions.indexOf("right"); + var directionsTried = 0; + + while( directionsTried < directions.length) { + + var testRow = iRow; + var testCell = iCell; + + switch (directions[direction]) { + case "right": + testCell++; + break; + case "down": + testRow++; + break; + case "left": + testCell--; + break; + case "up": + testRow--; + break; + } + + var tile = null; + if ((testRow < this.grid.length) && + (testCell < this.grid[0].length)) { + tile = this.grid[testRow][testCell]; + } + + if ((tile != null) && (!tile.queued)) { + tileQueue.unshift(tile); + tile.queued = true; + directionsTried = 0; + iRow = testRow; + iCell = testCell; + } else { + direction = (direction + 1) % 4; + directionsTried++; + } + } + + // now we go through and draw the tiles in forward order + for(var i=0; i < tileQueue.length; i++) { + var tile = tileQueue[i] + tile.draw(); + tile.queued = false; + } + }, /** * addTile gives subclasses of Grid the opportunity to create an