-
Notifications
You must be signed in to change notification settings - Fork 535
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
ReactMapboxGl style switching: The layer 'layer-1' does not exist in the map's style and cannot be queried for features. #129
Comments
Hey would you mind to send me a link ? JSFiddle or git repository with an example that run into this ? |
I think I understand this error. unfortunately i do not think that layers and such are removed before the style switching code executes, causing these errors. we solved this in our project by unmounting all of our layers before changing styles, although more "native" support of this behavior would be preferable. |
Same issue here, though I didn't get the solution from @z0d14c . <ReactMapboxGl ref="map" accessToken={ KEY } center={ center } onMoveEnd={ this.onMoveEnd } containerStyle={ { ...style, ...CONTAINER_STYLE } } style={ mapStyle } {...mapProps} >
{ children }
</ReactMapboxGl> Suppose children is any layer, or multiple layers, e.g. <Layer type="circle" id="position-marker" beore="position-marker-accuracy" paint={ POSITION_CIRCLE_PAINT }>
<Feature coordinates={ userPosition } onMouseEnter={ onMouseEnter } onMouseLeave={ onMouseLeave } onClick={ onClick } />
</Layer> when the prop
May be also related mapbox/mapbox-gl-draw#512 |
Hey @lamuertepeluda if you can reproduce the bug using https://github.com/alex3165/react-mapbox-gl-debug that would be very helpful for me to debug then |
Ok @alex3165 , I post here both the problem and my workaround/solution using In App.zip you will find: Copy and paste the code into your setup. |
Can the styledataloading event come to rescue? |
[may be off-topic here] but probably also an handler for the map load event can be helpful |
I dived into this issue, it is actually a major issue, the problem is that when we change the style of the map, all the layers and sources added previously using There is 2 workaround possible I would say:
Thanks @lamuertepeluda for reproducing the bug, it has been very helpful 👍 |
@alex3165 you're welcome. I think you could put on the proposed workaround n.2 while waiting for an answer to workaround n.1. What do you think about it? Since it's internal to the the |
I was playing with mapbox-gl and found out that the problem is actually coming from |
@alex3165 is that supposed to be throwing errors? im not getting any errors from that fiddle. |
btw this issue (or a very similar one) will also manifest itself not just when changing styles, but also for example:
|
this PR fixes the previously described issue for me, although im not 💯 on whether it fixes these types of issues overall. |
Cancelling the PR above ^ because I realized something else was the problem. |
Same problem here- need to select a different map style on the fly. Is there a way to remove everything from the map and then change styles. I'm using Redux for state, so it's no big deal to add all items back to the map. Or any other ideas? |
@brycebigger essentially the way we do it is by using a flag to hide all of the map components like etc. until the style is done loading. |
I couldn't find any good solution for now, so I removed the logic to update the style as it doesn't work anyway. If anyone has a good solution for that, feel free to open a PR. |
@alex3165 i left a comment but i think your change is breaking for those of us who were using the workaround of making sure our layers were removed, changing the style, then adding them back. I know that may not be a good reason to keep the functionality, but I think its worth mentioning as I won't be able to upgrade to the newest version of this library without finding a fix. |
@z0d14c Ok I am sorry for that I reverted it back with the version |
@alex3165 thanks for the quick response, i will try to find some time this weekend to work on identifying a more robust fix for this problem. |
why am I still getting this? |
Hi we have this problem too. we're using latest v2 version (2.15.0) |
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:
The text was updated successfully, but these errors were encountered: