Changeset 581

Show
Ignore:
Timestamp:
06/26/08 16:56:15 (5 months ago)
Author:
tom
Message:

making options be instance variables in TileGrid

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as

    r580 r581  
    4040 
    4141                // pan, zoom and rotate 
    42                 private var _panX:Number = -TILE_WIDTH/2; 
    43                 private var _panY:Number = -TILE_HEIGHT/2; 
    44                 private var _scale:Number = 1; 
     42                protected var _panX:Number = -TILE_WIDTH/2; 
     43                protected var _panY:Number = -TILE_HEIGHT/2; 
     44                protected var _scale:Number = 1; 
    4545                 
    4646                protected var worldMatrix:Matrix; 
     
    110110                public var zooming:Boolean; 
    111111 
     112                protected static const DEFAULT_MAX_PARENT_SEARCH:int = 5; 
     113                protected static const DEFAULT_MAX_CHILD_SEARCH:int = 1; 
     114                protected static const DEFAULT_MAX_TILES_TO_KEEP:int = 256; 
     115                protected static const DEFAULT_TILE_BUFFER:int = 0; 
     116                protected static const DEFAULT_ENFORCE_BOUNDS:Boolean = false; 
     117 
    112118                /** if we don't have a tile at currentZoom, onRender will look for tiles up to 5 levels out. 
    113119                 *  set this to 0 if you only want the current zoom level's tiles 
    114                  *  WARNING: tiles will get scaled up A LOT for this, but maybe it beats blank tiles? 
    115                  *  TODO: move to MapConfig? */  
    116                 public static var MAX_PARENT_SEARCH:int = 5; 
     120                 *  WARNING: tiles will get scaled up A LOT for this, but maybe it beats blank tiles? */  
     121                public var maxParentSearch:int = DEFAULT_MAX_PARENT_SEARCH; 
    117122                /** if we don't have a tile at currentZoom, onRender will look for tiles up to one levels further in. 
    118123                 *  set this to 0 if you only want the current zoom level's tiles 
    119124                 *  WARNING: bad, bad nasty recursion possibilities really soon if you go much above 1 
    120                  *  - it works, but you probably don't want to change this number :) 
    121                  *  TODO: move to MapConfig? */  
    122                 public static var MAX_CHILD_SEARCH:int = 1; 
     125                 *  - it works, but you probably don't want to change this number :) */ 
     126                public var maxChildSearch:int = DEFAULT_MAX_CHILD_SEARCH; 
    123127                 
    124128                // TODO: move to MapConfig 
    125                 public static var MAX_TILES_TO_KEEP:int = 256; // 256*256*4bytes = 0.25MB ... so 256 tiles is 64MB of memory, minimum! 
     129                public var maxTilesToKeep:int = DEFAULT_MAX_TILES_TO_KEEP; // 256*256*4bytes = 0.25MB ... so 256 tiles is 64MB of memory, minimum! 
    126130                 
    127131                // 0 or 1, really: 2 will load *lots* of extra tiles 
    128                 public static var TILE_BUFFER:int = 0
     132                public var tileBuffer:int = DEFAULT_TILE_BUFFER
    129133 
    130134                // set this to true to enable enforcing of map bounds from the map provider's limits 
    131                 public static var ENFORCE_BOUNDS:Boolean = false
     135                public var enforceBoundsEnabled:Boolean = DEFAULT_ENFORCE_BOUNDS
    132136                 
    133137                public var mapWidth:Number; 
     
    294298                        // optionally pad it out a little bit more 
    295299                        // TODO: investigate giving a directional bias to TILE_BUFFER when panning quickly 
    296                         minCol -= TILE_BUFFER
    297                         maxCol += TILE_BUFFER
    298                         minRow -= TILE_BUFFER
    299                         maxRow += TILE_BUFFER;  
     300                        minCol -= tileBuffer
     301                        maxCol += tileBuffer
     302                        minRow -= tileBuffer
     303                        maxRow += tileBuffer;  
    300304                         
    301305                        visibleTiles = []; 
     
    353357                                                 
    354358                                                // if it still doesn't have enough images yet, or it's fading in, try a double size parent instead 
    355                                                 if (MAX_PARENT_SEARCH > 0 && !tileReady && currentZoom > minZoom) { 
     359                                                if (maxParentSearch > 0 && !tileReady && currentZoom > minZoom) { 
    356360                                                        pkey = parentKey(col, row, currentZoom, currentZoom-1); 
    357361                                                        if (alreadySeen[pkey] is Tile) { 
     
    369373                                                 
    370374                                                // if it doesn't have an image yet, see if we can make it from smaller images 
    371                                                 if (!foundParent && MAX_CHILD_SEARCH > 0 && !tileReady && currentZoom < maxZoom) { 
    372                                                         for (var czoom:int = currentZoom+1; czoom <= Math.min(maxZoom, currentZoom+MAX_CHILD_SEARCH); czoom++) { 
     375                                                if (!foundParent && maxChildSearch > 0 && !tileReady && currentZoom < maxZoom) { 
     376                                                        for (var czoom:int = currentZoom+1; czoom <= Math.min(maxZoom, currentZoom+maxChildSearch); czoom++) { 
    373377                                                                var ckeys:Array = childKeys(col, row, currentZoom, czoom); 
    374378                                                                for each (var ckey:String in ckeys) { 
     
    393397                                        } 
    394398                                         
    395                                         var endZoomSearch:int = Math.max(minZoom, currentZoom-MAX_PARENT_SEARCH); 
     399                                        var endZoomSearch:int = Math.max(minZoom, currentZoom-maxParentSearch); 
    396400 
    397401                                        var stillNeedsAnImage:Boolean = !foundParent && foundChildren < 4;                                       
    398402                                        // if it still doesn't have an image yet, try more parent zooms 
    399                                         if (stillNeedsAnImage && MAX_PARENT_SEARCH > 1 && tileReady && currentZoom > minZoom) { 
     403                                        if (stillNeedsAnImage && maxParentSearch > 1 && tileReady && currentZoom > minZoom) { 
    400404                                                for (pzoom = startZoomSearch; pzoom >= endZoomSearch; pzoom--) { 
    401405                                                        pkey = parentKey(col, row, currentZoom, pzoom); 
     
    464468                        // all the visible tiles will be at the end of recentlySeen 
    465469                        // let's make sure we keep them around: 
    466                         var maxRecentlySeen:int = Math.max(visibleTiles.length,MAX_TILES_TO_KEEP); 
     470                        var maxRecentlySeen:int = Math.max(visibleTiles.length,maxTilesToKeep); 
    467471/*                      trace(); 
    468472                        trace('visibleTiles', visibleTiles.length); 
     
    473477                        if (recentlySeen.length > maxRecentlySeen) { 
    474478                                // throw away keys at the beginning of recentlySeen 
    475                                 recentlySeen = recentlySeen.slice(recentlySeen.length - MAX_TILES_TO_KEEP, recentlySeen.length); 
     479                                recentlySeen = recentlySeen.slice(recentlySeen.length - maxTilesToKeep, recentlySeen.length); 
    476480                                // loop over our internal tile cache  
    477481                                // and throw out tiles not in recentlySeen  
     
    10201024                protected function enforceBounds():Boolean 
    10211025                { 
    1022                         if (!ENFORCE_BOUNDS) { 
     1026                        if (!enforceBoundsEnabled) { 
    10231027                                return false; 
    10241028                        }