cameraForBounds should comply with map constrains
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**mapbox-gl-js version**: 1.9.1
**browser**: all
### Steps to Trigger Behavior
1. In full screen mode, use [`cameraForBounds`](https://www.mapbox.com/mapbox-gl-js/api#map#cameraforbounds) with the following:
```js
const center = [34.801497299999994, 32.082714300000006];
const bbox = [ center, center ];
const camera = this.map.cameraForBounds(bbox, { maxZoom: 1 });
```
2. Observe the new `camera.center` is `{lng: 34.801497299999994, lat: 32.082714300000006}`
2. `jumpTo` the new center:
```js
this.map.jumpTo({ center: camera.center });
```
3. Observe `map.getCenter()` is `{lng: 34.801497299999994, lat: 22.43134251570592}`
4. the `jumpTo` call initiate `transform._constrain()` but that is not reflected with the data from [`cameraForBounds`](https://www.mapbox.com/mapbox-gl-js/api#map#cameraforbounds)
My use-case is initiating `easeTo/flyTo/jumpTo` only if the center is different so i'm comparing the results of `cameraForBounds` with the current `map.getCenter()`. With the current flow a user cannot initiate map movement with preconditions.
### Link to Demonstration
https://jsfiddle.net/shayy/rs8f9qvx/5/embedded/result
Press `space` multiple times and watch the console logs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the cameraForBounds and jumpTo entry points, then trace how transform._constrain() affects map.getCenter(). Reproduce the jsfiddle case with a zero-area bounds value and maxZoom: 1; done means cameraForBounds and the subsequent map movement report the same constrained center.
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
- 35/100