Select to view content in your preferred language

routetask_closest_facility sample code doesn't work

2075
1
03-10-2016 08:46 PM
karldailey
Deactivated User


I'm working with the javascript api and trying to recreate the sample code for route task / closest facility : Find closest facilities | ArcGIS API for JavaScript

It seems to work on your site, but when I copy the code and run it on my side it doesnt work.  When I double click on the file I get: Failed to load resource: net::ERR_FILE_NOT_FOUND dojo.io.script error Error(…)

When I run it from a web service such as this:

Closest Facilities

I get:

GET http://musa505.com/sproxy/?https://route.arcgis.com/arcgis/rest/services/Wo…ts%22%3Atrue%7D&callback... 404 (Not Found)g._attach @ init.js:1241g @ init.js:1239a.get @ init.js:1669v @ init.js:1045d @ init.js:1049x @ init.js:1055a.solve @ ClosestFacilityTask.js:5v.addCallbacks.g @ init.js:824c @ init.js:66A.then.then @ init.js:68addCallbacks @ init.js:68c.(anonymous function) @ init.js:824mapClickHandler @ routetask_closest_facility.html:187(anonymous function) @ init.js:1353g.(anonymous function).h @ init.js:234m._fire @ init.js:956m._fireClickEvent @ init.js:962(anonymous function) @ init.js:167setTimeout (async)m._onClickHandler @ init.js:961(anonymous function) @ init.js:167

init.js:1672 dojo.io.script error Error(…)

Whats wrong with the sample code?

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Karl,

This sample is setup to use a proxy to provide the credentials for the routing task (the routing service consumes credits and thus you have to have a proxy configured if you do not want the user challenged for AGOL credentials). You will see in the code that the sample is looking for the proxy to be in the web pages sproxy folder and your copy does not have this.

 uaddProxyRule({
        urlPrefix: "route.arcgis.com", 
        proxyUrl: "/sproxy/"
      });

You either have to comment out the above section in your code and then it will prompt the user to login to your org or AGOL or you need to setup and configure a proxy for your page.