mapbox/geo-viewport

Incorrect zoom for some bounds

Opened this issue · 3 comments

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.

I am having the same issue. The amount its off by varies between cases so I can't even take a specific fraction of the zoom.

Does it make a difference when you specify the pixel size?

Leaflet and GL JS zooms are off by one because of the tileSize so wonder if that could be the reason here?

Yes, changing the tile size to 512 fixed the issue! Thank you!

I should have read the bottom part of the readme more closely. The blog link at the bottom is broken, I believe I found the correct post. Will open an MR with the new link.