mapbox / mapbox/mapbox-gl-js

Projected coordinates are not being unprojected back to the same coordinates

Open
#11,282 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

`unproject()` seems to be returning the incorrect coordinates when point is off screen. This issue becomes more apparent on higher zoom levels. The objective is to draw multiple lines between two points using only two sets of coordinates.

In the example below, I've removed all calculations I was performing on each zoom event and only projecting then unprojecting the same coordinates.

**mapbox-gl-js version**: version: v2.6.0

**browser**: Tested on Chrome, Safari, Firefox

### Steps to Trigger Behavior

1. Draw a line between using two sets of coordinates by adding a source with a line layer
2. On zoom event, project the each coordinate then unproject each coordinate and update source with resulting coordinates.

### Expected Behavior

**Zoomed out**
![Screen Shot 2021-11-15 at 4 01 47 PM](https://user-images.githubusercontent.com/42789252/141859395-d983b402-bbfc-4f27-a1ab-c174d5ca5ba0.png)

**Zoomed in at level 16**

![Screen Shot 2021-11-15 at 4 08 36 PM](https://user-images.githubusercontent.com/42789252/141859543-6a2a35c2-0fc6-47d8-999a-a9dfcc81de32.png)

### Actual Behavior

**Zoomed in at level 16**

![Screen Shot 2021-11-15 at 4 06 48 PM](https://user-images.githubusercontent.com/42789252/141859617-6bc9c27b-efa8-4889-a0c1-3b526f8f69bd.png)

**I manually added the line at zoom 16 then zoomed out to see the resulting line:**
![Screen Shot 2021-11-15 at 4 12 33 PM](https://user-images.githubusercontent.com/42789252/141859772-86c35059-737c-4149-ae26-0afd1a052486.png)

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

The issue names no source file or test; start by reproducing the project/unproject round trip during zoom events at a high zoom level, using the described two-coordinate line example. Trace the map.project() and map.unproject() entry points and verify that off-screen coordinates remain unchanged after the round trip.

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.