| 353 | | // for fixing row/cols so they're positioned at currentZoom |
|---|
| 354 | | var scaleFactor:Number; |
|---|
| | 346 | // |
|---|
| | 347 | // if the tile isn't ready yet, we're going to reuse a parent tile |
|---|
| | 348 | // if there isn't a parent tile, and we're zooming out, we'll reuse child tiles |
|---|
| | 349 | // if we don't get all 4 child tiles, we'll look at more parent levels |
|---|
| | 350 | // |
|---|
| | 351 | // yes, this is quite involved, but it should be fast enough because most of the loops |
|---|
| | 352 | // don't get hit most of the time |
|---|
| | 353 | // |
|---|
| 358 | | // if it still doesn't have enough images yet, or it's fading in, try a double size parent instead |
|---|
| 359 | | if (maxParentSearch > 0 && !tileReady && currentZoom > minZoom) { |
|---|
| 360 | | pkey = parentKey(col, row, currentZoom, currentZoom-1); |
|---|
| 361 | | if (alreadySeen[pkey] is Tile) { |
|---|
| 362 | | ptile = ensureVisible(pkey); |
|---|
| 363 | | ptile.alpha = 1; |
|---|
| 364 | | foundParent = true; |
|---|
| | 365 | // for fixing row/cols so they're positioned at currentZoom |
|---|
| | 366 | var scaleFactor:Number; |
|---|
| | 367 | |
|---|
| | 368 | if (currentZoom > previousZoom) { |
|---|
| | 369 | |
|---|
| | 370 | // if it still doesn't have enough images yet, or it's fading in, try a double size parent instead |
|---|
| | 371 | if (maxParentSearch > 0 && currentZoom > minZoom) { |
|---|
| | 372 | pkey = parentKey(col, row, currentZoom, currentZoom-1); |
|---|
| | 373 | if (alreadySeen[pkey] is Tile) { |
|---|
| | 374 | ptile = ensureVisible(pkey); |
|---|
| | 375 | ptile.alpha = 1; |
|---|
| | 376 | foundParent = true; |
|---|
| | 377 | } |
|---|
| 367 | | |
|---|
| 368 | | } |
|---|
| 369 | | else { |
|---|
| 370 | | |
|---|
| 371 | | // currentZoom <= previousZoom, so we're zooming out |
|---|
| 372 | | // and therefore we might want to reuse 'smaller' tiles |
|---|
| 373 | | |
|---|
| 374 | | // if it doesn't have an image yet, see if we can make it from smaller images |
|---|
| 375 | | if (!foundParent && maxChildSearch > 0 && !tileReady && currentZoom < maxZoom) { |
|---|
| 376 | | for (var czoom:int = currentZoom+1; czoom <= Math.min(maxZoom, currentZoom+maxChildSearch); czoom++) { |
|---|
| 377 | | var ckeys:Array = childKeys(col, row, currentZoom, czoom); |
|---|
| 378 | | for each (var ckey:String in ckeys) { |
|---|
| 379 | | if (alreadySeen[ckey] is Tile) { |
|---|
| 380 | | var ctile:Tile = ensureVisible(ckey); |
|---|
| 381 | | ctile.alpha = 1.0; |
|---|
| 382 | | foundChildren++; |
|---|
| 383 | | } |
|---|
| 384 | | } // ckeys |
|---|
| 385 | | if (foundChildren == ckeys.length) { |
|---|
| | 381 | else { |
|---|
| | 382 | |
|---|
| | 383 | // currentZoom <= previousZoom, so we're zooming out |
|---|
| | 384 | // and therefore we might want to reuse 'smaller' tiles |
|---|
| | 385 | |
|---|
| | 386 | // if it doesn't have an image yet, see if we can make it from smaller images |
|---|
| | 387 | if (!foundParent && maxChildSearch > 0 && currentZoom < maxZoom) { |
|---|
| | 388 | for (var czoom:int = currentZoom+1; czoom <= Math.min(maxZoom, currentZoom+maxChildSearch); czoom++) { |
|---|
| | 389 | var ckeys:Array = childKeys(col, row, currentZoom, czoom); |
|---|
| | 390 | for each (var ckey:String in ckeys) { |
|---|
| | 391 | if (alreadySeen[ckey] is Tile) { |
|---|
| | 392 | var ctile:Tile = ensureVisible(ckey); |
|---|
| | 393 | ctile.alpha = 1.0; |
|---|
| | 394 | foundChildren++; |
|---|
| | 395 | } |
|---|
| | 396 | } // ckeys |
|---|
| | 397 | if (foundChildren == ckeys.length) { |
|---|
| | 398 | break; |
|---|
| | 399 | } |
|---|
| | 400 | } // czoom |
|---|
| | 401 | } |
|---|
| | 402 | } |
|---|
| | 403 | |
|---|
| | 404 | var startZoomSearch:int = currentZoom - 1; |
|---|
| | 405 | |
|---|
| | 406 | if (currentZoom > previousZoom) { |
|---|
| | 407 | // we already looked for parent level 1, and didn't find it, so: |
|---|
| | 408 | startZoomSearch -= 1; |
|---|
| | 409 | } |
|---|
| | 410 | |
|---|
| | 411 | var endZoomSearch:int = Math.max(minZoom, currentZoom-maxParentSearch); |
|---|
| | 412 | |
|---|
| | 413 | var stillNeedsAnImage:Boolean = !foundParent && foundChildren < 4; |
|---|
| | 414 | // if it still doesn't have an image yet, try more parent zooms |
|---|
| | 415 | if (stillNeedsAnImage && maxParentSearch > 1 && currentZoom > minZoom) { |
|---|
| | 416 | for (pzoom = startZoomSearch; pzoom >= endZoomSearch; pzoom--) { |
|---|
| | 417 | pkey = parentKey(col, row, currentZoom, pzoom); |
|---|
| | 418 | if (alreadySeen[pkey] is Tile) { |
|---|
| | 419 | ptile = ensureVisible(pkey); |
|---|
| | 420 | ptile.alpha = 1; |
|---|
| | 421 | stillNeedsAnImage = false; |
|---|
| 387 | | } |
|---|
| 388 | | } // czoom |
|---|
| 389 | | } |
|---|
| 390 | | } |
|---|
| 391 | | |
|---|
| 392 | | var startZoomSearch:int = currentZoom - 1; |
|---|
| 393 | | |
|---|
| 394 | | if (currentZoom > previousZoom) { |
|---|
| 395 | | // we already looked for parent level 1, and didn't find it, so: |
|---|
| 396 | | startZoomSearch -= 1; |
|---|
| 397 | | } |
|---|
| 398 | | |
|---|
| 399 | | var endZoomSearch:int = Math.max(minZoom, currentZoom-maxParentSearch); |
|---|
| 400 | | |
|---|
| 401 | | var stillNeedsAnImage:Boolean = !foundParent && foundChildren < 4; |
|---|
| 402 | | // if it still doesn't have an image yet, try more parent zooms |
|---|
| 403 | | if (stillNeedsAnImage && maxParentSearch > 1 && !tileReady && currentZoom > minZoom) { |
|---|
| 404 | | for (pzoom = startZoomSearch; pzoom >= endZoomSearch; pzoom--) { |
|---|
| 405 | | pkey = parentKey(col, row, currentZoom, pzoom); |
|---|
| 406 | | if (alreadySeen[pkey] is Tile) { |
|---|
| 407 | | ptile = ensureVisible(pkey); |
|---|
| 408 | | ptile.alpha = 1; |
|---|
| 409 | | stillNeedsAnImage = false; |
|---|
| 410 | | break; |
|---|
| 411 | | } |
|---|
| 412 | | } |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | if (stillNeedsAnImage) { |
|---|
| 416 | | blankCount++; |
|---|
| 417 | | //trace("sorry, no parent known for", key); |
|---|
| 418 | | } |
|---|
| | 423 | } |
|---|
| | 424 | } |
|---|
| | 425 | } |
|---|
| | 426 | |
|---|
| | 427 | if (stillNeedsAnImage) { |
|---|
| | 428 | blankCount++; |
|---|
| | 429 | //trace("sorry, no parent known for", key); |
|---|
| | 430 | } |
|---|
| | 431 | |
|---|
| | 432 | } // if !tileReady |
|---|