Editor Widget -  Where is the returned feature set?

2586
4
Jump to solution
10-07-2013 06:56 AM
ionarawilson1
Occasional Contributor III
I am calling a geoprocessing service in a web app. The geoprocessing service has one parameter (a feature set). But I am not sure how to find the parameter in the javascript code to send it to the geoprocessing since I am using an editor widget to first create the polygon and then run the geoprocessing service. Can you guys take a look at my code and tell me how I reference a feature set from the editor widget results? Thank you!

      dojo.require("esri.tasks.query");           var map;              require([         "esri/map", "esri/dijit/BasemapGallery", "esri/arcgis/utils",          "esri/toolbars/edit",             "esri/layers/ArcGISTiledMapServiceLayer",         "esri/layers/FeatureLayer",   "esri/tasks/query", "esri/tasks/QueryTask",         "esri/symbols/SimpleMarkerSymbol",         "esri/symbols/SimpleLineSymbol",          "esri/dijit/editing/Editor",            "esri/dijit/editing/TemplatePicker",         "esri/config",         "dojo/i18n!esri/nls/jsapi",            "dojo/_base/array", "dojo/parser", "dojo/keys",          "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/TitlePane",            "dojo/dom", "dojo/on",          "dojo/domReady!",         ], function(         Map, BasemapGallery, arcgisUtils, Edit,          ArcGISTiledMapServiceLayer, FeatureLayer,   Query, QueryTask,         SimpleMarkerSymbol, SimpleLineSymbol,          Editor, TemplatePicker,          esriConfig, jsapiBundle,         arrayUtils, parser, keys,        borderContainer, contentPane, titlePane,         dom, on       ) {         parser.parse();                 // snapping is enabled for this sample - change the tooltip to reflect this         jsapiBundle.toolbars.draw.start = jsapiBundle.toolbars.draw.start +  "<br>Press <b>ALT</b> to enable snapping";                 // refer to "Using the Proxy Page" for more information:  https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html         esriConfig.defaults.io.proxyUrl = "/proxy";                    esriConfig.defaults.geometryService = new esri.tasks.GeometryService("http://tfsgis-iisd01:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");                  map = new Map("map", {            basemap: "hybrid",                     center: [-98.57, 30.98],           zoom: 6,           slider: true          });      map.on("layers-add-result", initEditor);            var ActivityArea = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/1",{           mode: FeatureLayer.MODE_ONDEMAND,            outFields: ['*']         });          var ActivityPoint = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/0",{           mode: FeatureLayer.MODE_ONDEMAND,            outFields: ['*']         });          var stewardship = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/2",{           mode: FeatureLayer.MODE_ONDEMAND,            outFields: ['*']         });          map.addLayers([ActivityArea,ActivityPoint,stewardship]);                             function initEditor(evt) {             var templateLayers = arrayUtils.map(evt.layers, function(result){             return result.layer;               });           var templatePicker = new TemplatePicker({             featureLayers: templateLayers,             grouping: true,             rows: "auto",             columns: 3           }, "templateDiv");           templatePicker.startup();            var layers = arrayUtils.map(evt.layers, function(result) {             return { featureLayer: result.layer };           });           var settings = {             map: map,             templatePicker: templatePicker,             layerInfos: layers,             toolbarVisible: true,             createOptions: {               polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],               polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,                 Editor.CREATE_TOOL_CIRCLE,                 Editor.CREATE_TOOL_TRIANGLE,                 Editor.CREATE_TOOL_RECTANGLE               ]             },             toolbarOptions: {               reshapeVisible: true             }                   };                   var params = {settings: settings};               var myEditor = new Editor(params,'editorDiv');           //define snapping options           var symbol = new SimpleMarkerSymbol(             SimpleMarkerSymbol.STYLE_CROSS,              15,              new SimpleLineSymbol(               SimpleLineSymbol.STYLE_SOLID,                new Color([255, 0, 0, 0.5]),                5             ),              null           );           map.enableSnapping({             snapPointSymbol: symbol,             tolerance: 20,             snapKey: keys.ALT           });                myEditor.startup();                          }             //add the basemap gallery, in this case we'll display maps from ArcGIS.com including bing maps         var basemapGallery = new BasemapGallery({           showArcGISBasemaps: true,           map: map         }, "basemapGallery");         basemapGallery.startup();                  basemapGallery.on("error", function(msg) {           console.log("basemap gallery error:  ", msg);         });      var queryTask, query;   queryTask = new QueryTask("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/2");          query = new Query();         query.returnGeometry = false;   //query.geometry = map.extent;    query.outFields = ["*"];        query.where = "1=1" ;                   queryTask.executeForCount(query,function(count){                  dom.byId("info").innerHTML = count             });           //     on(dom.byId("button"),"click", function() { //         gp = new esri.tasks.Geoprocessor("http://tfsgis-iisd01:6080/arcgis/rest/services/CalcFeaturesStewardshipOneParameter3/GPServer/CalcFeaturesStewardshipOneParameter") //   gp.outSpatialReference = map.spatialReference //  //  //   //  var features= []; //     //       var layer=map.getLayer("stewardship") //   var featureSet = new esri.tasks.FeatureSet(); //  featureSet.features = layer.graphics; //  featureSet.fields = layer.fields; //  featureSet.geometryType = layer.geometryType; //  var params = {Stewardship:featureSet} //  //    gp.submitJob(params, completeCallback , statusCallback) //       // //   //        }); //   //  function completeCallback(jobInfo){ //        //      } //    //      function statusCallback(jobInfo) { //        var status = jobInfo.jobStatus; //        if(status === "esriJobFailed"){ //          alert(status); //          //        } //        else if (status === "esriJobSucceeded"){ //          alert(status); //        } //      }              });// end require
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Occasional Contributor III
this worked for me: (stewardship is the id of the feature layer)

var featureSet = new esri.tasks.FeatureSet();         var layer=map.getLayer("stewardship")        featureSet.features = layer.graphics;      featureSet.fields=layer.fields;          featureSet.spatialReference = map.spatialReference;             spatial = featureSet.spatialReference      featureSet.geometryType=layer.geometryType;     geometry = featureSet.geometryType     var count = featureSet.features.length;    alert(count)    alert(geometry)    alert(spatial)         var params = {"Stewardship":featureSet}     gp.submitJob(params, completeCallback , statusCallback)              });      function completeCallback(jobInfo){         console.log("testing")  

View solution in original post

0 Kudos
4 Replies
ionarawilson1
Occasional Contributor III
Can anybody tell me why this does not work?

  

      ], function(
        Map, BasemapGallery, arcgisUtils, Edit, 
        ArcGISTiledMapServiceLayer, FeatureLayer,
  Query, QueryTask,
        SimpleMarkerSymbol, SimpleLineSymbol, 
        Editor, TemplatePicker, 
        esriConfig, jsapiBundle,
        arrayUtils, parser, keys,  
  
  borderContainer, contentPane, titlePane,
        dom, on
      ) {
        parser.parse();       

        // snapping is enabled for this sample - change the tooltip to reflect this
        jsapiBundle.toolbars.draw.start = jsapiBundle.toolbars.draw.start +  "<br>Press <b>ALT</b> to enable snapping";
       
        // refer to "Using the Proxy Page" for more information:  https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
        esriConfig.defaults.io.proxyUrl = "/proxy";    

     
        esriConfig.defaults.geometryService = new esri.tasks.GeometryService("http://tfsgis-iisd01:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
        
        map = new Map("map", { 
          basemap: "hybrid",
         
          center: [-98.57, 30.98],
          zoom: 6,
          slider: true 
        });
  
  map.on("layers-add-result", initEditor);
 

        var ActivityArea = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/1",{
          mode: FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });

        var ActivityPoint = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/0",{
          mode: FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });

        var stewardship = new FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/MyMapService2/FeatureServer/2",{
          mode: FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });

        map.addLayers([ActivityArea,ActivityPoint,stewardship]);
  
          
  
  
        function initEditor(evt) {
 
          var templateLayers = arrayUtils.map(evt.layers, function(result){
            return result.layer;
   
          });
        

          var templatePicker = new TemplatePicker({
            featureLayers: templateLayers,
            grouping: true,
            rows: "auto",
            columns: 3
          }, "templateDiv");
          templatePicker.startup();

          var layers = arrayUtils.map(evt.layers, function(result) {
            return { featureLayer: result.layer };
          });
 
          var settings = {
            map: map,
            templatePicker: templatePicker,
            layerInfos: layers,
            toolbarVisible: true,
            createOptions: {
              polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],
              polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,
                Editor.CREATE_TOOL_CIRCLE,
                Editor.CREATE_TOOL_TRIANGLE,
                Editor.CREATE_TOOL_RECTANGLE
              ]
            },
            toolbarOptions: {
              reshapeVisible: true
            }
   
   
          };


   


          var params = {settings: settings};    
          var myEditor = new Editor(params,'editorDiv');
          //define snapping options
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CROSS, 
            15, 
            new SimpleLineSymbol(
              SimpleLineSymbol.STYLE_SOLID, 
              new Color([255, 0, 0, 0.5]), 
              5
            ), 
            null
          );
          map.enableSnapping({
            snapPointSymbol: symbol,
            tolerance: 20,
            snapKey: keys.ALT
          });
    
          myEditor.startup();
    
    
      
        }
 

  
     on(dom.byId("button"),"click", function() {
        gp = new esri.tasks.Geoprocessor("http://tfsgis-iisd01:6080/arcgis/rest/services/CalcFeaturesStewardshipOneParameter3/GPServer/CalcFeaturesStewardshipOneParameter")
  //gp.outSpatialReference = map.spatialReference

  
  var features= [];

        var selectGraphics = featureLayer.getSelectedFeatures();

        features.push(selectGraphics);
   var featureSet = new esri.tasks.FeatureSet();
  
  featureSet.features = features;


  var params = {Stewardship:featureSet}
 
  gp.submitJob(params, completeCallback , statusCallback)


  
        });
  
  function completeCallback(jobInfo){
       
      }
   
      function statusCallback(jobInfo) {
        var status = jobInfo.jobStatus;
        if(status === "esriJobFailed"){
          alert(status);
         
        }
        else if (status === "esriJobSucceeded"){
          alert(status);
        }
      }

0 Kudos
ionarawilson1
Occasional Contributor III
At least now I am getting a job failed error.Can anybody take a look and tell me what is missing for the job to succeed? Thank you!

  on(dom.byId("button"),"click", function() {
        gp = new esri.tasks.Geoprocessor("http://tfsgis-iisd01:6080/arcgis/rest/services/CalcFeaturesStewardshipOneParameter3/GPServer/CalcFeaturesStewardshipOneParameter")
  //gp.outSpatialReference = map.spatialReference

  
  var features= [];

        var selectedFeatures = stewardship.getSelectedFeatures();
     
    

   var featureSet = new esri.tasks.FeatureSet();
  
  featureSet.features = selectedFeatures;
 
  featureSet.fields = selectedFeatures.fields
  var params = {Stewardship:featureSet}
 
  gp.submitJob(params, completeCallback , statusCallback)


  
        });
  
  function completeCallback(jobInfo){
        console.log("getting data");
    alert("TEST")
      }
   
      function statusCallback(jobInfo) {
        var status = jobInfo.jobStatus;
        if(status === "esriJobFailed"){
          alert(status);
         
        }
        else if (status === "esriJobSucceeded"){
          alert(status);
        }
      }
0 Kudos
ionarawilson1
Occasional Contributor III
this worked for me: (stewardship is the id of the feature layer)

var featureSet = new esri.tasks.FeatureSet();         var layer=map.getLayer("stewardship")        featureSet.features = layer.graphics;      featureSet.fields=layer.fields;          featureSet.spatialReference = map.spatialReference;             spatial = featureSet.spatialReference      featureSet.geometryType=layer.geometryType;     geometry = featureSet.geometryType     var count = featureSet.features.length;    alert(count)    alert(geometry)    alert(spatial)         var params = {"Stewardship":featureSet}     gp.submitJob(params, completeCallback , statusCallback)              });      function completeCallback(jobInfo){         console.log("testing")  
0 Kudos
JssrRR
by
Occasional Contributor II

Ionara,

I noticed that you have commented out this line in your code, why was that, do we not need this or did you have to republish your GP task again with the map's SpatialReference

//gp.outSpatialReference = map.spatialReference,

Thanks

0 Kudos