What's the URL to the analysis service

3922
5
05-06-2016 05:17 AM
LeoDeng
Occasional Contributor II

I want to use the PlanRoutes API (https://developers.arcgis.com/javascript/3/jsapi/planroutes-amd.html), but I don't know what's the analysisGpServer property should be set. At this moment, I only have a trial account applied from esri.com and there's no local server for me.

My version of arcgis js api is 3.16.

5 Replies
PanagiotisPapadopoulos
Esri Regular Contributor

Hi Leo,

You can use the GP Service from ArcGIS Online

http://analysis1.arcgis.com/arcgis/rest/services/tasks/GPServer/PlanRoutes

but this require organization account.

In order to access the Analysis service from your custom application use proxy page (Using the proxy | Guide | ArcGIS API for JavaScript )

in order to understand how PlanRoute is working use the Analysis tool Plan Routes from ArcGIS Online

Capture.PNG

execute task and inspect the submitJob

Capture.PNG

LeoDeng
Occasional Contributor II

Hi,Panagiotis:

   Thank you for your reply!

 

   The attach is my scripts. My goal is to execute PlanRoutes Analysis using javascript API. At this moment, I got the error: 1) You do not have permissions to use this resource. 2) Token Required.

 

   And my proxy.config has set the serverUrl of http://js.arcgis.com with my clientId and clientSecret got from arcgis online for trail user.

 

   How to do it next?

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

Hi Leo,

General the token and analysis url parameters are more complex on this case to be retrieved.

you have to follow the steps here:

Programmatically accessing analysis services—ArcGIS REST API: Spatial Analysis Service | ArcGIS for ...

in order to take the token and the analysis url for the PlanRoute task.

then see here for more details about the PlanRoute task

Plan Routes—ArcGIS REST API: Spatial Analysis Service | ArcGIS for Developers

In your case now at the beginning add this :

esriConfig.defaults.io.corsEnabledServers.push("analysis1.arcgis.com");

esriConfig.defaults.io.corsEnabledServers.push("www.arcgis.com");

 

urlUtils.addProxyRule({

  urlPrefix: "https://analysis1.arcgis.com",

  proxyUrl: "http://<machine>/proxy/proxy.ashx"

});

later on your code when you set the analysis service url:

.....

  analysisTools = new PlanRoutes({

              // startLayer: "",

              // endLayer: "",

              analysisGpServer: "https://analysis1.arcgis.com/arcgis/rest/services/tasks/GPServer/PlanRoutes/submitJob",

              portalUrl: "http://www.arcgis.com/",

              FeatureLayers: [schoolLayer, stopLayer],

              returnToStart: false,

              showChooseExtent: false,

.........

on the proxy page I am using the following:

<serverUrl url="https://analysis1.arcgis.com/arcgis/rest/services"

    accessToken="xxxxxxxxxxxxxxxx"

    matchAll="true"/>

in order to retrieve the token for your portal use this url

https://www.arcgis.com/sharing/generateToken?f=json&request=gettoken&username=<username>&password=<p...

but you also can use the clientId and the clientSecret in order to generate the token.

by doing that the PlanRoutes submit request is working

Capture.PNG

after that see the PlanRoutes settings Plan Routes—ArcGIS REST API: Spatial Analysis Service | ArcGIS for Developers  in order to make it return results

Capture.PNG

LeoDeng
Occasional Contributor II

Hi,Panagiotis:

  I've followed your suggestion and the response of http://localhost/proxy/DotNet/proxy.ashx?https://analysis1.arcgis.com/arcgis/rest/services/tasks/GPS... returns {"jobId":"jb787c736ed0e4c3a8f5d435a10b6a456","jobStatus":"esriJobSubmitted","results":{},"inputs":{},"messages":[]}.

  However, when I calling the javascript api of PlanRoutes (https://developers.arcgis.com/javascript/3/jsapi/planroutes-amd.html), the console got the error of "dojo.io.script error Error: Token Required".

20160510-1035.png

The attachement is my html, and the proxy.config has set the urls used.

  <serverUrl url="https://analysis1.arcgis.com/arcgis/rest/info"
    accessToken = "XXXXXXXXXX"
    matchAll="true"/>

  <serverUrl url="https://analysis1.arcgis.com/arcgis/rest/services/tasks/GPServer"
    accessToken = "XXXXXXXXXX"
    matchAll = "true" />

  <serverUrl url="http://js.arcgis.com"
  accessToken = "XXXXXXXXXX"
    matchAll = "true" />

Panagiotis Papadopoulos

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

Hi Leo,

from the image I can see that the token error arise for the logistics.arcgis.com url and not for the analysis1.arcgis.com.

Maybe the PlanRoutes using more than one analysis services.

Try to set on the proxy page this url also.