`setVisibleCoordinates` won't set viewport crossing international dateline
Platform: iOS Mapbox SDK version: 3.6.0
Steps to trigger behavior
- Create a coordinate just east of the international date line (e.g. Honolulu)
- Create a coordinate just west of the international date line (e.g. Tokyo)
- Update viewport with
setVisibleCoordinates:— passing in these two coordinates
Expected behavior
The viewport is centered between Honolulu and Tokyo (crossing international date line).
Actual behavior
The viewport is centered over the Atlantic Ocean and spans the majority of the world.
Hi @joengelm thank you for using Mapbox. I am sorry to hear you are having some issues. Could you please provide us the coordinates you are using to reproduce the problem.
@fabian-guerra Sure: Honolulu: (21.3069, -157.8583) Tokyo: (35.6895, 139.6917)
From playing around, it seems like this issue occurs for any pair of coordinates whose shortest connecting path crosses the international date line.
@joengelm thank you! We will take a look.
This method Map::cameraForLatLngs is returning wrong values with the lat/lon described above.
@brunoabinader could you please take a look?
This method Map::cameraForLatLngs is returning wrong values with the lat/lon described above.
@fabian-guerra can you please provide a test case?
My understanding is that if e.g. point A is at longitude -179 and point B is at longitude +179, the camera will end up spanning the whole world. If you want a different behavior (shortest path between the points), then consider using LatLng::unwrapForShortestPath in the iOS SDK implementation.
@brunoabinader bounds that cross the antimeridian.
Tokyo: (35.6895, 139.6917) Honolulu: (21.3069, -157.8583)
There are two problems to solve, one is the center. As is now is calculating from -157 to 139 lon; which give us a center near Morocco . The second is related to calculate the conversion from pixel to lat/lon to obtain the correct zoom level.
In this PR https://github.com/mapbox/mapbox-gl-native/pull/9804 I reflected the negative longitude to calculare the zoom based on a reflected area, and calculated the shortest path between points to get the center (I was not aware of the method you said so I made a new one, anyways I'm going to remove the new one). From @1ec5 comments on my PR I think the best solution is tell the transformation matrix when it should extend the degrees beyond 180 to address the case when boundaries cross the antimeridian.
Previously reported in #1867 and #4664. Should we dupe this issue to #4664?
+1
Mapbox Map SDK for iOS already supports setting bounds that cross the anti-meridian. This PR https://github.com/mapbox/mapbox-gl-native/pull/9804 adds documentation to clarify how to handle this case.