mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.24k stars 2.23k forks source link

Add API for allowing the map to zoom out to z0 #7326

Open ryanhamley opened 6 years ago

ryanhamley commented 6 years ago

Motivation

https://github.com/mapbox/mapbox-gl-js/pull/6918 clamps latitude values to +-85.56° to prevent fitBounds values such as -90 from throwing an error. This inadvertently made zooming all the way out to z0 impossible. This should have been considered a breaking change. At least one user has already asked about this. Clamping latitudes to valid Web Mercator values is the correct behavior, but we should provide a simple API to allow a user to revert to the pre-v0.48.0 behavior.

Design Alternatives

  1. Do nothing. It can be argued that the previous behavior was a bug and we shouldn't add a way to reintroduce "buggy" behavior. map.transform.latRange = null achieves the desired effect without introducing a new API

  2. map.setMaxBounds(null); used to achieve this functionality so we could ensure that this function call sets the latRange to null

  3. We could add a map option such as clampLatRange with the default true

  4. We could have an explicit transform method such as map.transform.unclampLatRange().

Design

The more I think about it, I might lean towards option 1. There's a way to achieve this without introducing a new API that allows arguably undesirable behavior. If we do want to implement this, I think 3 might be the simplest way for a user to allow this behavior.

ryanhamley commented 6 years ago

User comment adding more background:

Yes, we were able to get the desired behavior using that workaround. Note that we also needed to set map.transform.maxValidLatitude = Infinity to be able to pan the map past the top and bottom edges of the container. That seems to be a related but separate issue from zooming to z0. Thanks for the help!

ansis commented 6 years ago

map.setMaxBounds(null); used to achieve this functionality so we could ensure that this function

This sounds good. But I'm wondering if this should be accomplished by doing https://github.com/mapbox/mapbox-gl-js/pull/6918 some other way. I haven't thought deeply about this but my gut instinct is that clamping latitude in the projection function is not the right way to approach this. Projecting { lat: 90, lng: 0 } returns the point at { lat: 85.051129, lng: 0 } and that doesn't seem right.

ryanhamley commented 6 years ago

Would you propose clamping the value from 90 -> 85.051129 before projection happens? That would keep projection simpler and more predictable.

ansis commented 6 years ago

Yeah, making the bounds part of the code responsible for clamping sounds good to me and should let map.setMaxBounds(null) have the old behavior without any special cases.

ryanhamley commented 6 years ago

OK, this dovetails with some work I'm already doing on defining behavior for bounding boxes that cross the antimeridian so I'll take a look at changing this.