Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Apr 2, 2018
1 parent 25097b2 commit 7bc39da
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,18 @@ class SourceCache extends Evented {
_findLoadedChildren(tileID: OverscaledTileID, maxCoveringZoom: number, retain: {[any]: OverscaledTileID}): boolean {
let found = false;

for (const id in this._tiles) {
let tile = this._tiles[id];
for (const id in this._prevTiles) {
let tile;
for (const prevTile of this._prevTiles[id]) {
if (prevTile.hasData()) {
tile = prevTile;
break;
}
}
if (!tile) continue;

// only consider renderable tiles on higher zoom levels (up to maxCoveringZoom)
if (retain[id] || !tile.hasData() || tile.tileID.overscaledZ <= tileID.overscaledZ || tile.tileID.overscaledZ > maxCoveringZoom) continue;
if (tile.tileID.overscaledZ <= tileID.overscaledZ || tile.tileID.overscaledZ > maxCoveringZoom) continue;

// disregard tiles that are not descendants of the given tile coordinate
const z2 = Math.pow(2, tile.tileID.canonical.z - tileID.canonical.z);
Expand All @@ -334,7 +341,7 @@ class SourceCache extends Evented {
continue;

// found loaded child
retain[id] = tile.tileID;
this._addTile(tileID);
found = true;

// loop through parents; retain the topmost loaded one if found
Expand All @@ -356,18 +363,17 @@ class SourceCache extends Evented {
* Find a loaded parent of the given tile (up to minCoveringZoom);
* adds the found tile to retain object and returns the tile if found
*/
findLoadedParent(tileID: OverscaledTileID, minCoveringZoom: number, retain: {[any]: OverscaledTileID}): ?Tile {
findLoadedParent(tileID: OverscaledTileID, minCoveringZoom: number): ?Tile {
for (let z = tileID.overscaledZ - 1; z >= minCoveringZoom; z--) {
const parent = tileID.scaledTo(z);
if (!parent) return;
const id = String(parent.key);
const tile = this._getPrevTile(parent);
const id = String(parent.key);
if (tile && tile.hasData()) {
retain[id] = parent;
this._tiles[tileID.key] = tile;
return tile;
}
if (this._cache.has(id)) {
retain[id] = parent;
return this._cache.get(id);
}
}
Expand Down Expand Up @@ -608,12 +614,12 @@ class SourceCache extends Evented {
* Add a tile, given its coordinate, to the pyramid.
* @private
*/
_addTile(tileID: OverscaledTileID): Tile {
_addTile(tileID: OverscaledTileID, onlyLoaded: boolean): Tile {
let tile = this._tiles[tileID.key];
if (tile)
return tile;

tile = this._getPrevTile(tileID);
tile = this._getPrevTile(tileID, onlyLoaded);
if (tile) {
this._tiles[tileID.key] = tile;
return tile;
Expand All @@ -631,7 +637,7 @@ class SourceCache extends Evented {
}

const cached = Boolean(tile);
if (!cached) {
if (!cached && !onlyLoaded) {
tile = new Tile(tileID, this._source.tileSize * tileID.overscaleFactor());
this._loadTile(tile, this._tileLoaded.bind(this, tile, tileID.key, tile.state));
}
Expand Down

0 comments on commit 7bc39da

Please sign in to comment.