Changing the transparency of GeoprocessingTask results in a Map

Rex Hansen contributed this discussion about working with results of the .Net Web ADF GeoprocessingTask programmatically:

An ArcGIS Server geoprocessing service can contain server tools which generate feature output (e.g. feature class, feature layer, etc.) to be rendered in a map.  The Web ADF includes an out-of-the-box GeoprocessingTask control which can be used to interact with a server tool as a geoprocessing resource in a Web ADF application.  

As part of the Web ADF Task framework, a GeoprocessingTask can interact with a server tool, display tabular results in a TaskResults control, and display feature results in a Map control.   When a server tool generates feature results, either the raw feature data can be returned to the client, or a map service buddied with the geoprocessing service can be used to draw the results on the server.  The GeoprocessingTask maintains the boolean property DrawResultsOnMapServer to determine where feature results are drawn.  

In either case, one or more map resources must be created at runtime to draw results in a Web ADF Map control.   Upon successful execution of a GeoprocessingTask, the map resources are added to a MapResourceManager through the Task-TaskResults-Map-MapResourceManager buddy relationship.

If results are drawn using a map service, one ArcGIS Server map resource item is created for each set of result features when a geoprocessing job completes successfully.  The results are packaged as map resources in MapResourceNodes (in ESRI.ArcGIS.ADF.Web.UI.WebControls) by the GeoprocessingTask for display within a TaskResults control.   The internal framework of the TaskResults control manages adding the resources for you and eventually displaying the results in a map.

If results are drawn by the client, results are converted to Web ADF feature graphics layers in the GeoprocessingTask.  Upon display in a TaskResults control, the feature graphics layers are packaged as GraphicsLayerNodes (in ESRI.ArcGIS.ADF.Web.UI.WebControls).   The TaskResults control will create Web ADF graphics map resource items to contain the graphics layers; one resource item for each feature type.  

For example, assume a GeoprocessingTask is buddied with a TaskResults control named “TaskResults1” and a job initiated by the task generates a polygon feature set.  When the job is complete, a Web ADF graphics layer created from the polygon feature set will be added to a graphics resource item named “TaskResults1 Polygon Results”.  The graphics layer associated with each GraphicsLayerNode will be added to the graphics map resource item based its feature type (e.g. Point, Line, Polygon).  If a graphics map resource is already available for a certain type, all graphics layers of the same type are merely added to it.  All GeoprocessingTasks which share the same TaskResult control will also share the same graphics map resources.   The internal framework of the TaskResults control manages displaying the graphics map resource for you.  

By default, the transparency setting for all map resources created for MapResourceNodes and GraphicsLayerNodes is 25 (25%).   In addition, by default the symbols for features in a feature graphics layer created by the GeoprocessingTask have a transparency value of 0 (0%).  Note that map resources and graphics layers are two different entities.  A Web ADF graphics map resource can contain many Web ADF graphics layers.   The transparency settings of a feature layer renderer will be coupled with transparency defined for a map resource as a whole.   The GeoprocessingTask does not maintain a public property to change the transparency of results.  Consequently, the GeoprocessingTask must be subclassed to interrogate and change the results generated by the task before they are rendered in a Map.

To borrow a phrase from The Narrator in the movie Fight Club, let’s create a “single-serving” task only for use within the Web application it resides.  The custom task will override the transparency of results generated by a GeoprocessingTask.  Note that the techniques introduced in this example can also be applied to other Web ADF tasks.

  1. Create a new Web application (C#). Add MapResourceManager, Map, and TaskResults
    controls to the page. Buddy up the Map-MapResourceManager and TaskResults-Map.
  2. Add a TaskManager and Menu control to the page. Buddy up the TaskManager-Menu
    control. This step is not essential, but makes it easier to reinitialize the
    task by clicking on a menu item at runtime.
  3. Add a GeoprocessingTask to the TaskManager and buddy it up with the TaskResults
    control. In this example we will modify the out of the box GeoprocessingTask,
    so it’s easiest to start with one in the page and replace the reference once we
    have the custom task built.
  4. Add a map resource and geoprocessing resource. The outputs from the
    geoprocessing resource should be in the same coordinate system as the map. At
    this point, the application should appear similar to the following:

    Layout in Visual Studio

  5. Create a new class file in the Web application’s App_Code folder. Name the file
    CustomGeoprocessingTask.cs. The next set of steps will discuss adding code to
    this file. See the sample included with this post to view the code.
  6. Create a class named CustomGeoprocessingTask that subclasses the
    ESRI.ArcGIS.ADF.Web.UI.WebControls.GeoprocessingTask class and wrap it in the
    namespace CustomTasks.

    namespace CustomTasks
    public class CustomGeoprocessingTask :
    { . . .

  7. Add a property to retrieve the first TaskResults control buddied to the custom
    task. This will require you to work with the TaskResultsContainers property of
    the task. In the sample, two internal methods are used to iterate through the
    controls in the page to locate the appropriate TaskResults control.
  8. Override the GetCallbackResults() method to work with results generated by the
    custom GeoprocessingTask. Call GetCallbackResults() in the base class first -
    this will generate a set of results based on user inputs. The Results property
    of the task will store the output results to be read by the TaskResults control
    and rendered by the Map control. The Results property will usually contain a
    set of TreeViewPlusNodes.

    If results are to be rendered by the client, GraphicsLayerNodes will contain Web
    ADF feature graphics layers with the output features. Change the transparency
    value of the selected renderer symbol associated with the feature graphics
    layer. Since the graphics layer is added to the map as part of a resource, find
    the dynamic Web ADF graphics map resource that contains the graphics layer and
    change the transparency of its display settings. Each feature graphics layer
    created as a result from a geoprocessing job is given a unique name.

    If results are rendered on the server, MapResourceNodes will reference dynamic
    map images generated on the server. Find the dynamic ArcGIS Server map resource
    generated to render the results and change the transparency of its display

  9. Once finished, compile the Web project. Then add the following reference to the
    top of the aspx page:

    <%@ Register Assembly="App_Code" Namespace="CustomTasks" TagPrefix="customTasks" %>
  10. In the aspx page, change the tag associated with the out-of-the-box GeoprocessingTask to reference the custom GeoprocessingTask.

    Change the open and close tags from:




As an example, the following screenshots illustrate the difference between the default transparency values associated with results from the GeoprocessingTask and a transparency value of 0 (not transparent) associated with a custom GeoprocessingTask. In this example, the results were drawn on the server.

Default transparency values:

Task results with default transparency value

Custom transparency value of 0:

Task result with custom transparency value of 0

Download the code

This entry was posted in Services and tagged , , , , . Bookmark the permalink.

Leave a Reply