How to add the "overrides" property to RouteParameters?

1675
6
Jump to solution
05-31-2017 08:44 AM
NiklasKöhn
Esri Contributor

Hi all, hi Rene Rubalcava‌, hi mcrowder-esristaff‌,

I'm using the Directions widget in JS API 3.x, and I'm setting some RouteParameters via

this.directions.on("directions-start", lang.hitch(this, function(evt) {
  this.directions.routeParams.impedanceAttribute = <...>;
  this.directions.routeParams.accumulateAttributes = <...>;  
  this.directions.routeParams.directionsTimeAttribute = <...>;  
}));

Those are working, I can see them being send in the GET request and they affect the results as expected.

Now here's the thing: There is a new parameter in the 10.5 NAServer REST interface called "overrides", which I need to set. This parameter doesn't exist on the JS object RouteParameters, and if I just add it to directions.routeParams, it won't go through to the request. (I've tried just assigning this.directions.routeParams.overrides, but I've also tried ES6's Object.assign in the Chrome dev console: The property is added to the routeParams object, but it's still not transferred to the request.)

Afaik, there is no later point for me to alter the request: The Directions widgets seems to implicitly call RouteTask.solve(routeParams), and there is no pre-solve event or anything on the RouteTask to intercept the call.

Btw, the same goes for the 4.x API - no "overrides" parameter on RouteParameters.

Testing via the plain REST API test form (NAServer/Route/solve), I can set the "overrides" parameter and it works.

Can someone help?
Thanks
Nik

1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor

Check out this other post as the solution might apply to this situation as well.  The solution involves modifying the request parameters before it's sent to the REST endpoint via the setRequestPreCallback() method (esri/request | API Reference | ArcGIS API for JavaScript 3.20 ) Related Post:RouteTask Travel Mode 

View solution in original post

6 Replies
JohnGrayson
Esri Regular Contributor

Check out this other post as the solution might apply to this situation as well.  The solution involves modifying the request parameters before it's sent to the REST endpoint via the setRequestPreCallback() method (esri/request | API Reference | ArcGIS API for JavaScript 3.20 ) Related Post:RouteTask Travel Mode 

NiklasKöhn
Esri Contributor

John,

thanks for the hint! I'm now just calling 

esriRequest.setRequestPreCallback(lang.hitch(this, this.setRouteParams));

while esriRequest is not an instantiated object, but the class itself. I had no idea that I can use esriRequest in that static manner (if that's what you call it in JS).

Thanks again!
Nik

#setRequestPreCallback

0 Kudos
NiklasKöhn
Esri Contributor

Although my issue is solved, I'd still like to point out that I see two problems in the JS API here:

  • The RouteParameters class is missing the "overrides" property. (also in JS API 4.x)
  • Some of the RouteParameters can be set via directionsWidgetObject.routeParams and implicitly passed through to RouteTask.solve(). But the selection of properties that is exposed here seems pretty odd to me: While some important ones are missing (in fact, most of the RouteParameters properties are missing), I can totally bamboozle the Directions widget by misusing some of the properties provided. Just add this to the simple Directions sample after instantiating Directions:
    directions.on("directions-start", function() {
     directions.routeParams.returnDirections = false;
     directions.routeParams.returnRoutes = true;
     });
    Because the route summary is taken from the directions header, there will be no summary with these settings. If you also set returnRoutes=false, you'll get an "route cannot be calculated" error.

I would consider this a bug or at least awkward design. Rene Rubalcava‌, what do you think?

NiklasKöhn
Esri Contributor

Rene Rubalcava‌ no opinion, or did I link the wrong profile of yours?

0 Kudos
ReneRubalcava
Frequent Contributor

One of those was right, ha.

Looking at recent activity, I think the overrides property will be in 3.21. Not sure on 4x as there's lots of development currently happening around those modules, but we'll check.

As far as the design of what properties are passed to the REST API, I'm not too familiar with routing, but we'll look into it. Sometimes it's compatibility, but I couldn't say for sure.

Thanks!

NiklasKöhn
Esri Contributor

Thanks Rene!

0 Kudos