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