Save route itinerary details and load it again in arcgis api js 3.38

725
4
11-02-2021 07:34 AM
benchikh
New Contributor III

Hi,

I am working with arcgis api 3.38 Directions Widget, and Im wondering if can I save the route itinerary generated in a database or a file and then give the user the possibility to load the saved route again on map.

Many thanks

0 Kudos
4 Replies
Noah-Sager
Esri Regular Contributor

Hi @benchikh, thanks for posting your question here. If you're on 3x (and I do recommend using 4x if you have the ability; we have a lot of exciting Directions work in development there), then you can use the directions-finish event to grab the route results from the Directions widget.

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

The route result should have all the information you need. You can save it as a portal item and share it easily, or handle it locally as you wish.

https://developers.arcgis.com/javascript/3/jsapi/routeresult-amd.html

Hope this helps!

0 Kudos
benchikh
New Contributor III

HI Many thanks for your response

I can get the directions result with the below code instructions

directionsW.on("directions-finish", changeHandler);

function changeHandler(data) {
console.log("done", data.result);
dataFounded = data.result.routeResults[0];
if (data.result.routeResults.length > 0) {
const stopes = data.result.routeResults[0].stops;
stopes.forEach(function (result, i) {
console.log(result.attributes.Name);
});
}
}

 

but I dont know how can I save in a portal and load it again as you mentioned?

 

the second choise is save it locally and this is what I'm traying to do so I arrived to save the points(Stops) but still not able to load them again correctly on the map with associated restriction.

so if you could help me again with that it would be much appreciated.

Thanks again

0 Kudos
Noah-Sager
Esri Regular Contributor

Saving to a portal can be easily accomplished with the Directions widget itself. Look at line 51 here: https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=widget_directions_basic

Another option is to use the RouteTask to handle the routing between points:

https://developers.arcgis.com/javascript/3/sandbox/sandbox.html?sample=routetask_multiple_stops

Also worth noting, if you're starting a new project, I highly recommend the 4x directions widget, which will soon have saving to portal as an option as well, and is the more modern and recommended approach: https://developers.arcgis.com/javascript/latest/sample-code/widgets-directions/

 

0 Kudos
benchikh
New Contributor III

Hi Thanks for your reply 

Yes I already tried that, I have turned the showSaveBtn to true value, but Im not able to see the button on my widget, looks like there is something need to be configured on our Arcgis Server.

About 4.x Versio, OK I will try to work with it but Im not sure if can I find all the features/options that are in the Directions widget within 3.38

 

0 Kudos