mapbox / mapbox/mapbox-maps-android

`pixelForCoordinate` clamps output, which breaks some scenarios.

Open
#2,297 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle: feature :green_apple:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the public MapboxMap method pixelForCoordinate and compare it with the internal NativeMapImpl conversion mentioned in the report. The change is complete when callers can obtain an unclamped screen coordinate instead of (-1, -1) for off-screen positions, while the existing map-centering scenarios work without reflection.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.