Changeset 602
- Timestamp:
- 07/16/08 16:16:14 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as
r601 r602 30 30 private var map:Map; 31 31 32 // TILE_WIDTH and TILE_HEIGHT are now provider.tileWidth and provider.tileHeight32 // TILE_WIDTH and TILE_HEIGHT are now tileWidth and tileHeight 33 33 // this was needed for the NASA DailyPlanetProvider which has 512x512px tiles 34 34 // public static const TILE_WIDTH:Number = 256; 35 35 // public static const TILE_HEIGHT:Number = 256; 36 36 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; 39 40 40 41 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 41 47 42 48 // pan and zoom etc are stored in here … … 94 100 95 101 // what zoom level of tiles is 'correct'? 96 protected var currentZoom:int;102 protected var _currentZoom:int; 97 103 // so we know if we're going in or out 98 104 protected var previousZoom:int; … … 158 164 this.draggable = draggable; 159 165 this.provider = provider; 166 167 _tileWidth = provider.tileWidth; 168 _tileHeight = provider.tileHeight; 160 169 161 170 this.tileQueue = new TileQueue(); … … 286 295 // TODO deal with what happens with non-square projections! 287 296 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)); 289 298 290 299 // what zoom level of tiles should we be loading, taking into account min/max zoom? … … 299 308 300 309 // this is the level of tiles we'll be loading: 301 currentZoom = newZoom;310 _currentZoom = newZoom; 302 311 303 312 // this is how big the world is, in tiles: … … 493 502 var positionCol:Number = (scaleFactor*tile.column) - realMinCol; 494 503 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; 497 506 498 507 var tileScale:Number = Math.pow(2, zoomLevel-tile.zoom); 499 tileScale = Math.ceil(tileScale * provider.tileWidth) / provider.tileWidth; // round up to the nearest pixel508 tileScale = Math.ceil(tileScale * tileWidth) / tileWidth; // round up to the nearest pixel 500 509 tile.scaleX = tile.scaleY = tileScale; 501 510 } … … 687 696 if (tile) { 688 697 delete layersNeeded[tile]; 689 tile.paintError( provider.tileWidth, provider.tileHeight);698 tile.paintError(tileWidth, tileHeight); 690 699 if (tile.zoom == currentZoom) { 691 700 tile.show(); … … 738 747 _invertedMatrix = worldMatrix.clone(); 739 748 _invertedMatrix.invert(); 740 _invertedMatrix.scale(scale/ provider.tileWidth, scale/provider.tileHeight);749 _invertedMatrix.scale(scale/tileWidth, scale/tileHeight); 741 750 } 742 751 return _invertedMatrix; … … 746 755 throw new Error("invertedMatrix is read only"); 747 756 } 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 748 786 749 787 public function get topLeftCoordinate():Coordinate … … 871 909 worldMatrix.translate(mapWidth/2, mapHeight/2 ); 872 910 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); 874 912 875 913 // reset the inverted matrix, request a redraw, etc. … … 947 985 { 948 986 this.provider = provider; 987 988 _tileWidth = provider.tileWidth; 989 _tileHeight = provider.tileHeight; 949 990 950 991 calculateBounds(); … … 993 1034 var br:Coordinate = limits[1] as Coordinate; 994 1035 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); 997 1038 998 1039 tl = tl.zoomTo(0); 999 1040 br = br.zoomTo(0); 1000 1041 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; 1005 1046 } 1006 1047 … … 1025 1066 var br:Coordinate = bottomRightCoordinate.zoomTo(0); 1026 1067 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; 1029 1070 1030 1071 if (rightX-leftX > maxTx-minTx) { … … 1041 1082 } 1042 1083 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; 1045 1086 1046 1087 if (downY-upY > maxTy-minTy) {
