-
Notifications
You must be signed in to change notification settings - Fork 127
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
Changing map style causes plugin to throw errors #190
Comments
I was experiencing the same issue as described in the OP and came up with this hack work around which involves removing all the Directions Layers and Source, changing the map style, then re-adding the Source and Layers once again. It is a tedious process and the user will have to query the directions control once again to show a route after the style has changed. Since no one has responded to this thread I thought this might be helpful for others suffering from this same issue. function removeDirectionsLayers(){ function addDirectionsLayers(){ // when you want to switch styles use the following 3 step process |
This seems due to the onAdd method in directions.js
If a style is changed, loaded() will return false while it is loading but the 'load' event only triggers the first time the map is loaded, so it will not trigger if the style is changed after the initial load. Related issues: |
I think that the best solution may be subscribing to the idle event instead, and then unsubscribing once the event has triggered |
It is 2023! And this issue still persists... reloading the data layer after the style change works but only for displaying static data. The Direction Plugin API will still return the same error.
The markers for origin and destination and the routes disappear on the map, even though the API picks up the coordinates correctly and returns the right instructions and route statistics. Here is a simple snippet to recreate this bug if needed. I am desperately searching for workarounds. I tried removing the plugin and then re-creating it after the style change (hoping it will reinitialize the plugin), but it still does not work.
|
This bug was initially filed as mapbox/mapbox-gl-js#7019 but I'm moving it here because the bug is in the plugin.
When you change a map's style, the route feature is removed causing this line to throw the error
Error: The layer 'directions-route-line-alt' does not exist in the map's style and cannot be queried for features.
mapbox-gl-directions/src/directions.js
Lines 304 to 312 in 31c7911
Steps to Trigger Behavior
Link to Demonstration
https://plnkr.co/edit/M8mj1WTH1KjDa1dhiUKw?p=preview
Expected Behavior
The plugin should be able to handle this situation so that no errors are thrown.
Actual Behavior
Errors are thrown.
cc @mikeomeara1
The text was updated successfully, but these errors were encountered: