mapbox / mapbox/mapbox-gl-js

fitBound end up in error of NaN after call

Open
#10,476 1 comment 5 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: 1.13.1

browser: Tested in Chrome and Firefox

Steps to Trigger Behavior
  1. Set a map element with a size x (example: 400px)
  2. Call fitBounds method passing CameraOptions with padding being x / 2 (example: 200px)
Expected Behavior

Map should fit to provided boundaries

Actual Behavior

At this moment when it happens to map element width to be x and the padding (right and left) to be x / 2 we end up with the Point object generated in _cameraForBoxAndBearing to be a set of NaN of x and y, this happens due to the fact we multiply 0 with Infinity and the method just throw an error.

test

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 in src/ui/camera.js at _cameraForBoxAndBearing, following the fitBounds path and the scale, zoom, and offsetAtFinalZoom calculations described in the report. Reproduce the case with a 400px map and 200px left and right padding; done means fitBounds no longer produces NaN coordinates or throws when the available width is zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.