Skip to content

Re-introduce #10444: Don't load unnecessary tiles on terrain #10467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2021

Conversation

astojilj
Copy link
Contributor

@astojilj astojilj commented Mar 15, 2021

The commit includes original #10444 and #10446 with fix for issue reported in #10462.

The issue in #10462 is about assuming center elevation for parent nodes in tile pyramid: the approach needs to be applied only to final tile cover tiles.
This is because parent tiles don't have corresponding DEM tiles cover and could get clipped out "too early" from cover.

Fixes: #10463

The case #10462 is good for illustrating the issue with original PR and improvement compared to main. Following patch is used to log tiles loaded:

--- a/src/source/source_cache.js
+++ b/src/source/source_cache.js
@@ -738,6 +738,7 @@ class SourceCache extends Evented {
         const cached = Boolean(tile);
         if (!cached) {
             tile = new Tile(tileID, this._source.tileSize * tileID.overscaleFactor(), this.transform.tileZoom);
+            console.log(`${this.id} : ${tileID.toString()}`);
             this._loadTile(tile, this._tileLoaded.bind(this, tile, tileID.key, tile.state));
         }

Screen Shot 2021-03-15 at 11 44 11

This view uses 37 vector tiles and only those are loaded while opening screen.
Code in main branch loads 71 vector tiles, uses 37 of those once view is loaded.

TODO:

Considered refactoring getMinElevationBelowMSL() to MinMax and cache it for e.g. getBounds3D could also reuse it. However, for this case, only getMinElevationBelowMSL() is needed and performance impact is not such that it would require caching. getBounds3D is called only on getBounds() or query API calls. Caching would be orthogonal to the work here so leaving the PR as it is.

Sorry, something went wrong.

The commit includes original #10444 and #10446 with fix for issue reported in #10462.

The issue in #10462 is about asuming center elevation for parent nodes in tile pyramid: the approach needs to be applied only to final tile cover tiles.
This is because parent tiles don't have correspondiong DEM tiles cover and could get clipped out "too early" from cover.

Fixes: #10463
@astojilj astojilj self-assigned this Mar 15, 2021
@astojilj astojilj requested a review from karimnaaji March 15, 2021 18:25
@astojilj
Copy link
Contributor Author

Considered refactoring getMinElevationBelowMSL() to MinMax and cache it for e.g. getBounds3D could also reuse it. However, for this case, only getMinElevationBelowMSL() is needed and performance impact is not such that it would require caching. getBounds3D is called only on getBounds() or query API calls. Caching would be orthogonal to the work here so leaving the PR as it is.

PTAL

Copy link
Contributor

@karimnaaji karimnaaji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// When calculating tile cover for terrain, create deep AABB for nodes, to ensure they intersect frustum: for sources,
// other than DEM, use minimum of visible DEM tiles and center altitude as upper bound (pitch is always less than 90°).
const maxRange = options.isTerrainDEM && this._elevation ? this._elevation.exaggeration() * 10000 : this._centerAltitude;
const minRange = options.isTerrainDEM ? -maxRange : this._elevation ? this._elevation.getMinElevationBelowMSL() : 0;
Copy link
Contributor

@karimnaaji karimnaaji Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to note is when terrain._visibleDemTiles == 0, we may hit a corner case: when there are tiles fully within negative elevation we might miss tiles, because they don't intersect with the frustum (so they are not accounted for in getMinElevationBelowMSL). One approach would be to use with an overly larger frustum for tile cover, to ensure they are marked as visible at least once. It's not directly related to this PR (same happens in main).

EDIT: Captured in #10493

@karimnaaji karimnaaji merged commit fa5558c into main Mar 19, 2021
@karimnaaji karimnaaji deleted the astojilj-tilesOutside branch March 19, 2021 20:06
@karimnaaji karimnaaji added this to the v2.3 milestone Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reintroduce "Terrain: Don't load unnecessary tiles"
2 participants