How to call analysis services using AnalysisBase

1730
5
Jump to solution
10-21-2013 04:59 AM
NilsRydh
New Contributor
I am trying to call the FindNearest service from the ArcGIS Online analysis services.
I don't want to use the builtin user interface, so I found the AnalysisBase class in the API docs, and it seems to let me do analysis with custom interface:
This dijit does not provide a user interface, but can be used to build analysis apps with customized user interface.

My question is:
How do I use the AnalysisBase class? I've tried a few things, but can't make it work.

Thanks,
Nils
0 Kudos
1 Solution

Accepted Solutions
JanelYang
New Contributor III
Nils,

We are working on the documentation of this class and will provide more information soon. You may take a look at this code sample:
require([   "esri/config", "esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate", "dojo/ready", "dojo/parser", "dijit/_WidgetBase", "esri/dijit/analysis/AnalysisBase", "dojo/_base/declare", ], function(esriConfig, Map, FeatureLayer, InfoTemplate, ready, parser, _WidgetBase, AnalysisBase, declare){   ready(function(){     parser.parse();     esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";          var map = new Map("map", {       basemap: "oceans",       center: [-100, 40],       zoom: 4     });     var myCustomWidget = declare([_WidgetBase, AnalysisBase], {});     var analysisBase = new myCustomWidget({       toolName: "FindHotSpots",       portalUrl: "http://www.arcgis.com",       resultParameter: "HotSpotsResultLayer"     });          map.on("load", function(){       var params = {         jobParams: {           AnalysisLayer: "{\"url\":\"http://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/USA_National_Parks_Plus/FeatureServer/0\"}",           context: JSON.stringify({extent: map.extent.toJson()}),           returnFeatureCollection: true         }       };       analysisBase.execute(params);       analysisBase.on("job-result", parseResult);     });      function parseResult(result){       console.log(result);       var featureLayer = new FeatureLayer(result.value.url || result.value, {         outFields: ['*'],         infoTemplate: new InfoTemplate()       });       map.addLayer(featureLayer);     };   }); });


You may notice that we wrapped AnalysisBase in a customized widget. This is a workaround to deal with a bug in our API. This bug will be fixed at v3.8, and you will be able to new AnalysisBase({ ... }); to create the class instance then.

View solution in original post

0 Kudos
5 Replies
JanelYang
New Contributor III
Nils,

We are working on the documentation of this class and will provide more information soon. You may take a look at this code sample:
require([   "esri/config", "esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate", "dojo/ready", "dojo/parser", "dijit/_WidgetBase", "esri/dijit/analysis/AnalysisBase", "dojo/_base/declare", ], function(esriConfig, Map, FeatureLayer, InfoTemplate, ready, parser, _WidgetBase, AnalysisBase, declare){   ready(function(){     parser.parse();     esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";          var map = new Map("map", {       basemap: "oceans",       center: [-100, 40],       zoom: 4     });     var myCustomWidget = declare([_WidgetBase, AnalysisBase], {});     var analysisBase = new myCustomWidget({       toolName: "FindHotSpots",       portalUrl: "http://www.arcgis.com",       resultParameter: "HotSpotsResultLayer"     });          map.on("load", function(){       var params = {         jobParams: {           AnalysisLayer: "{\"url\":\"http://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/USA_National_Parks_Plus/FeatureServer/0\"}",           context: JSON.stringify({extent: map.extent.toJson()}),           returnFeatureCollection: true         }       };       analysisBase.execute(params);       analysisBase.on("job-result", parseResult);     });      function parseResult(result){       console.log(result);       var featureLayer = new FeatureLayer(result.value.url || result.value, {         outFields: ['*'],         infoTemplate: new InfoTemplate()       });       map.addLayer(featureLayer);     };   }); });


You may notice that we wrapped AnalysisBase in a customized widget. This is a workaround to deal with a bug in our API. This bug will be fixed at v3.8, and you will be able to new AnalysisBase({ ... }); to create the class instance then.
0 Kudos
NilsRydh
New Contributor
Thanks Jerome,

That snippet solved my problem.
I wanted to use a FeatureSet as input AnalysisLayer, and it took me a while to figure out the correct structure of that. Seems like it was the missing OBJECTID field that was causing me trouble.

My only headache now, is that the response time for a simple FindNearest analysis is 17 seconds...

/Nils
0 Kudos
deleted-user-VeZur_n9o0OZ
New Contributor III
Nils/Jerome,

Can you provide a code snippet? I'm trying to use FindNearest. I can submit my task but the job fails with:

ERROR 000735: analysisLayer: Value is required arcgis.js:62
ERROR 000735: nearLayer: Value is required arcgis.js:62
Failed.

I've tried a few different structures for the params JSON  object with no success.

 var gp = new Geoprocessor("http://analysis.arcgis.com/arcgis/rest/services/tasks/GPServer/FindNearest");
            var _params = {
                "analysisLayer": {
                    "url": "https://services1.arcgis.com/fcrLbZIfZI20fNqr/arcgis/rest/services/rig_subset_4326/FeatureServer/0"
                    //"url": "http://10.4.164.20:6080/arcgis/rest/services/RigPlanner/RigPlanner_server/MapServer/0"
                    //"filter" : "filter"
                },
                "NearLayer": {
                    "layerDefinition": {
                        "geometryType": "esriGeometryPoint",
                        "fields": [
                            {
                                "name": "Id",
                                "type": "esriFieldTypeOID",
                                "alias": "Id"
                            }
                        ]},
                    "featureSet": {
                        "geometryType": "esriGeometryPoint",
                        "spatialReference": {
                            "wkid": 4326
                        },
                        "features": [
                            {
                                "geometry": {
                                    "x": -94.00,
                                    "y": 28.00
                                },
                                "attributes": {
                                    "Id": 1
                                }
                            }
                        ]}
                },
                "maxCount": 10,
                "measurementType": "StraightLine",
                //"searchCutoff": 44,
                //"searchCutoffUnits": "Kilometers"
                "f": "json"
            }
            gp.submitJob(_params, completeCallback, statusCallback, errorCallback);



Thanks,
James
0 Kudos
NilsRydh
New Contributor
Hi James,
I have a little sample on github that is working:
https://github.com/pilsna/arcgis-web-demo/blob/master/nearestbar/js/basic.js
I've used the Esri boilerplate template as a starting point. I don't think I can share the ready application across organizations, but hopefully this will get you a bit further.

/Nils
0 Kudos
deleted-user-VeZur_n9o0OZ
New Contributor III
Thanks Nils. We went about it slightly differently but your example was really useful

My fix:
http://forums.arcgis.com/threads/103931-How-to-use-a-Spatial-Analysis-Service-FindNearest-with-JS-ap...
0 Kudos