Skip to content

Commit

Permalink
Revert tile loading changes from #11988 (#12075)
Browse files Browse the repository at this point in the history
* Use max instead of interpolating arc midopint

* Adding render test

* Correcting cornerMin + cornerMax, undoing change to arc extremum interpolation

* Removing interpolation introduced in #11988

* Fix CI

* Updating baseline reflecting less tiles loaded
  • Loading branch information
SnailBones authored Aug 2, 2022
1 parent 98ce3b6 commit dcc5a2b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 59 deletions.
72 changes: 14 additions & 58 deletions src/geo/projection/globe_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export function aabbForTileOnGlobe(tr: Transform, numTiles: number, tileId: Cano
updateCorners(cornerMin, cornerMax, corners, m, scale);

if (bounds.contains(tr.center)) {
// Extend the aabb by encapsulating the center point
// Extend the aabb by including the center point. There are some corner cases where center point is inside the
// tile but due to curvature aabb computed from corner points does not cover the curved area.
cornerMax[2] = 0.0;
const point = tr.point;
const center = [point.x * scale, point.y * scale, 0];
Expand Down Expand Up @@ -298,8 +299,8 @@ export function aabbForTileOnGlobe(tr: Transform, numTiles: number, tileId: Cano
}

// Here we determine the arc which is closest to the map center point.
// Horizontal arcs origin = arcCenter.
// Vertical arcs origin = arcCenter + yAxis * shift.
// Horizontal arcs origin = globe center
// Vertical arcs origin = globe center + yAxis * shift.
// Where `shift` is determined by latitude.
let closestArcIdx = 0;
if (Math.abs(dx) > Math.abs(dy)) {
Expand All @@ -311,35 +312,22 @@ export function aabbForTileOnGlobe(tr: Transform, numTiles: number, tileId: Cano
vec3.scaleAndAdd(arcCenter, arcCenter, yAxis, shift);
}

const arcA = corners[closestArcIdx];
const arcB = corners[(closestArcIdx + 1) % 4];
const arcStart = corners[closestArcIdx];
const arcEnd = corners[(closestArcIdx + 1) % 4];

const closestArc = new Arc(arcA, arcB, arcCenter);
let arcBounds = [
(localExtremum(closestArc, 0) || arcA[0]),
(localExtremum(closestArc, 1) || arcA[1]),
(localExtremum(closestArc, 2) || arcA[2])];

// Interpolate the four corners towards their world space location in mercator projection during transition.
const phase = globeToMercatorTransition(tr.zoom);
if (phase > 0.0 && phase < 1.0) {
const mercatorCorners = mercatorTileCornersInCameraSpace(tileId, numTiles, tr._pixelsPerMercatorPixel, camX, camY);
for (let i = 0; i < corners.length; i++) {
corners[i] = interpolateArray(corners[i], mercatorCorners[i], phase);
}

// Interpolate arc extremum toward the edge midpoint in Mercator
const mercatorExtremum = interpolateArray(mercatorCorners[closestArcIdx], mercatorCorners[(closestArcIdx + 1) % 4], .5);
arcBounds = interpolateArray(arcBounds, mercatorExtremum, phase);
}
const closestArc = new Arc(arcStart, arcEnd, arcCenter);
const arcExtremum = [
(localExtremum(closestArc, 0) || arcStart[0]),
(localExtremum(closestArc, 1) || arcStart[1]),
(localExtremum(closestArc, 2) || arcStart[2])];

// Reduce height of the aabb to match height of the closest arc. This reduces false positives
// of tiles farther away from the center as they would otherwise intersect with far end
// of the view frustum
cornerMin[2] = Math.min(arcA[2], arcB[2]);
cornerMin[2] = Math.min(arcStart[2], arcEnd[2]);

vec3.min(cornerMin, cornerMin, arcBounds);
vec3.max(cornerMax, cornerMax, arcBounds);
vec3.min(cornerMin, cornerMin, arcExtremum);
vec3.max(cornerMax, cornerMax, arcExtremum);

return new Aabb(cornerMin, cornerMax);
}
Expand All @@ -351,38 +339,6 @@ export function tileCornersToBounds({x, y, z}: CanonicalTileID): LngLatBounds {
return new LngLatBounds(sw, ne);
}

function mercatorTileCornersInCameraSpace({x, y, z}: CanonicalTileID, numTiles: number, mercatorScale: number, camX, camY): $ReadOnlyArray<Array<number>> {

const tileScale = 1.0 / (1 << z);
let w = x * tileScale;
let e = w + tileScale;
let n = y * tileScale;
let s = n + tileScale;

// Ensure that the tile viewed is the nearest when across the antimeridian
let wrap = 0;
const tileCenterXFromCamera = (w + e) / 2 - camX;
if (tileCenterXFromCamera > .5) {
wrap = -1;
} else if (tileCenterXFromCamera < -.5) {
wrap = 1;
}

camX *= mercatorScale;
camY *= mercatorScale;

// Transform position in Mercator to points on the plane tangent to the globe at cameraCenter.
w = ((w + wrap) * numTiles - camX) * mercatorScale + camX;
e = ((e + wrap) * numTiles - camX) * mercatorScale + camX;
n = (n * numTiles - camY) * mercatorScale + camY;
s = (s * numTiles - camY) * mercatorScale + camY;

return [[w, s, 0],
[e, s, 0],
[w, n, 0],
[e, n, 0]];
}

function boundsToECEF(bounds: LngLatBounds) {
const ny = degToRad(bounds.getNorth());
const sy = degToRad(bounds.getSouth());
Expand Down
3 changes: 2 additions & 1 deletion test/ignores.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"render-tests/fill-extrusion-pattern/opacity-terrain": "skip - deferred for globe-view",
"render-tests/globe/globe-transition/horizon-during-transition": "skip - pending globe-view implementation",
"render-tests/resize/mercator": "skip - implemented for mapbox-gl-native only",
"render-tests/resize/globe": "skip - implemented for mapbox-gl-native only"
"render-tests/resize/globe": "skip - implemented for mapbox-gl-native only",
"render-tests/globe/globe-transition/tiles-high-pitch": "skip - fix introduced other issues"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": 8,
"metadata": {
"test": {
"width": 512,
"height": 512,
"allowed": 0.001
}
},
"center": [22, 78.9],
"zoom": 5.65,
"sources": {
"mapbox": {
"type": "vector",
"tiles": [
"local://tiles/{z}-{x}-{y}.mvt"
]
}
},
"projection": {
"name": "globe"
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {"background-color": "hsl(206, 100%, 74%)"}
},
{
"id": "country-boundaries",
"type": "fill",
"source": "mapbox",
"source-layer": "country_boundaries",
"layout": {},
"paint": {"fill-color": "hsl(43, 90%, 56%)"}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/integration/tiles/3-4-0.mvt
Binary file not shown.

0 comments on commit dcc5a2b

Please sign in to comment.