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.

ReactMapboxGl style switching: The layer 'layer-1' does not exist in the map's style and cannot be queried for features.

See original GitHub issue
<ReactMapboxGl
      style={getMapStyle()}
>
  <Layer
    type="line"
    layout={{ 'line-cap': 'round', 'line-join': 'round' }}
  >
    <Feature coordinates={props.coordinates} />
  </Layer>
</ReactMapboxGl>

If I have the layer object, the following error is produced when I switch Map styles (getMapStyle() returns a different style…in this case it’s from ‘mapbox://styles/mapbox/streets-v9’ to ‘mapbox://styles/mapbox/satellite-streets-v9’) “The layer ‘layer-1’ does not exist in the map’s style and cannot be queried for features.”

There’s also the following error trace:

Uncaught TypeError: Cannot read property 'forEach' of undefined
    at e.Layer._this.onMouseMove (eval at <anonymous> (bundle.js:10513), <anonymous>:76:21)
    at e.Evented.fire (eval at <anonymous> (bundle.js:10483), <anonymous>:237:700)
    at h (eval at <anonymous> (bundle.js:10483), <anonymous>:183:1330)
    at HTMLDivElement.a (eval at <anonymous> (bundle.js:10483), <anonymous>:183:788)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
z0d14ccommented, Mar 25, 2017

btw this issue (or a very similar one) will also manifest itself not just when changing styles, but also for example:

  1. Be on page A
  2. Navigate to Page B which has a <ReactMapboxGL /> element with various <Layer />s and such in it
  3. Quickly navigate to page A before all of the sources have been successfully added/loaded on to the map. ReactMapboxGL will be unmounted, causing all of the children to be unmounted, resulting in these errors being thrown.
2reactions
alex3165commented, Mar 23, 2017

I was playing with mapbox-gl and found out that the problem is actually coming from react-mapbox-gl, I will work on it asap.

https://jsfiddle.net/alex3165/acr3ykz5/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapbox - Changing map style causes Directions to not work ...
When you "change a map's style", you're essentially removing all the existing sources and layers, and adding new ones. So it is removing...
Read more >
Change a map's style | Mapbox GL JS
When the user clicks a style name, it uses setStyle to redraw the map using the style URL associated with that option. The...
Read more >
mapbox show zoom controls
Show your own MapBox map styles & 3D buildings inside your bubble app. Such as mkdir -p, cp -r, and rm -rf. If...
Read more >
react-mapbox-gl - npm
Proxy components (proxy between React and Mapbox API). ReactMapboxGL; Layer & Feature. property symbol displays a mapbox symbol. property line ...
Read more >
Using Mapbox GL JS with React - LogRocket Blog
Every time I try to use layers and features, I get a “Module not found: Can't resolve 'react-mapbox-gl'”. Is this a create react...
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