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.05k stars 2.21k forks source link

Inconsistent behavior in `getBounds`, `cameraForBounds`, `fitScreenCoordinates` and `fitBounds` with `globe` projection #11795

Open akoylasar opened 2 years ago

akoylasar commented 2 years ago

When globe projection is used the following snippets yield inconsistent behavior when compared to mercator projection:

getBounds and cameraForBounds:

const c = map.cameraForBounds(map.getBounds());
map.easeTo(c);

https://user-images.githubusercontent.com/67509069/164701266-16ce6e51-6faf-490f-94aa-74045d3ee2e7.mp4

The returned camera transform should remain the same similar to when mercator is in use:

https://user-images.githubusercontent.com/67509069/164701298-847b9f91-30c4-4bbf-ac70-743d6d0fb1e5.mp4

fitScreenCoordinates:

map.fitScreenCoordinates([0, 0], [map.transform.width, map.transform.height], map.getBearing())

https://user-images.githubusercontent.com/67509069/164707548-bb06e6a5-52b9-4d3e-8a61-da3280a18d26.mp4

fitBounds:

map.fitBounds(map.getBounds());

https://user-images.githubusercontent.com/67509069/164712924-6dee4d71-c681-473b-9971-c36d609e994f.mp4

boxZoom:

https://user-images.githubusercontent.com/67509069/164719186-e14b7ae6-423f-4053-84ea-2c03f90a1b5f.mp4

avpeery commented 2 years ago

Here are more different behaviors with box zoom. I note in the example @akoylasar provided that the behavior occurs only when zoomed in to a certain point. A few more interesting behaviors is if I make a box off the globe it'll rotate the globe in that direction and zoom in.

https://user-images.githubusercontent.com/42715836/164816675-27ea64b9-a547-40b5-9c68-4792884d8530.mov

SnailBones commented 2 years ago

I think that some of these behaviors are happening because off-sceen mouse events are currently handled as if they were on the closest point on the horizon (as demonstrated in #11746).

getBounds currently works by min-maxing the positions of the viewport corners. In the case of globe when the corners are in space, this clearly doesn't work and will require a different algorithm.

karimnaaji commented 2 years ago

Notes from globe view meeting:

We need to ensure that these APIs are no-op (instead of returning invalid values) with globe view projection, as these need to be thought about for 3d and were mainly designed for the 2d case. The current state of returning incorrect results can be rather misleading for our users. We also need to coordinate with native to be sure to adopt the same no-op behavior.

karimnaaji commented 2 years ago

https://github.com/mapbox/mapbox-gl-js/pull/11882

SnailBones commented 2 years ago

These functions have been re-enabled in globe in https://github.com/mapbox/mapbox-gl-js/pull/12008 due to their widespread use. We should address providing a correct implementation soon.