gp.getResultImageLayer(jobInfo.jobId,"final_shp", imageParams, function(gpLayer) { map.addLayer(gpLayer); });
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" /> <title>GP Viewshed Task</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/dojo/dijit/themes/claro/claro.css"> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" /> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2compact"></script> <script type="text/javascript"> dojo.require("esri.map"); dojo.require("esri.tasks.gp"); dojo.require("esri.layers.FeatureLayer"); dojo.require("esri.dijit.Popup"); dojo.require("dijit.TooltipDialog"); var map, gp, featureLayer, dialog; /*Initialize map, GP*/ function init() { var startExtent = new esri.geometry.Extent({ "xmin": -13644840.338547781, "ymin": 4529944.368315823, "xmax": -13614265.527233753, "ymax": 4552875.476801345, "spatialReference": { "wkid": 102100 } }); map = new esri.Map("mapDiv", { extent: startExtent }); var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"); map.addLayer(streetMap); //http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons (Drive Time Polygons) gp = new esri.tasks.Geoprocessor("http://webgis.arizona.edu/ArcGIS/rest/services/webGIS/Shock_Models/GPServer/Income_Log"); gp.setOutputSpatialReference({ wkid: 102100 }); dojo.connect(map, "onClick", computeViewShed); } function computeViewShed(evt) { map.graphics.clear(); if (map.graphicsLayerIds.length >= 1) { map.removeLayer(map.getLayer(map.graphicsLayerIds[0])); } var pointSymbol = new esri.symbol.SimpleMarkerSymbol(); pointSymbol.setSize(20); pointSymbol.setOutline(new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1)); pointSymbol.setColor(new dojo.Color([0, 0, 255, 0.25])); var graphic = new esri.Graphic(evt.mapPoint, pointSymbol); map.graphics.add(graphic); var features = []; features.push(graphic); var featureSet = new esri.tasks.FeatureSet(); featureSet.features = features; var params = { "Input_Feature_Layer": featureSet, "Expression": "50" }; //gp.execute(params, drawViewshed); gp.submitJob(params, completeCallback, statusCallback, function (error) { alert(error); //esri.hide(loading); }); } function completeCallback(jobInfo) { if (jobInfo.jobStatus !== "esriJobFailed") { //gp.getResultData(jobInfo.jobId,"Output_Polygons", downloadFile); var imageParams = new esri.layers.ImageParameters(); imageParams.imageSpatialReference = map.spatialReference; gp.getResultImageLayer(jobInfo.jobId, "final.shp", imageParams, function (gpLayer) { map.addLayer(gpLayer); }); } } function statusCallback(jobInfo) { var status = jobInfo.jobStatus; if (status === "esriJobFailed") { alert(status); //esri.hide(loading); } else if (status === "esriJobSucceeded") { console.log("Success"); //esri.hide(loading); } } dojo.addOnLoad(init); </script> </head> <body class="claro"> <div id="mapDiv" style="width:800px; height:600px; border:1px solid #000;"></div>Click on map to execute my GP Task.</body> </html>
Solved! Go to Solution.
Well I am happy for you!
If I have understand your question: see this sample http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jssamples/map_dialog.html
If I understand your question: yes, using result map service you return a image. It's rendered using map service and data in job folder but I don't see request rest passing from map server for get info on data.
(...If the GP service is associated with a result map service, the default output for GPRasterDataLayer and GPFeatureSetLayer parameters is a map image ...)
you have two solution:
you don't use result map service and you use only gp and render on client the output of gp
or
you use result map service but you must create a soe (server object extension) where you pass id of job and so you get on server your data (feature class, raster ect) and return on client the info that you need.
I have done a similar solution for a result map service yet set and so I don't want modify resutl map service (render complex) so I create a soe that from jobID (sent from client) I get feature class from server and serialize in json for js api esri.
If I understand your question: yes, using result map service you return a image. It's rendered using map service and data in job folder but I don't see request rest passing from map server for get info on data.
(...If the GP service is associated with a result map service, the default output for GPRasterDataLayer and GPFeatureSetLayer parameters is a map image ...)
you have two solution:
you don't use result map service and you use only gp and render on client the output of gp.
gp.getResultData(jobInfo.jobId,"final_shp", imageParams, addResults); function addResults(results) { console.log(results); var features = results.value.features; }
TypeError: results.value is undefined
gp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults); function addResults(results) { console.log(results); var features = results.value.features; // do render ... }
Ok, getResultData but you have a imageParams (old paste/cut) from remove ...
fix your code sogp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults); function addResults(results) { console.log(results); var features = results.value.features; // do render ... }
gp.getResultData(jobInfo.jobId,"final_shp", addResults, errResults); function addResults(results) { console.log(results); var features = results.value.features; } function errResults(err) { console.log(err); }
The problem is that you use a gp with set A map so result is a image and not a recordset so you need change your gp in tab parameters and in "The tools exposed by Geoprocessing Service are stored in":
select radio button A toolbox and select toolbox.