Common_ExtendTasks_VBNet\App_Code\ExtendGPTask.vb
' Copyright 2011 ESRI ' ' All rights reserved under the copyright laws of the United States ' and applicable international laws, treaties, and conventions. ' ' You may freely redistribute and use this sample code, with or ' without modification, provided you include the original copyright ' notice and use restrictions. ' ' See the use restrictions. ' Imports Microsoft.VisualBasic Imports System Namespace ExtendedTasks Public Class ExtendGPTask Inherits ESRI.ArcGIS.ADF.Tasks.GeoprocessingTask #Region "Instance Variable Declarations" Private m_taskResults As ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults = Nothing #End Region #Region "GeoprocessingTask Overrides" Public Overrides Function GetCallbackResult() As String ' Call the base task's GetCallbackResult method so the base task logic is executed MyBase.GetCallbackResult() For Each commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality In TaskResultsInstance.MapInstance.GetFunctionalities() ' Check whether the current resource contains the task's point results If (commonMapFunctionality.Resource.Name = TaskResultsInstance.ClientID & " Point Results") Then ' Get a reference to the resource containing the results Dim commonMapResource As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource = CType(commonMapFunctionality.Resource, ESRI.ArcGIS.ADF.Web.DataSources.IMapResource) ' Change the transparency of the point results by altering the transparency of ' the Web ADF Map Resource Item. For GraphicsLayers rendered in the web tier ' (as GP Task Results are by default), this property acts as a transparency limit - ' GraphicsLayers can be more transparent than this, but not less. For ' GraphicsLayers rendered on the client, this setting has no effect commonMapResource.DisplaySettings.Transparency = 70 TaskResultsInstance.MapInstance.RefreshResource(commonMapResource.Name) ' Add the map's callback results to those of the base task, since we refreshed a ' map resource MyBase.CallbackResults.CopyFrom(TaskResultsInstance.MapInstance.CallbackResults) End If Next commonMapFunctionality Return MyBase.CallbackResults.ToString() End Function Public Overrides Sub ExecuteTask() MyBase.ExecuteTask() If TypeOf Results Is ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode Then ' Set the TaskResults' GraphicsTransparency to zero to allow client-side results to be rendered as ' completely opaque. When explicitly setting transparency on GraphicsLayers that are rendered ' client-side (as in SetPolygonNodeRenderers, below), this property acts as transparency limit - ' GraphicsLayers can be more transparent than this, but not less. For GraphicsLayers rendered in ' the web tier, this setting has no effect. Me.TaskResultsInstance.GraphicsTransparency = 0 Dim rootResultsTreeViewPlusNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode = CType(Results, ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode) SetPolygonNodeRenderers(rootResultsTreeViewPlusNode, True) End If End Sub #End Region #Region "Instance Properties and Methods" ' Convenient access to the first TaskResults control in the Task's TaskResultsContainers collection Private ReadOnly Property TaskResultsInstance() As ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults Get ' Retrieve the TaskResults control if it has not already been If (m_taskResults Is Nothing) AndAlso (Not TaskResultsContainers(0) Is Nothing) Then m_taskResults = TryCast(Utility.FindControl(TaskResultsContainers(0).Name, Page), ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults) End If Return m_taskResults End Get End Property Private Sub SetPolygonNodeRenderers(ByVal treeViewPlusNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode, ByVal recursive As Boolean) ' Only manipulate GraphicsLayerNodes If TypeOf treeViewPlusNode Is ESRI.ArcGIS.ADF.Web.UI.WebControls.GraphicsLayerNode Then ' Get a reference to the feature graphics layer corresponding to the node Dim graphicsLayerNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.GraphicsLayerNode = TryCast(treeViewPlusNode, ESRI.ArcGIS.ADF.Web.UI.WebControls.GraphicsLayerNode) Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer = TryCast(graphicsLayerNode.Layer, ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer) ' Task results have a selected renderer, but neither a highlight renderer nor a default renderer by ' default. Here we check to make sure this is the case, and that the graphics layer has a polygon ' geometry type - the code here only handles polygons. If (Not featureGraphicsLayer.SelectedRenderer Is Nothing) AndAlso (featureGraphicsLayer.HighlightRenderer Is Nothing) AndAlso (featureGraphicsLayer.Renderer Is Nothing) AndAlso (featureGraphicsLayer.FeatureType = ESRI.ArcGIS.ADF.Web.FeatureType.Polygon) Then ' Get the selected renderer Dim adfSelectedRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer = TryCast(featureGraphicsLayer.SelectedRenderer, ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer) ' Create a highlight renderer Dim adfHighlightFillSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol = TryCast(adfSelectedRenderer.Symbol.Clone(), ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol) adfHighlightFillSymbol.Color = System.Drawing.Color.Red adfHighlightFillSymbol.Transparency = 25 Dim adfHighlightRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer = New ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer(adfHighlightFillSymbol) featureGraphicsLayer.HighlightRenderer = adfHighlightRenderer ' Create a default renderer Dim adfDefaultFillSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol = TryCast(adfSelectedRenderer.Symbol.Clone(), ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol) adfDefaultFillSymbol.Color = System.Drawing.Color.Purple adfDefaultFillSymbol.Transparency = 25 Dim adfDefaultRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer = New ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer(adfDefaultFillSymbol) featureGraphicsLayer.Renderer = adfDefaultRenderer ' De-select each row in the graphics layer. Otherwise, the symbology specified by the selected ' renderer would be used For Each dataRow As System.Data.DataRow In featureGraphicsLayer.Rows If featureGraphicsLayer.IsSelected(dataRow) Then dataRow(featureGraphicsLayer.IsSelectedColumn) = False End If Next dataRow ' Specify that the layer be rendered on the client so the highlight symbology shows when polygon ' results are moused over, and that callouts are disabled so maptips do not appear featureGraphicsLayer.RenderOnClient = True featureGraphicsLayer.EnableCallout = False End If End If ' Set up renderers for child nodes if the function call specified recursion If recursive AndAlso (treeViewPlusNode.Nodes.Count > 0) Then For Each childTreeViewPlusNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode In treeViewPlusNode.Nodes SetPolygonNodeRenderers(childTreeViewPlusNode, True) Next childTreeViewPlusNode End If End Sub #End Region End Class End Namespace