mapbox / mapbox/mapbox-gl-js

How can threejs layers and mapboxgl layers have the correct layering relationship?

Open
#12,864 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

**mapbox-gl-js version**: ^2.15.0

### Question

I added two layers using threejs in mapboxgl. The expected rendering order of the layers is layerA - background - layerB, but the actual order is background - layerA - layerB.

### code

```
layers: [
{
id: "background",
name: "背景",
category: "背景",
type: "background",
paint: {
"background-color": "rgba(9, 26, 56, 0.71)",
},
},
],

map.on("style.load", function () {
// instantiate threebox
window.tb = new Threebox(map, map.getCanvas().getContext("webgl"), {
defaultLights: true,
enableSelectingObjects: true,
});

map.addLayer(
{
id: "layerA",
type: "custom",
renderingMode: "3d",
onAdd: function (map, mbxContext) {
//instantiate a red sphere and position it at the origin lnglat
var sphere = tb
.sphere({ color: "red", material: "MeshToonMaterial" })
.setCoords(origin);
// add sphere to the scene
tb.add(sphere);
},
render: function (gl, matrix) {
tb.update();
},
},
"background"
);

map.addLayer({
id: "layerB",
type: "custom",
renderingMode: "3d",
onAdd: function (map, mbxContext) {
//instantiate a red sphere and position it at the origin lnglat
var sphere = tb
.sphere({ color: "red", material: "MeshToonMaterial" })
.setCoords([-122.434, 37.7453, 1]);

// add sphere to the scene
tb.add(sphere);
},
render: function (gl, matrix) {
tb.update();
},
});
});
```

### mapboxgl order
![image](https://github.com/mapbox/mapbox-gl-js/assets/2898403/1c8de435-6536-44fa-aa3e-bb94ffb98bad)
### rendered results
![image](https://github.com/mapbox/mapbox-gl-js/assets/2898403/01d68f3c-c579-4ec6-bc73-07bb11e82fca)

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 with the map.addLayer calls in the issue, especially the custom layer render callbacks and the "background" before-ID. Read the custom-layer ordering behavior and compare it with the Threebox update path. Done means establishing whether the requested layerA-background-layerB relationship is supported and documenting or reproducing the correct behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, three.js
Domain
computer-graphics, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.