| 327 | | |
|---|
| 328 | | visibleTiles = []; |
|---|
| | 327 | |
|---|
| | 328 | // loop over all tiles and find parent or child tiles from cache to compensate for unloaded tiles: |
|---|
| | 329 | repopulateVisibleTiles(minCol, maxCol, minRow, maxRow); |
|---|
| | 330 | |
|---|
| | 331 | // make absolutlely sure all our newly visible tiles are cached if they're done loading |
|---|
| | 332 | // TODO: should this happen onLoadEnd when there are no URLs left? |
|---|
| | 333 | for each (var visibleTile:Tile in visibleTiles) { |
|---|
| | 334 | // if we're done loading this one, add/move it to the end of recently seen: |
|---|
| | 335 | if (!layersNeeded[visibleTile]) { |
|---|
| | 336 | var ri:int = recentlySeen.indexOf(visibleTile.name); |
|---|
| | 337 | if (ri >= 0) { |
|---|
| | 338 | recentlySeen.splice(ri, 1); |
|---|
| | 339 | } |
|---|
| | 340 | recentlySeen.push(visibleTile.name); |
|---|
| | 341 | } |
|---|
| | 342 | } |
|---|
| | 343 | |
|---|
| | 344 | // prune tiles from the well if they shouldn't be there (not currently in visibleTiles) |
|---|
| | 345 | // (loop backwards so removal doesn't change i) |
|---|
| | 346 | for (var i:int = well.numChildren-1; i >= 0; i--) { |
|---|
| | 347 | var wellTile:Tile = well.getChildAt(i) as Tile; |
|---|
| | 348 | if (visibleTiles.indexOf(wellTile) < 0) { |
|---|
| | 349 | well.removeChild(wellTile); |
|---|
| | 350 | wellTile.hide(); |
|---|
| | 351 | if (!tileCache.containsKey(wellTile.name)) { |
|---|
| | 352 | //trace("destroying tile that was in the well but never cached"); |
|---|
| | 353 | map.destroyTile(wellTile); |
|---|
| | 354 | } |
|---|
| | 355 | } |
|---|
| | 356 | } |
|---|
| | 357 | |
|---|
| | 358 | // position tiles such that currentZoom is approximately scale 1 |
|---|
| | 359 | // and x and y make sense in pixels relative to realMinCol and realMinRow, topleft |
|---|
| | 360 | positionTiles(realMinCol, realMinRow); |
|---|
| | 361 | |
|---|
| | 362 | // all the visible tiles will be at the end of recentlySeen |
|---|
| | 363 | // let's make sure we keep them around: |
|---|
| | 364 | var maxRecentlySeen:int = Math.max(visibleTiles.length, maxTilesToKeep); |
|---|
| | 365 | |
|---|
| | 366 | // prune cache of already seen tiles if it's getting too big: |
|---|
| | 367 | if (recentlySeen.length > maxRecentlySeen) { |
|---|
| | 368 | |
|---|
| | 369 | // throw away keys at the beginning of recentlySeen |
|---|
| | 370 | recentlySeen = recentlySeen.slice(recentlySeen.length - maxRecentlySeen, recentlySeen.length); |
|---|
| | 371 | |
|---|
| | 372 | // loop over our internal tile cache |
|---|
| | 373 | // and throw out tiles not in recentlySeen |
|---|
| | 374 | tileCache.retainKeys(recentlySeen); |
|---|
| | 375 | } |
|---|
| | 376 | |
|---|
| | 377 | // update center position: |
|---|
| | 378 | centerRow = (realMaxRow+realMinRow)/2; |
|---|
| | 379 | centerColumn = (realMaxCol+realMinCol)/2.0; |
|---|
| | 380 | |
|---|
| | 381 | dirty = false; |
|---|
| | 382 | } |
|---|
| | 383 | |
|---|
| | 384 | /** |
|---|
| | 385 | * loops over given cols and rows and adds tiles to visibleTiles array and the well |
|---|
| | 386 | * using child or parent tiles to compensate for tiles not yet available in the tileCache |
|---|
| | 387 | */ |
|---|
| | 388 | private function repopulateVisibleTiles(minCol:int, maxCol:int, minRow:int, maxRow:int):void |
|---|
| | 389 | { |
|---|
| | 390 | visibleTiles = []; |
|---|
| | 391 | |
|---|
| 455 | | } |
|---|
| 456 | | } |
|---|
| 457 | | |
|---|
| 458 | | /* trace((maxCol - minCol + 1) * (maxRow - minRow + 1), "tiles visible at currentZoom"); |
|---|
| 459 | | trace(visibleTiles.length, " tiles visible"); */ |
|---|
| 460 | | |
|---|
| 461 | | // make absolutlely sure all our newly visible tiles are cached if they're done loading |
|---|
| 462 | | // TODO: this should probably happen onLoadEnd when there are no URLs left? |
|---|
| 463 | | for each (tile in visibleTiles) { |
|---|
| 464 | | // if we're done loading this one, add/move it to the end of recently seen: |
|---|
| 465 | | if (!layersNeeded[tile]) { |
|---|
| 466 | | var ri:int = recentlySeen.indexOf(tile.name); |
|---|
| 467 | | if (ri >= 0) { |
|---|
| 468 | | recentlySeen.splice(ri, 1); |
|---|
| 469 | | } |
|---|
| 470 | | recentlySeen.push(tile.name); |
|---|
| 471 | | } |
|---|
| 472 | | } |
|---|
| 473 | | |
|---|
| 474 | | // prune tiles from the well if they shouldn't be there (not currently in visibleTiles) |
|---|
| 475 | | // (loop backwards so removal doesn't change i) |
|---|
| 476 | | for (var i:int = well.numChildren-1; i >= 0; i--) { |
|---|
| 477 | | tile = well.getChildAt(i) as Tile; |
|---|
| 478 | | if (visibleTiles.indexOf(tile) < 0) { |
|---|
| 479 | | well.removeChild(tile); |
|---|
| 480 | | tile.hide(); |
|---|
| 481 | | if (!tileCache.containsKey(tile.name)) { |
|---|
| 482 | | //trace("destroying tile that was in the well but never cached"); |
|---|
| 483 | | map.destroyTile(tile); |
|---|
| 484 | | } |
|---|
| 485 | | } |
|---|
| 486 | | } |
|---|
| 487 | | |
|---|
| 488 | | //trace(well.numChildren, " tiles in the well"); |
|---|
| 489 | | |
|---|
| | 507 | } // for row |
|---|
| | 508 | } // for col |
|---|
| | 509 | |
|---|
| | 510 | } // repopulateVisibleTiles |
|---|
| | 511 | |
|---|
| | 512 | private function positionTiles(realMinCol:Number, realMinRow:Number):void |
|---|
| | 513 | { |
|---|
| 513 | | } |
|---|
| 514 | | |
|---|
| 515 | | // all the visible tiles will be at the end of recentlySeen |
|---|
| 516 | | // let's make sure we keep them around: |
|---|
| 517 | | var maxRecentlySeen:int = Math.max(visibleTiles.length, maxTilesToKeep); |
|---|
| 518 | | |
|---|
| 519 | | /* trace("maxRecentlySeen is", maxRecentlySeen); |
|---|
| 520 | | trace("recentlySeen.length is", recentlySeen.length); */ |
|---|
| 521 | | |
|---|
| 522 | | // prune cache of already seen tiles if it's getting too big: |
|---|
| 523 | | if (recentlySeen.length > maxRecentlySeen) { |
|---|
| 524 | | //trace("... and that's too big"); |
|---|
| 525 | | |
|---|
| 526 | | // throw away keys at the beginning of recentlySeen |
|---|
| 527 | | recentlySeen = recentlySeen.slice(recentlySeen.length - maxRecentlySeen, recentlySeen.length); |
|---|
| 528 | | |
|---|
| 529 | | /* trace("recentlySeen.length is now", recentlySeen.length); |
|---|
| 530 | | |
|---|
| 531 | | trace("trimming cache from", tileCache.size); */ |
|---|
| 532 | | |
|---|
| 533 | | // loop over our internal tile cache |
|---|
| 534 | | // and throw out tiles not in recentlySeen |
|---|
| 535 | | tileCache.retainKeys(recentlySeen); |
|---|
| 536 | | |
|---|
| 537 | | // trace("to", tileCache.size); |
|---|
| 538 | | } |
|---|
| 539 | | |
|---|
| 540 | | // update center position: |
|---|
| 541 | | centerRow = (realMaxRow+realMinRow)/2; |
|---|
| 542 | | centerColumn = (realMaxCol+realMinCol)/2.0; |
|---|
| 543 | | |
|---|
| 544 | | dirty = false; |
|---|
| | 537 | } |
|---|