mapbox / mapbox/geo-viewport

Incorrect zoom for some bounds

Open
#30 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
197
Forks
39
PR merge metrics
No merged PRs in 30d

Description

For some bounds it calculates incorrect zoom, for example here `[-112.16601, 37.622623, -112.082016, 37.672085]` it calculates zoom 13 and it doesn't include most of markers, correct zoom will be 12.

`geoViewport.viewport([-112.16601, 37.622623, -112.082016, 37.672085], [672, 376])`

Here is example URL for static map with zoom 13:
https://api.mapbox.com/styles/v1/tripexpertweb/ckcdpjifn06ru1impw321xsqi/static/pin-s+000(-112.15432,37.672085),pin-s+000(-112.082016,37.624809),pin-s+000(-112.16601,37.622623),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15611,37.64101),pin-s+000(-112.15611,37.64101)/-112.12401330471039,37.64735841514176,13/672x376@2x?access_token=pk.eyJ1IjoidHJpcGV4cGVydHdlYiIsImEiOiJja2Fud3l2MDcwbXZ0MndyeGF3eGI3ZWhzIn0.zLqNa1RECyZZadF8zfQM5w

And correct one with zoom 12:
https://api.mapbox.com/styles/v1/tripexpertweb/ckcdpjifn06ru1impw321xsqi/static/pin-s+000(-112.15432,37.672085),pin-s+000(-112.082016,37.624809),pin-s+000(-112.16601,37.622623),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15432,37.672085),pin-s+000(-112.15611,37.64101),pin-s+000(-112.15611,37.64101)/-112.12401330471039,37.64735841514176,12/672x376@2x?access_token=pk.eyJ1IjoidHJpcGV4cGVydHdlYiIsImEiOiJja2Fud3l2MDcwbXZ0MndyeGF3eGI3ZWhzIn0.zLqNa1RECyZZadF8zfQM5w

If I convert back to bounds from center and zoom, it doesn't match initial bounds:
`geoViewport.bounds([-112.12401330471039, 37.64735841514176], 13, [672, 376])`

`[-112.1817398071289, 37.621845878167704, -112.0663833618164, 37.67295135774715]`

In this case `[2.269904, 48.849976, 2.391055, 48.874565]` it calculates zoom 12 which is correct and includes all markers.

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 reported cases with geoViewport.viewport and geoViewport.bounds, using the supplied bounds and viewport size. Trace how the library converts bounds to center and zoom, then verify that the Utah case returns zoom 12 and includes the markers while the Paris case remains correct. Done means the regression is covered by a test and both conversions agree with the expected bounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
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.