OpenLayers OpenLayers

Changeset 1199

Show
Ignore:
Timestamp:
08/12/06 11:58:25 (2 years ago)
Author:
euzuro
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Layer/Grid.js

    r1171 r1199  
    3939 
    4040    /** on destroy, clear the grid. 
    41      *  
     41     * 
    4242     */ 
    4343    destroy: function() { 
     
    220220     
    221221        do { 
    222             var row; 
    223              
    224             row = this.grid[rowidx++]; 
     222            var row = this.grid[rowidx++]; 
    225223            if (!row) { 
    226224                row = new Array(); 
     
    230228            tileoffsetlon = startLon; 
    231229            tileoffsetx = startX; 
    232  
    233230            var colidx = 0; 
    234231  
     
    246243 
    247244                var px = new OpenLayers.Pixel(x, y); 
    248                 var tile; 
    249                  
    250                 tile = row[colidx++]; 
     245                var tile = row[colidx++]; 
    251246                if (!tile) { 
    252247                    tile = this.addTile(tileBounds, px); 
    253                     tile.draw(); 
    254248                    row.push(tile); 
    255249                } else { 
    256                     tile.moveTo(tileBounds, px); 
     250                    tile.moveTo(tileBounds, px, false); 
    257251                } 
    258252      
     
    265259        } while(tileoffsetlat >= bounds.bottom - tilelat * this.buffer) 
    266260 
    267     }, 
    268      
     261        //now actually draw the tiles 
     262        this.spiralTileLoad(); 
     263    }, 
     264     
     265    /** 
     266     *  
     267     */ 
     268    spiralTileLoad: function() { 
     269        var tileQueue = new Array(); 
     270  
     271        var directions = ["right", "down", "left", "up"]; 
     272 
     273        var iRow = 0; 
     274        var iCell = -1; 
     275        var direction = directions.indexOf("right"); 
     276        var directionsTried = 0; 
     277         
     278        while( directionsTried < directions.length) { 
     279 
     280            var testRow = iRow; 
     281            var testCell = iCell; 
     282 
     283            switch (directions[direction]) { 
     284                case "right": 
     285                    testCell++; 
     286                    break; 
     287                case "down": 
     288                    testRow++; 
     289                    break; 
     290                case "left": 
     291                    testCell--; 
     292                    break; 
     293                case "up": 
     294                    testRow--; 
     295                    break; 
     296            }  
     297     
     298            var tile = null; 
     299            if ((testRow < this.grid.length) &&  
     300                (testCell < this.grid[0].length)) { 
     301                tile = this.grid[testRow][testCell]; 
     302            } 
     303             
     304            if ((tile != null) && (!tile.queued)) { 
     305                tileQueue.unshift(tile); 
     306                tile.queued = true; 
     307                directionsTried = 0; 
     308                iRow = testRow; 
     309                iCell = testCell; 
     310            } else { 
     311                direction = (direction + 1) % 4; 
     312                directionsTried++; 
     313            } 
     314        }  
     315         
     316        // now we go through and draw the tiles in forward order 
     317        for(var i=0; i < tileQueue.length; i++) { 
     318            var tile = tileQueue[i] 
     319            tile.draw(); 
     320            tile.queued = false;        
     321        } 
     322    }, 
    269323 
    270324    /**