mapbox / mapbox/mapbox-gl-directions

Directions Line/Path Not Appearing on Map

Open
#202 1 comment 10 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

Hey All,

I have an issue with a fairly intricate map with multiple layers, data sources (all of which update realtime) and directions that are dynamically added based on outside coordinates.

I wanted to post what I knew about it and the workaround for documentation and further help by others:

The fix I had to use was:

```javascript
this.directions = new Directions({});
this.directions.on('route',()=>{
try {
this.directions.mapState()
}catch(e){
console.error(e);
}
})
```

Digging into this, I found that the culprit of this is: https://github.com/mapbox/mapbox-gl-directions/blob/master/src/directions.js#L88 where even though the map is actually loaded, this function returns false. Digging into that, it appears that is located here: https://github.com/mapbox/mapbox-gl-js/blob/b57f79d94a530bcc382f65e424f1342c23c84448/src/ui/map.js#L1570 and for me `this._styleDirty` was returning true which was causing the entire thing to fall apart.

Interestingly enough `directions._map._loaded` did in fact return true, however that function simply didn't want to play ball.

Hopefully this helps someone else, and if I can aid in debugging this further, feel free to reach out!

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 with src/directions.js around line 88 and the referenced mapbox-gl-js map.js logic around line 1570. Reproduce the missing directions line with dynamically added directions, realtime layers, and outside coordinates, then investigate the differing _loaded and _styleDirty states. Done means the route appears reliably without relying on the reported event-handler workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.