Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapbox Max/Min Zoom and bounds #5296

Closed
nicolaskruchten opened this issue Nov 20, 2020 · 3 comments · Fixed by #6339
Closed

Mapbox Max/Min Zoom and bounds #5296

nicolaskruchten opened this issue Nov 20, 2020 · 3 comments · Fixed by #6339
Labels
feature something new

Comments

@nicolaskruchten
Copy link
Contributor

For many applications it would be good to be able to set bounds on where the user can pan and zoom mapbox maps: https://docs.mapbox.com/mapbox-gl-js/example/restrict-bounds/ and https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setmaxzoom

@nicolaskruchten
Copy link
Contributor Author

See also #3434 and the related cartesian #1876

@beautah
Copy link

beautah commented Dec 2, 2020

I've come up with this as a python workaround, could be easily adaptable to js.

lats and longs are lists of all the coordinates.

`

zoom_lat = abs(abs(max(lats)) - abs(min(lats)))  

zoom_long = abs(abs(max(longs)) - abs(min(longs)))

zoom_factor = max([zoom_lat,zoom_long])

if zoom_factor < 0.002:

    zoom_factor = 0.002

auto_zoom = -1.35 * math.log(float(zoom_factor)) + 7

`

I should mention this has only been tested for regional (USA) coordinates, I could see it needing modification when crossing hemispheres/equator

@archmoj archmoj added the feature something new label Oct 7, 2022
@jacksongoode
Copy link

@archmoj I'm not sure if the bounds provide the same effect min/max zoom. Mapbox mention that there are some performance benefits by setting min/max zoom levels https://docs.mapbox.com/help/troubleshooting/mapbox-gl-js-performance/#filter-by-zoom-levels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants