Skip to content
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

Fix/remaining issues camera inside terrain #4551

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/geo/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,15 @@ export class Transform {
const requiredWorldSize = requiredPixelPerMeter / mercatorZfromAltitude(1, center.lat);
// Since worldSize = this.tileSize * scale:
const requiredScale = requiredWorldSize / this.tileSize;
const zoom = this.scaleZoom(requiredScale);

// update matrices
this._elevation = elevation;
this._center = center;
this.zoom = zoom;
try {
const zoom = this.scaleZoom(requiredScale);
// update matrices
this._elevation = elevation;
this._center = center;
this.zoom = zoom;
} catch (_e) {
console.error(`Could not recalculate zoom. requiredScale: ${requiredScale}`);
chrneumann marked this conversation as resolved.
Show resolved Hide resolved
}
}

setLocationAtPoint(lnglat: LngLat, point: Point) {
Expand Down
8 changes: 6 additions & 2 deletions src/ui/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,9 @@

_finalizeElevation() {
this._elevationFreeze = false;
this.transform.recalculateZoom(this.terrain);
const tr = this._getTransformForUpdate();
tr.recalculateZoom(this.terrain);
this._applyUpdatedTransform(tr);
}

/**
Expand All @@ -1101,7 +1103,7 @@
if (!this.transformCameraUpdate && !this.terrain) return this.transform;

if (!this._requestedCameraState) {
this._requestedCameraState = this.transform.clone();

Check failure on line 1106 in src/ui/camera.ts

View workflow job for this annotation

GitHub Actions / Unit tests and Coverage

#flyTo › check elevation callbacks

TypeError: this.transform.clone is not a function at CameraMock._getTransformForUpdate (src/ui/camera.ts:1106:57) at CameraMock._finalizeElevation (src/ui/camera.ts:1088:25) at Object.<anonymous> (src/ui/camera.test.ts:1802:16)
}
return this._requestedCameraState;
}
Expand All @@ -1119,7 +1121,9 @@
*/
_elevateCameraIfInsideTerrain(tr: Transform) : { pitch?: number; zoom?: number } {
const camera = tr.getCameraPosition();
const minAltitude = this.terrain.getElevationForLngLatZoom(camera.lngLat, tr.zoom);
const surfacePadding = Math.min(500, 20 * (25 - tr.zoom));
const minAltitude = this.terrain.getElevationForLngLatZoom(
camera.lngLat, tr.zoom) + surfacePadding;
if (camera.altitude < minAltitude) {
const newCamera = this.calculateCameraOptionsFromTo(
camera.lngLat, minAltitude, tr.center, tr.elevation);
Expand Down
Binary file modified test/integration/render/tests/terrain/fog-sky-blend/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/integration/render/tests/terrain/fog/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading