Globe view may switch between correct layer order and drape first mode (optimized mode)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Current behavior**
There's a potential issue visible from the `geojson-polygon` example that gets inherited from terrain rendering with draping that globe view leverages, note the change of layer order during the transition to mercator:
https://user-images.githubusercontent.com/7061573/164814346-de8c96fc-3ed2-47cb-bc82-9abe6679f5e1.mov
Since layer draw order is not always honored with terrain unless we force it (when using the map option `optimizeForTerrain` to switch draped rendering to draw-order priority, refer https://docs.mapbox.com/mapbox-gl-js/api/map/#map-parameters), there may be inconsistency with globe where we switch between the two modes at runtime around the transition between globe and mercator, since one projection uses draping but the other doesn't.
A reminder on the `optimizeForTerrain` option:
>With terrain on, if true , the map will render for performance priority, which may lead to layer reordering allowing to maximize performance (layers that are draped over terrain will be drawn first, including fill, line, background, hillshade and raster). Otherwise, if set to false , the map will always be drawn for layer order priority.
A few situation describing this issue and impact when using globe:
- If the user creates a map using `optimizeForTerrain: false`, this issue is will not occur, but performance can be impacted
- If the user creates a map without providing this option, it will default to `true` meaning that layer reordering can happen and this issue will manifest itself when a draped layers is added on top of other non-draped layers (such as a polygon on top of symbols) **and** the user crosses the transition threshold
| | Globe > transition | Globe < transition | Globe + Terrain > transition | Globe + Terrain < transition | Terrain | Mercator |
|-|-|-|-|-|-|-|
|`optimizeForTerrain:true`| :red_circle: | :green_circle: |:green_circle: |:green_circle: |:green_circle: | no-op |
|`optimizeForTerrain:false`| :green_circle: | :green_circle: | :green_circle: | :green_circle: |:green_circle: | no-op |
*:red_circle: potential inconsistency of draw order across zoom ranges
*:green_circle: consistent draw order across zoom ranges as per `optimizeForTerrain` definition
**Potential options**
1. We force correct draw order when using globe projection. This option may have a high performance impact on globe and would have to be profiled carefully before being adopted. Choosing this option could lead to confusion:
- it would diverge from the behavior adopted by terrain
- the globe + terrain use case would be inconsistent with terrain
2. We force mercator draw order to match globe draw order. This option would mean reordering the layers to match the drape-first approach when terrain is in optimized mode and globe is used, preferring consistency. Choosing this option would mean that draw order would be different between globe and mercator
**Expected behavior**
Layer draw order is consistent while using globe across all zoom ranges as per `optimizeForTerrain` definition and performance isn't impacted when using `optimizeForTerrain: true`.
**Workaround**
For consistency, it's possible to switch to `optimizeForTerrain:false` option.
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 reproducing the behavior in the geojson-polygon example while crossing the globe-to-Mercator transition, with and without terrain and with optimizeForTerrain set to true or false. Read the optimizeForTerrain map option description and compare the two proposed draw-order approaches. Done means globe layer order remains consistent across zoom ranges without the performance impact described for optimized terrain rendering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- computer-graphics, web-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100