Mapbox 11 breaks cameraForCoordinates
Environment
- Android OS version: 13
- Devices affected: Samsung Tab Active4 Pro
- Maps SDK Version: 11.0.0, 11.1.0, 11.2.0-beta.1, 11.2.0
Observed behavior and steps to reproduce
cameraForCoordinates gives zoom levels that are too zoomed out outside of 45 degree rotation increments.
We underlay a mapbox map to fit coordinates given the lat lon of the topLeft and bottomRight of the screen.
map.setCamera(
map.cameraForCoordinates(
listOf(fromLngLat(topLeft.x, topLeft.y), fromLngLat(bottomRight.x, bottomRight.y)),
EdgeInsets(0.0, 0.0, 0.0, 0.0),
Math.toDegrees(renderer.rotation),
0.0
)
)
This only works when the rotation in degrees % 45 == 0. Outside of this the returned zoom from cameraForCoordinates is too zoomed out.
https://github.com/mapbox/mapbox-maps-android/assets/7464462/2068a31d-946c-499e-b3b5-a3968ed36c37
Expected behavior
The yellow always aligns with the map (as it does at 45 degree rotation increments). This is what happens in Mapbox 10.
Notes / preliminary analysis
Must be somehow fitting a rectangle of the wrong rotation in somewhere to get this effect.
The returned centre is fine, only the zoom returned by cameraForCoordinates is wrong.
Add tests outside 45 degree increments.
Additional links and references
Regression from Mapbox 10 (code is the same, broken after updating to 11).
Possible duplicate to #2080 / #2282
@viktor76525 can you try using latest v11.2.0?
@kiryldz still broken in v11.2.0.
@viktor76525 is this comment relevant for your use-case? If not I'd like to ask you for reproducible code as the issue is not very clear from the video and description.
@kiryldz same input, different output in version 10 vs 11 below.
Input
cameraForCoordinates(
listOf(
fromLngLat(170.35194281432135, -45.87917719887077),
fromLngLat(170.3535593659461, -45.88131407799949)
),
EdgeInsets(0.0, 0.0, 0.0, 0.0),
22.5,
0.0
)
v10.16.6
[
center: Point{type=Point, bbox=null, coordinates=[170.35275109013315, -45.880245648708936]},
padding: [top: 0.0, left: 0.0, bottom: 0.0, right: 0.0],
anchor: ,
zoom: 17.730936854021547,
bearing: 22.5,
pitch: 0.0
]
v11.2.0
[
center: Point{type=Point, bbox=null, coordinates=[170.35275109013372, -45.880245648708026]},
padding: ,
anchor: ,
zoom: 17.091227085357797,
bearing: 22.5,
pitch: 0.0
]
Summary
Even the coordinates are slightly off in v11 but the major issue is that the zoom level is wrong in v11. Generally v10 and v11 are only equal when bearing % 45 == 0. The further from this case (worst case bearing % 45 == 22.5), the more wrong v11 is. This is why in the video, the map is bouncing as it is rotated instead of being anchored to the polygon which is not rendered in Mapbox. This sort of bug is typical of ignoring the rotation of rectangular objects at one point of the calculation process.
@viktor76525 The way we calculate camera in v11 is different from v10. Differences are expected between v10 and v11. I tried these coordinates above, and the points (green circles with white squares) are within viewport.
@viktor76525 The way we calculate camera in v11 is different from v10. Differences are expected between v10 and v11. I tried these coordinates above, and the points (green circles with white squares) are within viewport.
But the padding is incorrect. Edge Insets are set to 0. Please check the videos below to see how this looks like in practice.
v10 setting the viewport to fit the 2 green circles in the corner: https://github.com/mapbox/mapbox-maps-android/assets/7464462/c0912a7b-9a66-461e-8a8c-8d93dd985cc1
v11 failing to set the viewport to fit the 2 green circles which should be in the corner: https://github.com/mapbox/mapbox-maps-android/assets/7464462/1e7dab75-ec69-4510-bc43-83610e241ad5
The computation results really differs a lot, the same input parameters in our project resolve to zoom level about 14.8 in v10, and 12.1 in v11 — definitely above some rounding error.
The non-deprecated cameraForCoordinates method from v11.4.0-beta.2 works ok, and resolves the zoom to the same scale as it was for v10