Changeset 602

Show
Ignore:
Timestamp:
07/16/08 16:16:14 (2 months ago)
Author:
tom
Message:

more refactoring to TileGrid in tween branch

Files:

Legend:

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

    r601 r602  
    3030                private var map:Map; 
    3131 
    32         // TILE_WIDTH and TILE_HEIGHT are now provider.tileWidth and provider.tileHeight 
     32        // TILE_WIDTH and TILE_HEIGHT are now tileWidth and tileHeight 
    3333        // this was needed for the NASA DailyPlanetProvider which has 512x512px tiles 
    3434                // public static const TILE_WIDTH:Number = 256; 
    3535                // public static const TILE_HEIGHT:Number = 256;         
    3636         
    37         public var minZoom:Number; 
    38         public var maxZoom:Number; 
     37        // read-only, kept up to date by calculateBounds() 
     38        protected var _minZoom:Number; 
     39        protected var _maxZoom:Number; 
    3940 
    4041                protected var minTx:Number, maxTx:Number, minTy:Number, maxTy:Number; 
     42 
     43                // read-only, convenience for tileWidth/Height 
     44                protected var _tileWidth:Number; 
     45                protected var _tileHeight:Number; 
     46 
    4147 
    4248                // pan and zoom etc are stored in here 
     
    94100 
    95101                // what zoom level of tiles is 'correct'? 
    96                 protected var currentZoom:int;  
     102                protected var _currentZoom:int;  
    97103                // so we know if we're going in or out 
    98104                protected var previousZoom:int;          
     
    158164                        this.draggable = draggable; 
    159165                        this.provider = provider; 
     166 
     167                        _tileWidth = provider.tileWidth; 
     168                        _tileHeight = provider.tileHeight; 
    160169 
    161170                        this.tileQueue = new TileQueue(); 
     
    286295                        // TODO deal with what happens with non-square projections! 
    287296                        var worldMin:Point = worldMatrix.transformPoint(new Point(0,0)); 
    288                         var worldMax:Point = worldMatrix.transformPoint(new Point(provider.tileWidth, provider.tileHeight)); 
     297                        var worldMax:Point = worldMatrix.transformPoint(new Point(tileWidth, tileHeight)); 
    289298 
    290299                        // what zoom level of tiles should we be loading, taking into account min/max zoom? 
     
    299308                         
    300309                        // this is the level of tiles we'll be loading: 
    301                         currentZoom = newZoom; 
     310                        _currentZoom = newZoom; 
    302311                 
    303312                        // this is how big the world is, in tiles: 
     
    493502                                var positionCol:Number = (scaleFactor*tile.column) - realMinCol; 
    494503                                var positionRow:Number = (scaleFactor*tile.row) - realMinRow; 
    495                                 tile.x = positionCol*provider.tileWidth*positionScaleCompensation; 
    496                                 tile.y = positionRow*provider.tileHeight*positionScaleCompensation; 
     504                                tile.x = positionCol*tileWidth*positionScaleCompensation; 
     505                                tile.y = positionRow*tileHeight*positionScaleCompensation; 
    497506                                 
    498507                                var tileScale:Number = Math.pow(2, zoomLevel-tile.zoom); 
    499                                 tileScale = Math.ceil(tileScale * provider.tileWidth) / provider.tileWidth; // round up to the nearest pixel 
     508                                tileScale = Math.ceil(tileScale * tileWidth) / tileWidth; // round up to the nearest pixel 
    500509                                tile.scaleX = tile.scaleY = tileScale;                           
    501510                        } 
     
    687696                                        if (tile) { 
    688697                                                delete layersNeeded[tile]; 
    689                                                 tile.paintError(provider.tileWidth, provider.tileHeight); 
     698                                                tile.paintError(tileWidth, tileHeight); 
    690699                                                if (tile.zoom == currentZoom) { 
    691700                                                        tile.show(); 
     
    738747                                _invertedMatrix = worldMatrix.clone(); 
    739748                                _invertedMatrix.invert(); 
    740                                 _invertedMatrix.scale(scale/provider.tileWidth, scale/provider.tileHeight); 
     749                                _invertedMatrix.scale(scale/tileWidth, scale/tileHeight); 
    741750                        } 
    742751                        return _invertedMatrix; 
     
    746755                        throw new Error("invertedMatrix is read only"); 
    747756                } 
     757 
     758                /** derived from map provider by calculateBounds(), read-only here for convenience */ 
     759                public function get minZoom():Number 
     760                { 
     761                        return _minZoom; 
     762                } 
     763                /** derived from map provider by calculateBounds(), read-only here for convenience */ 
     764                public function get maxZoom():Number 
     765                { 
     766                        return _maxZoom; 
     767                } 
     768 
     769                /** convenience method for tileWidth */ 
     770                public function get tileWidth():Number 
     771                { 
     772                        return _tileWidth; 
     773                } 
     774                /** convenience method for tileHeight */ 
     775                public function get tileHeight():Number 
     776                { 
     777                        return _tileHeight; 
     778                } 
     779 
     780                /** read-only, this is the level of tiles we'll be loading first */ 
     781                public function get currentZoom():Number 
     782                { 
     783                        return _currentZoom; 
     784                } 
     785 
    748786 
    749787                public function get topLeftCoordinate():Coordinate 
     
    871909                        worldMatrix.translate(mapWidth/2, mapHeight/2 ); 
    872910                        worldMatrix.translate(point.x, point.y); 
    873                         worldMatrix.translate(-provider.tileWidth*coord.column, -provider.tileHeight*coord.row); 
     911                        worldMatrix.translate(-tileWidth*coord.column, -tileHeight*coord.row); 
    874912 
    875913                        // reset the inverted matrix, request a redraw, etc. 
     
    947985                { 
    948986                        this.provider = provider; 
     987 
     988                        _tileWidth = provider.tileWidth; 
     989                        _tileHeight = provider.tileHeight; 
    949990                         
    950991                        calculateBounds(); 
     
    9931034                        var br:Coordinate = limits[1] as Coordinate; 
    9941035 
    995                         maxZoom = Math.max(tl.zoom, br.zoom);   
    996                         minZoom = Math.min(tl.zoom, br.zoom); 
     1036                        _maxZoom = Math.max(tl.zoom, br.zoom);   
     1037                        _minZoom = Math.min(tl.zoom, br.zoom); 
    9971038                         
    9981039                        tl = tl.zoomTo(0); 
    9991040                        br = br.zoomTo(0); 
    10001041 
    1001                         minTx = tl.column * provider.tileWidth; 
    1002                         maxTx = br.column * provider.tileWidth; 
    1003                         minTy = tl.row * provider.tileHeight; 
    1004                         maxTy = br.row * provider.tileHeight; 
     1042                        minTx = tl.column * tileWidth; 
     1043                        maxTx = br.column * tileWidth; 
     1044                        minTy = tl.row * tileHeight; 
     1045                        maxTy = br.row * tileHeight; 
    10051046                } 
    10061047                 
     
    10251066                        var br:Coordinate = bottomRightCoordinate.zoomTo(0); 
    10261067                         
    1027                         var leftX:Number = tl.column * provider.tileWidth; 
    1028                         var rightX:Number = br.column * provider.tileHeight; 
     1068                        var leftX:Number = tl.column * tileWidth; 
     1069                        var rightX:Number = br.column * tileHeight; 
    10291070                         
    10301071                        if (rightX-leftX > maxTx-minTx) { 
     
    10411082                        } 
    10421083 
    1043                         var upY:Number = tl.row * provider.tileHeight; 
    1044                         var downY:Number = br.row * provider.tileWidth; 
     1084                        var upY:Number = tl.row * tileHeight; 
     1085                        var downY:Number = br.row * tileWidth; 
    10451086 
    10461087                        if (downY-upY > maxTy-minTy) {