mapbox / mapbox-gl-directions

Directions plugin for mapbox-gl-js using Mapbox Directions API.
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-directions/
ISC License
237 stars 125 forks source link

Error thrown when trying to swap departure and arrival #296

Open AntoineRondelet opened 1 year ago

AntoineRondelet commented 1 year ago

If you try to swap the depart location with the arrival you get the following error thrown:

mapbox-gl-directions.js:7626 Uncaught TypeError: Cannot read properties of undefined (reading 'coordinates') at HTMLButtonElement.<anonymous> (mapbox-gl-directions.js:7626:68)

This would be great to handle this case gracefully. In some cases this can result in an error message being thrown at the user (which depends on the specifics of the deployment) which isn't very friendly. I think this is something that needs to be handled at the component level with a conditional to check if the boxes are empty or not.

Actually, when only, say, the departure is set, and you hit the "swap" button to set it as arrival, the same error is thrown and the departure gets duplicated instead of swapped. This is rather unexpected. As a user you'd expect the box content to swap and thus the departure to become empty and the arrival box to get the former "departure" value.

Happy to send screens if needed, but the bug should be reproducible when one of the directions boxes (e.g. the departure) is unset and when you then try to swap the values with the double arrow symbol (if no error gets thrown on the UI, open the web console and an error as the one pasted above should show up).