visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.29k stars 2.09k forks source link

[Bug] MapboxOverlay throw id already exists when interleaved=true #9043

Closed chunlampang closed 2 months ago

chunlampang commented 4 months ago

Description

Any layer inside MapboxOverlay will throw Error: Layer with id "layer-id" already exists on this map when interleaved is set to true.

Flavors

Expected Behavior

No error

Steps to Reproduce

const { MapboxOverlay, TextLayer } = deck;

mapboxgl.accessToken = 'token';
const map = new mapboxgl.Map({
  container: document.body,
  style: "mapbox://styles/mapbox/light-v11",
  center: [0, 0],
  zoom: 10,
});

map.on('load', () => {
  const mapboxOverlay = new MapboxOverlay({
    interleaved: true,
    layers: [
      new TextLayer({
        id: 'TextLayer1',
        getText: (d) => d.name,
        getPosition: (d) => d.position,
        data: [
          { name: 'Hiiiii', position: [0, 0] }
        ]
      })
    ]
  });
  map.addControl(mapboxOverlay);
});

Environment

deck.gl@9.0.24 mapbox-gl@3.5.2

Logs

No response

moong23 commented 4 months ago

It seems like the issue is with mapbox-gl@3.5.2. I found that no errors occur with version 3.5.1 of mapbox-gl. I've also reported the bug to the mapbox-gl library. https://github.com/mapbox/mapbox-gl-js/issues/13239

Pessimistress commented 4 months ago

Thanks for bringing this to our attention. I provided a reproduction on the upstream issue thread.

dekc commented 3 months ago

FYI same error occurs with previous major deck.gl version. That is

Pessimistress commented 3 months ago

@dekc this is a Mapbox bug, not deck.gl's. It's been acknowledged by Mapbox.

chunlampang commented 3 months ago

In mapbox-gl 3.6.0, they solved the bug, but created another error. TypeError: Cannot read properties of undefined (reading 'setProps')

aemonm commented 3 months ago

Follwoing up on @chunlampang, specifically the issue is now caused by this section of code:

function DeckGLOverlay(props: DeckProps) {
  const overlay = useControl<MapboxOverlay>(() => new MapboxOverlay(props));
  overlay.setProps(props);
  return null;
}

which is found here in the MapboxOverlay section of the docs. Issue is present in mapbox-gl: 3.6.0

chunlampang commented 3 months ago

In mapbox-gl 3.6.0, they solved the bug, but created another error. TypeError: Cannot read properties of undefined (reading 'setProps')

Someone opened another issue for this case. https://github.com/visgl/deck.gl/issues/9086