mapbox / mapbox/mapbox-maps-android
Map gestures (drag, pinch-to-zoom) broken when app runs in secondary pane on dual-pane/multi-window displays
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 578
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- **Android OS version:** Android Automotive OS (Android 13+)
- **Devices affected:** Infotainment systems with dual-pane displays. Likely affects any Android Automotive or multi-window setup where the app runs in a secondary pane with a non-zero display offset.
- **Maps SDK Version:** 11.16.2 (Mapbox Maps SDK for Android)
## Observed behavior and steps to reproduce
1. Run an app containing a `MapboxMap` (Compose) or `MapView` in a **dual-pane / split-screen** configuration where the app is positioned in the **right/secondary pane**
2. Attempt to **drag** (pan) the map — the camera does not move
3. Attempt to **pinch-to-zoom** — the gesture either doesn't respond or zooms to the wrong focal point
4. **Tap** on the map — this works correctly
5. **Fast fling** (drag and lift quickly) — may partially work, moving the camera via the fling animation
The issue does **not** occur when the app runs in the left/primary pane or in full-screen mode.
### Diagnostic findings
We instrumented touch events on the `MapView` and found:
| | Left pane (working) | Right pane (broken) |
|---|---|---|
| `getX()` / `getY()` | Correct (view-relative) | Correct (view-relative) |
| `getRawX()` / `getRawY()` | Same as `getX/Y` | Offset by pane position (~860–2880px in X) |
| `getLocationOnScreen()` | `(0, 0)` | `(0, 0)` — **incorrect**, should reflect pane offset |
| `getLocationInWindow()` | `(0, 0)` | `(0, 0)` |
The SDK's internal gesture detectors (e.g. `MoveGestureDetector`) appear to use `getRawX()`/`getRawY()` for focal point calculations. Since `getLocationOnScreen()` incorrectly reports `(0, 0)` on the right pane, the SDK cannot compensate for the display offset, resulting in a focal point that is off by the pane's X offset (e.g. ~2880px on a wide display).
## Expected behavior
Drag, pinch-to-zoom, and all other map gestures should work correctly regardless of the app's position on the display — including when running in a secondary pane in a dual-pane or multi-window configuration.
## Notes / preliminary analysis
The root cause appears to be in the gesture handling pipeline within the SDK. Specifically:
- The gesture detectors use `MotionEvent.getRawX()`/`getRawY()` (display-absolute coordinates) for focal point and movement delta calculations
- On dual-pane automotive displays, the `MapView` reports `getLocationOnScreen() = (0, 0)` even when it has a significant display offset, so the SDK cannot correct for the difference between raw and local coordinates
- This is similar to the issue fixed in [PR #1575](https://github.com/mapbox/mapbox-maps-android/pull/1575) (`MapSurface#surfaceChanged` not updating dimensions for plugins) and related to [issue #2131](https://github.com/mapbox/mapbox-maps-android/issues/2131) (coordinate projection issues)
**Our workaround**: We intercept touch events via `setOnTouchListener` and create corrected `MotionEvent` copies (using `MotionEvent.obtain()` with `PointerCoords` from `getPointerCoords()`) where `getRawX() == getX()`, then dispatch the corrected event to `MapView.onTouchEvent()`. This resolves the issue for all gesture types.
A proper SDK fix would likely involve the gesture detectors using view-relative coordinates (`getX()`/`getY()`) instead of `getRawX()`/`getRawY()`, or correctly accounting for the view's screen position when computing focal points.
## Additional links and references
- Related PR: [#1575 — Fix MapSurface#surfaceChanged](https://github.com/mapbox/mapbox-maps-android/pull/1575)
- Related issue: [#2131 — pixelForCoordinate / coordinate projection](https://github.com/mapbox/mapbox-maps-android/issues/2131)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the gesture handling pipeline around MapView, onTouchEvent(), and detectors such as MoveGestureDetector, focusing on their use of MotionEvent coordinates. Reproduce the issue in a secondary pane with a non-zero display offset and compare drag and pinch behavior with the primary pane. Done means map gestures use the correct focal point and movement in both configurations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100