question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when removing a layer

See original GitHub issue

Hi,

Sometimes, I got this error when I try to remove a layer from my map.

mapbox-gl.js:411 The layer '5948b9f3b506c203ba0d7baa' does not exist in the map's style and cannot be queried for features.
Uncaught TypeError: Cannot read property 'length' of undefined

Here is my code :

render() {
    console.log(this.state.locations)
    return (
      <div>
        <Map
          style="mapbox://styles/mapbox/streets-v9"
          containerStyle={{
            height: '100vh',
            width: '100vw'
          }}>
          {this.state.locations.length > 0 &&
            this.state.locations.map(l =>
              <Layer type="symbol" id={l.id} layout={{ 'icon-image': 'marker-15' }} key={l.id}>
                <Feature coordinates={[getFloat(l.longitude), getFloat(l.latitude)]} />
              </Layer>
            )}}
        </Map>
      </div>
    )
  }

On my page, I have a menu to select and unselect locations and it’s modifying my locations array. When I come on my page for the first time, my locations array is empty but I don’t get any error. When I select a locations it’s displaying a layer correctly on my map, but when I unselect some locations and remove it from my array, mapbox-gl.js is throwing this error. It seems to happen a bit randomly.

Thanks for your help.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
clydecbrowncommented, Aug 30, 2017

Here is the underlying bug: https://github.com/mapbox/mapbox-gl-js/issues/5145. The fix should be in the next mapbox-gl-js release (0.40.0).

0reactions
DanielAeoncommented, Nov 27, 2017

Did you investigate the error in the above comment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot remove a layer from a group in TOC in Pro
The workaround is to remove the whole group layer, then "undo" the remove. After this, i can remove layers from the group, but...
Read more >
Code error - remove layer using python - GIS Stack Exchange
Code error - remove layer using python ... Have you got an mxd in your list that has no layers, or perhaps the...
Read more >
Error: Can not execute remove on an inactive layer - Mocha Pro
I have four total layers and all of them are active. My remove, my background, one foreground layer and a layer I used...
Read more >
Error Deleting an App layer due to a Template
Location: UdmcSilverlight.Modules.Layers.Wizards.Delete.ViewModels.ContainerDeleteViewModel Message: 2 Templates are using layer version '1' Details: Remove the ...
Read more >
Error in removing the first layer of keras model - Stack Overflow
I was not able to recreate the error you were facing. May be you can share the reproducible code. Below options I have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found