mapbox / mapbox/mapbox-gl-js

mouseMove event lngLat is offset from mouse pointer at intermediate zoom levels

Open
#13,322 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

I have a mapbox app that plots points on a map and lets the user hover to reveal additional info. To detect hover state, I'm using a mousemove event + queryRenderedFeatures, but the event's lngLat doesn't always correspond to the mouse cursor's apparent position. It appears to happen at intermediate zoom levels (approximately zoom "5.5"). Setting the map projection to "mercator" prevents the offset from occurring, but I prefer to keep the default "globe" view if possible.

Is there any way to fix the offset, while still using "globe" projection?

**mapbox-gl-js version**: 3.7.0

**browser**: Chrome, Safari, Edge

### Steps to Trigger Behavior

1. Create a map with the default "globe" projection, set to zoom level 5.5
2. Trigger a mousemove event and get the lngLat
3. Draw a point at the lngLat coordinates, and notice that it is not aligned with the mouse

### Link to Demonstration
I built this debug app to show the offset visually. Mousing over the red dots in the grid should cause a popup to appear. The green-and-red circle shows the mousemove event's point.lngLat coordinates. The green-and-red circle does not track my cursor precisely, which makes it hard to select a specific dot.
https://output.jsbin.com/xewegam/1
![mapbox](https://github.com/user-attachments/assets/cf83b1fa-d432-4aee-abc2-a51f45410424)

### Expected Behavior
mousemove lngLat is visually aligned with the mouse cursor
### Actual Behavior
lngLat is misaligned, with a variable offset that depends on the position of the cursor within the map window

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 reproducing the issue with the linked JSBin in mapbox-gl-js at globe projection and zoom 5.5, then compare the mousemove event's lngLat with mercator behavior. Trace the globe projection's pointer-coordinate handling and verify the reported point stays aligned with the cursor across the map window and intermediate zoom levels.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.