Changeset 601
- Timestamp:
- 07/16/08 13:56:25 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as
r600 r601 60 60 protected var provider:IMapProvider; 61 61 62 // Tiles we want to load: 63 protected var queue:Array = []; 62 protected var tileQueue:TileQueue; 64 63 65 64 // per-tile, the number of images we're expecting to load … … 83 82 // currently visible tiles 84 83 protected var visibleTiles:Array = []; 85 86 // TODO: move to MapConfig 87 public static var MAX_OPEN_REQUESTS:int = 4; 88 84 89 85 // number of tiles we're failing to show 90 86 protected var blankCount:int = 0; … … 119 115 protected static const DEFAULT_TILE_BUFFER:int = 0; 120 116 protected static const DEFAULT_ENFORCE_BOUNDS:Boolean = true; 117 protected static const DEFAULT_MAX_OPEN_REQUESTS:int = 4; 121 118 122 119 /** if we don't have a tile at currentZoom, onRender will look for tiles up to 5 levels out. … … 135 132 // 0 or 1, really: 2 will load *lots* of extra tiles 136 133 public var tileBuffer:int = DEFAULT_TILE_BUFFER; 134 135 // how many Loaders are allowed to be open at once? 136 public var maxOpenRequests:int = DEFAULT_MAX_OPEN_REQUESTS; 137 137 138 138 // set this to true to enable enforcing of map bounds from the map provider's limits … … 158 158 this.draggable = draggable; 159 159 this.provider = provider; 160 161 this.tileQueue = new TileQueue(); 160 162 161 163 doubleClickEnabled = true; … … 235 237 + "\ncurrent child count: " + well.numChildren 236 238 + "\nvisible tile count: " + visibleTiles.length 237 + "\nqueue length: " + queue.length239 + "\nqueue length: " + tileQueue.length 238 240 + "\nblank count: " + blankCount 239 241 + "\nrequests: " + openRequests.length … … 352 354 // keep a local copy of the URLs so we don't have to call this twice: 353 355 layersNeeded[tile] = provider.getTileUrls(coord); 354 queue.push(tile);356 tileQueue.push(tile); 355 357 } 356 358 else { … … 527 529 { 528 530 // prepare the queue 529 if (openRequests.length < MAX_OPEN_REQUESTS && queue.length > 0) {531 if (openRequests.length < maxOpenRequests && tileQueue.length > 0) { 530 532 531 533 // prune queue for tiles that aren't visible 532 queue = queue.filter(function(tile:Tile, i:int, a:Array):Boolean { 533 return visibleTiles.indexOf(tile) >= 0; 534 }); 534 tileQueue.retainAll(visibleTiles); 535 535 536 536 // note that queue is not the same as visible tiles, because things … … 539 539 540 540 // sort queue by distance from 'center' 541 queue = queue.sort(centerDistanceCompare);541 tileQueue.sortTiles(centerDistanceCompare); 542 542 } 543 543 544 544 // process the queue 545 while (openRequests.length < MAX_OPEN_REQUESTS && queue.length > 0) {546 var tile:Tile = queue.shift() as Tile;545 while (openRequests.length < maxOpenRequests && tileQueue.length > 0) { 546 var tile:Tile = tileQueue.shift(); 547 547 // if it's still on the stage: 548 548 if (tile.parent) { … … 598 598 { 599 599 if (t1.zoom == t2.zoom && t1.zoom == currentZoom && t2.zoom == currentZoom) { 600 var d1:int = Math.pow(t1.row -centerRow,2) + Math.pow(t1.column-centerColumn,2);601 var d2:int = Math.pow(t2.row -centerRow,2) + Math.pow(t2.column-centerColumn,2);600 var d1:int = Math.pow(t1.row+0.5-centerRow,2) + Math.pow(t1.column+0.5-centerColumn,2); 601 var d2:int = Math.pow(t2.row+0.5-centerRow,2) + Math.pow(t2.column+0.5-centerColumn,2); 602 602 return d1 < d2 ? -1 : d1 > d2 ? 1 : 0; 603 603 } … … 982 982 openRequests = []; 983 983 recentlySeen = []; 984 queue = [];984 tileQueue.clear(); 985 985 986 986 dirty = true; … … 1154 1154 } 1155 1155 1156 import com.modestmaps.core.Tile; 1157 1158 class TileQueue 1159 { 1160 // Tiles we want to load: 1161 protected var queue:Array; 1162 1163 public function TileQueue() 1164 { 1165 queue = []; 1166 } 1167 1168 public function get length():Number 1169 { 1170 return queue.length; 1171 } 1172 1173 public function push(tile:Tile):void 1174 { 1175 queue.push(tile); 1176 } 1177 1178 public function shift():Tile 1179 { 1180 return queue.shift() as Tile; 1181 } 1182 1183 public function sortTiles(callback:Function):void 1184 { 1185 queue = queue.sort(callback); 1186 } 1187 1188 public function retainAll(tiles:Array):void 1189 { 1190 var tilesToKeep:Array = tiles; 1191 queue = queue.filter(function(tile:Tile, i:int, a:Array):Boolean { 1192 return tilesToKeep.indexOf(tile) >= 0; 1193 }); 1194 tilesToKeep = null; 1195 } 1196 1197 public function clear():void 1198 { 1199 queue = []; 1200 } 1201 1202 } 1203
