mapbox / mapbox/mapbox-gl-js

bug: fitBounds behavior can be inconsistent when terrain elevation is enabled

Open
#13,656 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

### mapbox-gl-js version

v3.21.0

### Browser and version

tested in Chromium Version 145.0.7632.159 (Official Build) (64-bit), and Firefox 140.0 (64-bit)

### Expected behavior

calling `fitBounds` with the same bounds, on the same map, with the same settings, should result in the same camera zoom and center.

### Actual behavior

calling `fitBounds` with the same bounds, on the same map, with the same settings, results in different camera zoom and center when terrain is set on the map.

### Link to the demonstration

https://jsbin.com/saxasovuzo/edit?html,output

### Steps to trigger the unexpected behavior

The demonstration has been programmed to call `fitBounds` twice in a row in order to trigger the unexpected behavior.

### Relevant log output

```shell
=== call 1 ===
[call 1] current: center=(0.00000000, 0.00000000) z=1.000000
[call 1] target: center=(33.38546777, -2.57608454) z=19.039717
[call 1] terrain: nw=null se=null ne=null sw=null

=== call 2 (from moveend of call 1) ===
[call 2] current: center=(33.38514890, -2.57608454) z=19.039718
[call 2] target: center=(33.38546777, -2.57608454) z=15.968305
[call 2] terrain: nw=1149.3545487659221 se=1153.7093150069609 ne=1149.1340876072286 sw=1154.144002061813
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked JSBin reproduction in Chromium or Firefox and compare the two consecutive fitBounds calls with terrain enabled. Trace the fitBounds camera calculation and terrain elevation inputs; done means repeated calls with identical bounds and settings produce the same camera center and zoom.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.