mapbox / mapbox/mapbox-gl-js

map.fitBounds with padding affects the map.getBounds

Open
#13,409 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

map.fitBounds(bounds, { padding: 150 }) in v3.10 somehow sets the global bounds.
If you call map.getBounds(), it returns the bounds including the 150 px padding, which is incorrect.

In v2, map.getBounds() returns the correct bounds covering 100% of the height and width without any padding.

```
map.fitBounds(bounds, { padding: 150 });
const s = map.getBounds();
console.log('s', s);
```

v2 Results: [7.1204, 52.6618, 13.8875, 59.2029]
v3 Results: [8.4594, 53.4663, 12.5486, 58.5104]

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 reproducing the map.fitBounds(bounds, { padding: 150 }) and map.getBounds() sequence from the issue, then compare the v2 and v3 results shown. Trace the fitBounds and getBounds behavior to determine whether padding is being included in the reported geographic bounds. Done means getBounds() reports the fitted bounds without the pixel padding while fitBounds still honors that padding.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.