Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Adding Mapbox layer after DeckGL layer does not put Mapbox layer above it #9222

Open
2 of 7 tasks
joshnice opened this issue Oct 24, 2024 · 0 comments
Open
2 of 7 tasks
Labels

Comments

@joshnice
Copy link

Description

Came across a scenario of when I had a DeckGL Scenegraph layer in a Mapbox overlay and then added a new Mapbox layer to the map, the Mapbox layer appeared underneath the DeckGL layer.

Normal Mapbox behaviour would place the most recently added layer to the top of the map.

However I understand this may be intended behaviour however I could not see something in the docs for it, when looking at the beforeId property.

I created an example here - https://codepen.io/joshnice/pen/LYwOeLy?editors=1000

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Display a map on a webpage</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <link href="https://api.mapbox.com/mapbox-gl-js/2.15.0/mapbox-gl.css" rel="stylesheet">
    <script src="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js"></script>
    <script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }

        button {
            position: absolute;
            top: 10px;
            left: 10px;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <button id="add-more-models">Add new layer</button>
    <script>

        mapboxgl.accessToken = "pk.eyJ1Ijoiam9zaG5pY2U5OCIsImEiOiJjanlrMnYwd2IwOWMwM29vcnQ2aWIwamw2In0.RRsdQF3s2hQ6qK-7BH5cKg";

        let deckGlLayer;
        let deckOverlay;

        const createSceneGraphLayer = (beforeId) => {
            return new deck.ScenegraphLayer({
                id: "deckgl-layer-one",
                type: deck.ScenegraphLayer,
                scenegraph: "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BoxAnimated/glTF-Binary/BoxAnimated.glb",
                data: [{ coords: [0, 0] },],
                sizeScale: 10,
                getPosition: (d) => d.coords,
                getOrientation: () => [0, 0, 0],
                beforeId,
                _lighting: "pbr",
            });
        }

        const map = new mapboxgl.Map({
            container: "map",
            style: {
                version: 8,
                layers: [
                    { id: "background", type: "background", paint: { "background-color": "#cccccc" } },
                    { id: "sky", type: "sky" },
                ],
                sources: {
                    "layer-geojson": {
                        type: "geojson",
                        data: {
                            type: "FeatureCollection",
                            features: [
                                {
                                    type: "Feature",
                                    geometry: {
                                        type: "Polygon",
                                        "coordinates": [
                                            [
                                                [
                                                    -0.00041750760772174544,
                                                    0.0002822042163899141
                                                ],
                                                [
                                                    -0.00041750760772174544,
                                                    -0.00022679425441651802
                                                ],
                                                [
                                                    0.0003788494938135045,
                                                    -0.00022679425441651802
                                                ],
                                                [
                                                    0.0003788494938135045,
                                                    0.0002822042163899141
                                                ],
                                                [
                                                    -0.00041750760772174544,
                                                    0.0002822042163899141
                                                ]
                                            ]
                                        ],
                                    },
                                },
                            ],
                        },
                    },
                }
            },
            center: [0, 0],
            zoom: 20,
            pitch: 60,
            bearing: 0,
            hash: true,
            useWebGL2: true
        });

        map.on("error", (event) => {
            console.error(event.error.message);
        })

        map.once("idle", () => {
            deckGlLayer = createSceneGraphLayer(undefined);
            deckOverlay = new deck.MapboxOverlay({
                interleaved: true,
                layers: [deckGlLayer],
            });

            map.addControl(deckOverlay);
        });

        document.getElementById("add-more-models").onclick = () => {
            const layer = {
                id: "layer", type: "fill", paint: { "fill-color": "red" }, source: "layer-geojson",
            }
            map.addLayer(layer, undefined);
        }

    </script>

</body>

</html>

Flavors

  • Script tag
  • React
  • Python/Jupyter notebook
  • MapboxOverlay
  • GoogleMapsOverlay
  • CartoLayer
  • ArcGIS

Expected Behavior

The most recent layer to be added to the top of the map.

Steps to Reproduce

Shown in example above.

Environment

  • Framework version: Latest
  • Browser: Edge
  • OS: Windows 11

Logs

No response

@joshnice joshnice added the bug label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant