Using result map service in web applications

A geoprocessing service creates a result map service to provide visual representation of asynchronous geoprocessing task outputs. You can enable the result map service option when you have defined symbology to better understand the output data or if you have large dataset outputs that cannot be downloaded.

Learn more about result map servicesLearn more about enabling a result map service

You can add a result map service to web applications similar to how you add dynamic map services. A layer in a result map service corresponds to geodataset output of the geoprocessing task. When you add a result map service to web applications, all the output layers in the result map service will be added to the web application. However, if you wish to exclude some of the outputs, you can turn off the visibility of layers as needed. If there are any feature layers in a result map service, you can add them independently as client-side feature layers in web applications. The client-side feature layer will dynamically query the features and render them as graphics at the client. In the case of large dataset outputs, you can set the property of the client-side feature layer to dynamically download features for the current extent of the web application.

Using a result map service as a dynamic map service

A result map service can be accessed using the URL http://<arcgis rest services>/<GPServiceName>/MapServer/jobs/<jobId>. The jobId is the unique identifier assigned by the server for the asynchronous job. You can obtain the jobId from the JobInfo instance returned by the jobComplete event handler. The JavaScript code below shows:

  1. Connecting an event handler to the jobComplete event of an asynchronous geoprocessing task
  2. Determining a result map service URL from the jobId in the jobComplete event handler
  3. Adding a result map service as a dynamic map service to the web application

Using a result map service in JavaScript API

//connect eventhandlers and submitJob.
function myGPSubmitJob(){ 
    // Connect event handler onJobComplete 
    dojo.connect(gpTask, "onJobComplete",onTaskComplete);
    dojo.connect(gpTask, "onError",onTaskFailure);
    dojo.connect(gpTask, "onStatusUpdate",onTaskStatus);
    //params is assumed as a name-value pair instance of gpparameter values.
    gpTask.submitJob(params);
}

// On Job Complete Callback add a dynamic map service using ResultMapService
function onTaskComplete(jobInfo){
    //replace mapservice url with your url and append jobid
    var mapurl = "http://..../<MyGPServiceName>/MapServer/jobs/" + jobinfo.jobId;
    //create a dynamic map service
    var gpResultLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapurl, {
                id: "gpLayer",
                opacity: 0.5
            });
    //add to web application.
     map.addLayer(gpResultLayer);
}

The three steps to add a result map service to web applications is applicable to the Flex and Silverlight APIs as well. You can find Flex and Silverlight API code snippets in their respective online SDK.

You can learn more about defining task parameters and other event handlers in Using geoprocessing tasks in web applications.

Using the rresult map service layer as client-side feature layers

A geoprocessing task output parameter of data type GPFeatureRecordSetLayer will be rendered as a featurelayer in the result map service. You can add these layers as client-side feature layers. When the layers are added as client-side feature layers, the features are downloaded to the client. Using FeatureLayer methods, you can create interactive pop-up and info windows or you can create dynamic charts and graphs based on the attribute values. You can also access HTML pop-up windows and attachments, if available for these layers. The JavaScript code below shows how to add a feature layer to a web application.

Adding featureLayers to web applications

// On Job Complete Callback add a featurelayer using ResultMapService
function onTaskComplete(jobInfo){
    //replace mapservice url with your url and append jobid
    var mapurl = "http://..../<MyGPServiceName>/MapServer/jobs/" + jobinfo.jobId;
    //the code snippet assumes the featureLayer is the first layer in the result map service
    var fLayerUrl = mapurl + “/0”;
    
    //create a feature layer 
    //the MODE_ONDEMAND property allows the client to restrictively download features for current web app extent
    var featurelayer=new esri.layers.FeatureLayer(fLayerUrl, {
                id: "gpfLayer",
                mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
                outFields: ["*"]
            });
    map.addLayer(featurelayer);	

    
}

Again, the code snippet logic is applicable for the Flex and Silverlight APIs as well. You can learn more about creating pop-up and info windows, graphs, and charts in JavaScript, Flex, and Silverlight SDKs.

Related Topics

12/18/2014