Skip to content

Commit

Permalink
Fix MapboxLayer crash when pitch=0 (#7760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Mar 16, 2023
1 parent 049704a commit 518dfee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/mapbox/src/deck-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ function centerCameraOnTerrain(map: Map, viewState: MapViewState) {

const pitchRadians = pitch! * DEGREES_TO_RADIANS;
const altitudePixels = 1.5 * height;
const scale = (altitudePixels * Math.sin(pitchRadians)) / cameraToCenterDistanceGround;
const scale =
pitchRadians < 0.001
? // Pitch angle too small to deduce the look at point, assume elevation is 0
(altitudePixels * Math.cos(pitchRadians)) / cameraZ
: (altitudePixels * Math.sin(pitchRadians)) / cameraToCenterDistanceGround;
viewState.zoom = Math.log2(scale);

const cameraZFromSurface = (altitudePixels * Math.cos(pitchRadians)) / scale;
Expand Down

0 comments on commit 518dfee

Please sign in to comment.