mapbox-maps-android
mapbox-maps-android copied to clipboard
`pixelForCoordinate` clamps output, which breaks some scenarios.
Environment
- Android OS version: any
- Devices affected: any
- Maps SDK Version: 11+
Observed behavior and steps to reproduce
The method pixelForCoordinate returns the screen coordinate of (-1, -1) if the output falls off-screen. However, this behavior breaks some scenarios. Examples:
- I want to offset the screen based on the user's geolocation changes - which means making sure the screen position of the user's geolocation marker remains the same while moving. I calculate the pixel offset between the current and the new position to do that. If one of them is off-screen - this calculation goes wrong, and the map gets centered on the wrong position.
- I want to expand the bottom sheet of a placemark and focus the map on that placemark in the fully expanded state. The centering part only works correctly if the placemark is on screen initially.
I tried calling the MapboxMap internal property NativeMapImpl method for this conversion via reflection, which removes clamping - and the above two scenarios worked flawlessly. But it feels hacky, and I'd like to avoid reflection as much as possible.
Considering that, can we have the version without clamping? Thanks.
@boiler23 we introduced clamping in https://github.com/mapbox/mapbox-maps-android/pull/1226 as we could not guarantee things will be valid if we're offscreen. However I asked native folks what could be our options here.
@boiler23 ok, so the answer is:
It works in case the pitch is zero, if it’s not zero, the coordinate might be behind the camera’s position and in those cases it returns random values.
So that's why clamping was added. There are no immediate plans to provide proper support for offscreen values but there's an internal issue tracking this. Guess for now I could only suggest using reflection if you're sure that pitch == 0.
Ok, thanks for clarifying! I will check the pitch and stay with reflection at the moment.