diff --git a/CHANGELOG.md b/CHANGELOG.md index fdf54045594..9074980d188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes + - Fix line-placed map-pitch-aligned texts being too large when viewed from some latitudes on a globe ([#4786](https://github.com/maplibre/maplibre-gl-js/issues/4786)) +- Fix crashes when camera is inside terrain. Add padding between camera and surface to prevent cases like this. ([#1542](https://github.com/maplibre/maplibre-gl-js/issues/1542)) - _...Add new stuff here..._ ## 5.0.0-pre.4 diff --git a/src/ui/camera.test.ts b/src/ui/camera.test.ts index 3ae21ad9800..b64f361ef57 100644 --- a/src/ui/camera.test.ts +++ b/src/ui/camera.test.ts @@ -2028,6 +2028,9 @@ describe('#flyTo', () => { }; camera.transform = { elevation: 0, + recalculateZoom: () => true, + clone: () => camera.transform, + apply: () => {}, recalculateZoomAndCenter: () => true, setMinElevationForCurrentTile: (_a) => true, setElevation: (e) => { camera.transform.elevation = e; } diff --git a/src/ui/camera.ts b/src/ui/camera.ts index 844bfac81c8..3a0d12078b2 100644 --- a/src/ui/camera.ts +++ b/src/ui/camera.ts @@ -1205,7 +1205,9 @@ export abstract class Camera extends Evented { _finalizeElevation() { this._elevationFreeze = false; if (this.getCenterClampedToGround()) { - this.transform.recalculateZoomAndCenter(this.terrain); + const tr = this._getTransformForUpdate(); + tr.recalculateZoomAndCenter(this.terrain); + this._applyUpdatedTransform(tr); } } @@ -1238,13 +1240,14 @@ export abstract class Camera extends Evented { * * @param tr - The transform to check. */ - _elevateCameraIfInsideTerrain(tr: ITransform) : { pitch?: number; zoom?: number } { + _elevateCameraIfInsideTerrain(tr: ITransform): { pitch?: number; zoom?: number } { if (!this.terrain && tr.elevation >= 0 && tr.pitch <= 90) { return {}; } + const surfacePadding = Math.min(500, 20 * (25 - tr.zoom)); const cameraLngLat = tr.getCameraLngLat(); const cameraAltitude = tr.getCameraAltitude(); - const minAltitude = this.terrain ? this.terrain.getElevationForLngLatZoom(cameraLngLat, tr.zoom) : 0; + const minAltitude = this.terrain ? this.terrain.getElevationForLngLatZoom(cameraLngLat, tr.zoom) + surfacePadding : 0; if (cameraAltitude < minAltitude) { const newCamera = this.calculateCameraOptionsFromTo( cameraLngLat, minAltitude, tr.center, tr.elevation); diff --git a/test/integration/render/tests/high-pitch/terrain-pitch95/expected.png b/test/integration/render/tests/high-pitch/terrain-pitch95/expected.png index 77ce8a5bf61..4043da41243 100644 Binary files a/test/integration/render/tests/high-pitch/terrain-pitch95/expected.png and b/test/integration/render/tests/high-pitch/terrain-pitch95/expected.png differ diff --git a/test/integration/render/tests/terrain/fog-no-sky-blend-roll/expected.png b/test/integration/render/tests/terrain/fog-no-sky-blend-roll/expected.png index 4fc9a0539ec..c777fdfa474 100644 Binary files a/test/integration/render/tests/terrain/fog-no-sky-blend-roll/expected.png and b/test/integration/render/tests/terrain/fog-no-sky-blend-roll/expected.png differ diff --git a/test/integration/render/tests/terrain/fog-no-sky-blend/expected.png b/test/integration/render/tests/terrain/fog-no-sky-blend/expected.png index 0046b826478..f62de64e672 100644 Binary files a/test/integration/render/tests/terrain/fog-no-sky-blend/expected.png and b/test/integration/render/tests/terrain/fog-no-sky-blend/expected.png differ diff --git a/test/integration/render/tests/terrain/fog-sky-blend-roll/expected.png b/test/integration/render/tests/terrain/fog-sky-blend-roll/expected.png index 6fa175db323..e2357bd0bd3 100644 Binary files a/test/integration/render/tests/terrain/fog-sky-blend-roll/expected.png and b/test/integration/render/tests/terrain/fog-sky-blend-roll/expected.png differ diff --git a/test/integration/render/tests/terrain/fog-sky-blend/expected.png b/test/integration/render/tests/terrain/fog-sky-blend/expected.png index a9b443b46dd..eb712372acb 100644 Binary files a/test/integration/render/tests/terrain/fog-sky-blend/expected.png and b/test/integration/render/tests/terrain/fog-sky-blend/expected.png differ diff --git a/test/integration/render/tests/terrain/fog/expected.png b/test/integration/render/tests/terrain/fog/expected.png index 045f70a4b73..6564c0858ac 100644 Binary files a/test/integration/render/tests/terrain/fog/expected.png and b/test/integration/render/tests/terrain/fog/expected.png differ