mapbox / mapbox/mapbox-gl-js

Map isn't respecting passed in bounds

Open
#13,620 0 comments 0 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

### mapbox-gl-js version

Latest

### Expected behavior

We are building an application using mapbox where the map bounds can be shared across multiple users. We've found that when passing in a set of bounds to initalize a map, that there are differences across the shared bounding boxes, even though the map is being opened in the same browser, with the same size of map.

### Steps to trigger the unexpected behavior

Using the below code take the console output and replace the bounds with that output, whilst maintaining the same size of map, at that point I'm expecting `map.getBounds()` to return the same as the passed in bounds -

```
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/standard',
bounds: new mapboxgl.LngLatBounds(
{lat: 51.982898278386415, lng: 0.5317321224441969},
{lat: 51.90657505892173, lng: 0.21361845136780744}
),
fitBoundsOptions: { padding: 0 },
padding: 0
});

// This will be different from the passed in bounds...
console.log(map.getBounds());
```

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 Map constructor's bounds and fitBoundsOptions handling, then compare it with the getBounds behavior using the provided reproduction and fixed map dimensions. Done means getBounds() returns the same bounds passed during initialization when padding is zero.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.