Hi,
Im working with arcgis api 3.38 Directions Widget, I have declared the directions widget as below:
var directions = new Directions({
map: map,
showClearButton: true,
showSegmentPopup: false,
directionsLengthUnits: "esriMiles",
mapClickActive: true,
routeTaskUrl: "https://xxxxxxxx/arcgis/rest/services/CALCUL_ITINERAIRE/NAServer/Route",
searchOptions: options
}, "dir");
directions.startup();
The question is, there is a way to recuperate the Directions route info Details (Start Point, Time,... Finish Point, time) as I want to send them to a web service URL
Many thanks for your help
Solved! Go to Solution.
I have solved the issue as below, Many thanks for your support
directionsW.on("directions-finish", changeHandler);
function changeHandler(data) {
console.log("done", data.result);
if (data.result.routeResults.length > 0) {
const features = data.result.routeResults[0].stops;
features.forEach(function (result, i) {
console.log(result.attributes.Name );
});
}
}
You should be able to listen to the `directions-finish` event, which returns a RouteResult that you can then handle as you wish.
https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#event-directions-finish
Many thanks for your reply, could please describe it with a sample of code as Im a beginner and dont have enough experience to handle it please .
I have solved the issue as below, Many thanks for your support
directionsW.on("directions-finish", changeHandler);
function changeHandler(data) {
console.log("done", data.result);
if (data.result.routeResults.length > 0) {
const features = data.result.routeResults[0].stops;
features.forEach(function (result, i) {
console.log(result.attributes.Name );
});
}
}
Hi I have tried to sort it out, and have created somthing like below
directions.on("directions-finish", changeHandler);
function changeHandler(data) {
if (data.routeResults.length > 0) {
const features = data.routeResults[0].directions.features;
features.forEach(function (result, i) {
console.log(result.attributes.text);
});
But I have got a message error :
TypeError: Cannot read properties of undefined (reading 'length')