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
Solved! Go to Solution.
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
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
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
Although my issue is solved, I'd still like to point out that I see two problems in the JS API here:
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?
Rene Rubalcava no opinion, or did I link the wrong profile of yours?
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!
Thanks Rene!