Select to view content in your preferred language

Directions widget not updating travel modes when changing routing service

627
6
01-04-2022 07:11 AM
voliv
by
Emerging Contributor

I'm using Directions Widget available in Api for Javascript 3.39.

The user can choose two routing services. When I want to change the routing service, changing the RouteTask for the directings widget, it doesn't update the travel modes available to select from in the Travel Modes list.

How do I accomplish this?

Do I need to destroy the directions widget and create it again everytime the user changes the routing service? I need the user to be able to use the same input for both routing services, so if I need to destroy the object, I would need to save and recreate everything, and I would really like to avoid this, if possible. 

 

0 Kudos
6 Replies
Noah-Sager
Esri Regular Contributor

Hi @voliv, thanks for posting your question here. It sounds like the widget would need to be somehow refreshed or re-created. Have you tried either of these methods?

https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#reset

https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#settravelmode

Also, do you have the ability to migrate to 4x?

0 Kudos
voliv
by
Emerging Contributor

Hello @Noah-Sager !
Thank you for your reply.

I have tried to reset the widget with no luck. 

As far as I understand setTravelMode, its to force the widget to use one of the travel modes already loaded for that routing service. The thing is the travel modes from the actually loaded routing service are not reflected in the widget. There is a method called getSupportedTravelModeNames, which returns the Supported Travel Node names for the routing service used by the widget, and when I call it, I get the names from the previously loaded routing service.

My guess is, even if the widget allows to set a different RouteTask, and it actually starts routing with that service, it doesn't update the rest of the information in the widget itself. 
That's why I'm wondering if I'm missing something else I need to do, that maybe is not documented, and it's not just setting the new routeTask, or it's just something that is missing in the implementation of the widget and I'm basically in trouble and have to find another way 🙂

 

ETA: Migrating to 4x is in the plans but not possible yet. Do you think this is solved in that version? 

0 Kudos
Noah-Sager
Esri Regular Contributor

Ok, if those methods aren't working, then it's probably reading the metadata from the route service upon load, and then even if you change the route service, the widget would need to be destroyed and recreated to honor the updated settings. I'm not sure if we solved this in 4x yet, but we are putting most of our resources in 4x development currently, and we have a lot of exciting plans for Directions and Routing in 4x coming soon.

voliv
by
Emerging Contributor

I'll go cry in the corner now then, haha

I'm looking forward to the improvements in 4x for when we are able to migrate.
Is it possible for both apis to coexist within the same project? Maybe I could use the 4x Directions widget and leave the rest in 3x until we are able to migrate the whole project? Thank you!

0 Kudos
Noah-Sager
Esri Regular Contributor

It's probably possible, but not recommended to mix 3x and 4x in the same project. I'd like to learn more about your use case though. Why do users need the option of choosing between two routing services? And why change them on-the-fly as opposed to making the choice up front? Have you tried having 2 Directions widgets?

0 Kudos
voliv
by
Emerging Contributor

They use different data, one over the data as it exist today, and another with data as it will exist in the future, and they want to be able to run the same scenario for both. I have thought about using two widgets, but the problem would remain the same as if I need to destroy the widget and recreate it, being that I need to clone the input from one to the other. 

0 Kudos