mapbox / mapbox/mapbox-gl-directions

Changing map style causes plugin to throw errors

Open
#190 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug
Dominant language
JavaScript
Stars
255
Forks
130
PR merge metrics
No merged PRs in 30d

Description

This bug was initially filed as https://github.com/mapbox/mapbox-gl-js/issues/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.`

https://github.com/mapbox/mapbox-gl-directions/blob/31c7911a616a0e2e306742b30d87e33cdfd56c8f/src/directions.js#L304-L312

### Steps to Trigger Behavior

1. Add directions route to map
2. Change base map style
3. Move mouse around the map

### 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/directions.js at lines 304-312 and reproduce the reported sequence: add a directions route, change the base map style, then move the mouse. Verify the plugin's behavior when the route feature or queried layer is absent. Done means changing the style and moving around the map no longer throws errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.