From 1b14eeaee93f328c7a5085aafc8d1ce71fddd944 Mon Sep 17 00:00:00 2001 From: wcwcwcwc Date: Mon, 23 May 2022 09:54:05 +0800 Subject: [PATCH] fix the problem of camera height calculation when using setFreeCameraOptions,see https://github.com/mapbox/mapbox-gl-js/issues/11914 --- src/geo/transform.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/geo/transform.js b/src/geo/transform.js index b3b46d2b25e..8ad6b4f3638 100644 --- a/src/geo/transform.js +++ b/src/geo/transform.js @@ -585,8 +585,9 @@ class Transform { const minWorldSize = this.zoomScale(this.minZoom) * this.tileSize; const maxWorldSize = this.zoomScale(this.maxZoom) * this.tileSize; const distToCenter = this.cameraToCenterDistance; - - position[2] = clamp(position[2], distToCenter / maxWorldSize, distToCenter / minWorldSize); + // Camera height calculations take forward into account + const dir = this._camera.forward(); + position[2] = clamp(position[2], (-dir[2] * distToCenter) / maxWorldSize, (-dir[2] * distToCenter) / minWorldSize); this._camera.position = position; }