Select to view content in your preferred language

RouteTask Travel Mode

1925
5
Jump to solution
05-25-2017 03:07 PM
CoryDudart
Deactivated User

I'm having an issue with the travel modes. I cant really find any documentation on it but i found other forum posts related to my problem and tried to make my own fix, it just does not seem like it is doing anything. 

I need the route that it returns from the solve() function to give me trucking routes instead of general ones. It actually looks like its just the first one that it finds, not even optimized for fastest/shortest route like most map routing software does. 

I've attached below the object that gets sent to the solve function if it helps anything. I got the travel mode object from running the getTravelModes function in the rest api. I then pasted it in to the travel mode attribute in the RouteParameter Object.

I've also tried setting the default mode in my account settings but that also does not seem to effect anything.

RouteParameter Object:

{
"returnDirections": true,
"returnRoutes": true,
"returnZ": true,
"returnStops": false,
"returnBarriers": false,
"returnPolygonBarriers": false,
"returnPolylineBarriers": false,
"outSR": 3857,
"outputLines": "esriNAOutputLineTrueShape",
"findBestSequence": false,
"travelMode": {
"attributeParameterValues": [
{
"parameterName": "Restriction Usage",
"attributeName": "Use Preferred Truck Routes",
"value": "PREFER_HIGH"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Unpaved Roads",
"value": "AVOID_HIGH"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Private Roads",
"value": "AVOID_MEDIUM"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Driving a Truck",
"value": "PROHIBITED"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Roads Under Construction Prohibited",
"value": "PROHIBITED"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Gates",
"value": "AVOID_MEDIUM"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Express Lanes",
"value": "PROHIBITED"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Carpool Roads",
"value": "PROHIBITED"
},
{
"parameterName": "Restriction Usage",
"attributeName": "Avoid Truck Restricted Roads",
"value": "AVOID_HIGH"
}
],
"description": "Models basic truck travel by preferring designated truck routes, and finds solutions that optimize travel time. Routes must obey one-way roads, avoid illegal turns, and so on.",
"impedanceAttributeName": "TruckTravelTime",
"simplificationToleranceUnits": "esriMeters",
"uturnAtJunctions": "esriNFSBNoBacktrack",
"restrictionAttributeNames": [
"Avoid Carpool Roads",
"Avoid Express Lanes",
"Avoid Gates",
"Avoid Private Roads",
"Avoid Truck Restricted Roads",
"Avoid Unpaved Roads",
"Driving a Truck",
"Roads Under Construction Prohibited",
"Use Preferred Truck Routes"
],
"useHierarchy": true,
"simplificationTolerance": 10,
"timeAttributeName": "TruckTravelTime",
"distanceAttributeName": "Kilometers",
"type": "TRUCK",
"id": "ZzzRtYcPLjXFBKwr",
"name": "Trucking Time"
},
"stops": "{\"type\":\"features\",\"features\":[{\"geometry\":{\"x\":-112.788894,\"y\":49.706994,\"spatialReference\":{\"wkid\":4326}},\"attributes\":{}},{\"geometry\":{\"x\":-112.84417,\"y\":49.707616,\"spatialReference\":{\"wkid\":4326}},\"attributes\":{}}],\"doNotLocateOnRestrictedElements\":true}"
}

0 Kudos
1 Solution

Accepted Solutions
CoryDudart
Deactivated User

Actually with a bit of tinkering i got it to work and its actually using trucking routes now. I'll post my solution below  for that function.

Thanks for the Help!

function travelModeCallback(ioArgs){
    if((ioArgs.url.search('/solve') > -1)) {
        ioArgs.content.travelMode = JSON.stringify(routeParams.travelMode);
    }
    return ioArgs;
}
esriRequest.setRequestPreCallback(travelModeCallback);

View solution in original post

5 Replies
JohnGrayson
Esri Regular Contributor

Q: What version of the JS API are you using?
Q: Check the parameters being sent to the REST endpoint (Network tab in the browser dev pane) and verify that 'travelMode' is being sent.  If the parameter is missing, you could try appending it via 'setRequestPreCallback(...)'.  Here's a sample, but you'll have to modify it to match the your code:

// APPEND TRAVEL MODE TO SERVICE AREA REQUEST //
esriRequest.setRequestPreCallback((ioArgs) => {
  if((ioArgs.url.search(/solveServiceArea/ig) > -1) && (this.currentTravelModeInfo != null)) {
    ioArgs.content.travelMode = this.currentTravelModeInfo.TravelMode;
  }
  return ioArgs;
});
0 Kudos
CoryDudart
Deactivated User

I'm using version 4.3 for the JS API.

And it definitely looks like it is removing the travelmode when it sends like you suggested. I'm just having a bit of issues implementing what you wanted me to try.

function travelModeCallback(ioArgs){
    if((ioArgs.url.search(/solveServiceArea/ig) > -1) && (this.currentTravelModeInfo != null)) {
        ioArgs.content.travelMode = this.currentTravelModeInfo.TravelMode;
    }
    return ioArgs;
}

esriRequest.setRequestPreCallback(travelModeCallback());

This is what i have right now, I just cant figure out what the ioArgs actually is to pass it to the function.

I found a few things from the 3.2 documentation saying its a dojo object but they all return undefined.

0 Kudos
CoryDudart
Deactivated User

Actually I got this working but it didn't send the travel mode still, its not in the request url.

0 Kudos
JohnGrayson
Esri Regular Contributor

The ioArgs is passed to your function by setRequestPreCallback, so don't call your function, just reference it:

esriRequest.setRequestPreCallback(travelModeCallback);

- I would suggest you log an issue Tech Support so it's in the system and the dev team can take a look at this.

0 Kudos
CoryDudart
Deactivated User

Actually with a bit of tinkering i got it to work and its actually using trucking routes now. I'll post my solution below  for that function.

Thanks for the Help!

function travelModeCallback(ioArgs){
    if((ioArgs.url.search('/solve') > -1)) {
        ioArgs.content.travelMode = JSON.stringify(routeParams.travelMode);
    }
    return ioArgs;
}
esriRequest.setRequestPreCallback(travelModeCallback);