GithubHelp home page GithubHelp logo

Comments (5)

Pessimistress avatar Pessimistress commented on September 5, 2024 1

deck.gl uses map.getLayer(id) to determine if a layer already exists in the stack. Starting 3.5.2, this method is returning undefined for a layer that is already added.

Here is a minimal reproduction:

const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/light-v9',
  accessToken: MAPBOX_TOKEN
});

const layer = {
  id: 'my-layer',
  type: 'custom',

  onAdd() {
    console.log(`Layer ${this.id} is added`);
  },

  onRemove() {
    console.log(`Layer ${this.id} is removed`);
  },

  render() {}
}

map.on('styledata', () => {
  if (map.getLayer(layer.id)) {
    // already added
  } else {
    map.addLayer(layer);
  }
});

Log:

Layer my-layer is added
evented.ts:172
Error: Layer with id "my-layer" already exists on this map
    at Da.addLayer (style.ts:2118:38)
    at Map.addLayer (map.ts:2813:20)
    at Map.<anonymous> (app.js:38:9)
    at Map.fire (evented.ts:150:26)
    at Map.<anonymous> (map.ts:768:18)
    at Map.fire (evented.ts:150:26)
    at Da.fire (evented.ts:166:24)
    at style.ts:1202:18
    at h2 (load_sprite.ts:55:13)
    at load_sprite.ts:37:27

from mapbox-gl-js.

stepankuzmin avatar stepankuzmin commented on September 5, 2024

@moong23, could you please make a standalone reproduction of this? I.e., using only GL JS?

from mapbox-gl-js.

moong23 avatar moong23 commented on September 5, 2024

@stepankuzmin well haven't tried to use GL JS only, but i'll try my best 😃

from mapbox-gl-js.

moong23 avatar moong23 commented on September 5, 2024

thx @Pessimistress

from mapbox-gl-js.

stepankuzmin avatar stepankuzmin commented on September 5, 2024

Thanks, @Pessimistress. This is a bug.

from mapbox-gl-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.