mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Projected coordinates are not being unprojected back to the same coordinates

Open Diegodlt opened this issue 4 years ago • 6 comments

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

Zoomed in at level 16

Screen Shot 2021-11-15 at 4 08 36 PM

Actual Behavior

Zoomed in at level 16

Screen Shot 2021-11-15 at 4 06 48 PM

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

Diegodlt avatar Nov 15 '21 22:11 Diegodlt

@Diegodlt Can you share a minimal example of what you're seeing? I can only partially replicate it when the line is really far offscreen and no longer visible and the changes are very minimal.

ryanhamley avatar Dec 01 '21 21:12 ryanhamley

@ryanhamley Sure thing.

map

Diegodlt avatar Dec 02 '21 16:12 Diegodlt

Can you provide a code example using a site like JSFiddle or CodePen?

ryanhamley avatar Dec 02 '21 21:12 ryanhamley

I was trying to replicate the issue on JS Bin. The issue doesn’t happen when the same source id is used to draw the same line. It only seems to happen when the source id is generated on each zoom event.

In the code example I have both dynamically generated source ids (green line) and a static source id (red line). In the GIF I provided in the original example, I'm removing the sources and layers on every zoom event. I'm not doing that in the code example to show the lines being drawn at each zoom level.

https://jsbin.com/napazequyu/edit?html,console,output map

Diegodlt avatar Dec 03 '21 15:12 Diegodlt

This example is great @Diegodlt Thanks so much for providing that

ryanhamley avatar Dec 06 '21 20:12 ryanhamley

This seems to be a regression introduced in v2.0.0.

SnailBones avatar Jun 24 '22 18:06 SnailBones