I'm new to JavaScript and using geoprocessing services, so maybe this is simple syntax mistake, but I've spent numerous days trying to figure it out and I'm completely stuck. I???m having problems getting the result of our geoprocessing service to display in our web application. The service is a simple select by attributes task that outputs a polygon feature (inputs are a choice list of feature classes, and an SQL statement). I???ve been able to return the polygon geometry as a graphic (which I know from console log statements) but when I try to add the graphic to the map nothing happens. Does anyone have any ideas? They would be much appreciated!! require(["dojo/dom",
"dojo/_base/array",
"dojo/parser",
"dijit/registry",
"esri/domUtils",
"esri/map",
"esri/graphic",
"esri/layers/GraphicsLayer",
"esri/layers/FeatureLayer",
"esri/tasks/Geoprocessor",
"esri/tasks/FeatureSet",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane"],
function(dom, array, locale, parser, registry,
domUtils, Map, Graphic, GraphicsLayer, FeatureLayer, Geoprocessor, FeatureSet){
var gpServiceUrl= "http://<server>/arcgis/rest/services/Pipelines/ExportHazardCatchment/GPServer/Select";
parser.parse();
var map = new Map("map",{
basemap: "streets",
center: [-122.81, 45.466],
zoom: 8
});
//Run the gp task
var gp = new Geoprocessor(gpServiceUrl);
gp.setOutSpatialReference({wkid:102001});
function selectCatchment(){
var client = dom.byId('clientList').value;
console.log(client);
var params = {"input_features": client,
"output_feature_class": JSON,
"where_clause": buildDefinitionQuery()
};
gp.submitJob(params, gpJobComplete, gpJobStatus, gpJobFailed);
}
function gpJobComplete(jobInfo) {
console.log("in JobComplete");
var status = jobInfo.jobStatus;
if (status === "esriJobSucceeded"){
console.log("success, jobId:" + jobInfo.jobId);
var results = gp.getResultData(jobInfo.jobId, "out_feature_class", onTaskResultComplete);
console.log("past getResultsData");
console.log(results);
}
}
function onTaskResultComplete(paramResult) {
// Retrieve the value of the parameter from the paramresult
var featureSet = paramResult.value;
console.log(featureSet);
// Create a symbol based on the geometry.
var simplePolySymbol = new esri.symbol.SimpleFillSymbol();
simplePolySymbol.setOutline(new esri.symbol.SimpleLineSymbol(
esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([0,0,0,0.5]), 1));
simplePolySymbol.setColor(new dojo.Color([255,0,0,0.7]));
var gra = new Graphic(featureSet);
console.log(gra);
map.graphics.add(gra);
}
function gpJobStatus(jobInfo){
console.log(jobInfo.jobStatus);
}
function gpJobFailed(error){
console.log("Error");
alert("Error:"+ error);
}
function buildDefinitionQuery(){
var defQuery;
//get input info from form and build definition expression
var hazardIDs = dojo.byId('query').value;
defQuery = "\"HazardID\"=" + hazardIDs;
console.log(defQuery);
return defQuery;
}
app = {
selectCatchment: selectCatchment
};
return app;
});
Here is a screen shot of the page from our gp task:[ATTACH=CONFIG]33661[/ATTACH]