mapbox / mapbox/mapbox-gl-js

fitBounds doesn't work sometimes

Open
#12,168 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs information :pray:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**:1.13.1
### Question
hello,I use addLayer to show some polygons,when change the polygon data,I want to use fitBounds to get better view,most time,it worked well,but sometimes,some area is out of bounds,I don't know why.Am i doing something wrong, or is there a bug in fitbounds?Here is my code:
this.map = new mapboxgl.Map(
{
container:'map',
style:...some style,
zoom:6,
pitch:60,
bearing:0,
center:[113.45,34,81],
hash :false,
renderWorldCopies:false
}
)

when change the data,I use fitBounds, here is the code
let bbox = turf.bbox(mapData)
this.map.fitBounds([[bbox[0],bbox[1]],[bbox[2],bbox[3]]])

looking forward to your reply,thank you.

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 with the reported entry points: addLayer, turf.bbox(mapData), and map.fitBounds after polygon data changes. Reproduce the intermittent out-of-bounds view and inspect the fitBounds API behavior around data or rendering timing; done means identifying a reliable cause or a minimal reproduction that confirms a library bug.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.