Common Extend tasks
Common_ExtendTasks_VBNet\App_Code\ExtendFindAddressTask.vb
' Copyright 2010 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
Imports System.Web
Imports ESRI.ArcGIS.ADF.Tasks
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls
Imports ESRI.ArcGIS.ADF.Web.DataSources
Imports ESRI.ArcGIS.ADF.Web.Display.Graphics

Namespace ExtendedTasks
  Public Class ExtendFindAddressTask
    Inherits FindAddressTask
    Private m_taskResults As TaskResults = Nothing

    #Region "Instance Properties"

    ' 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

    #End Region

    #Region "FindAddressTask Overrides"

    ' Customizes the task results
    Public Overrides Sub ExecuteTask()
      ' Call the base task's ExcecuteTask function so that a default set of results is created
      MyBase.ExecuteTask()

      ' Results generated by the FindAddressTask are packaged in a Web ADF GraphicsDataSet
      If TypeOf Results Is GraphicsDataSet Then
        Dim resultsGraphicsDataSet As GraphicsDataSet = CType(Results, GraphicsDataSet)

        ' Only one table of match candidates is packaged as a FeatureGraphicsLayer and returned.
        Dim matchedResultsLayer As FeatureGraphicsLayer = CType(resultsGraphicsDataSet.Tables(0), FeatureGraphicsLayer)

        ' Define custom default renderer
        Dim newSimpleRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer = New ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer()

        Dim simpleMarkerSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol()
        simpleMarkerSymbol.Color = System.Drawing.Color.Red
        simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle
        simpleMarkerSymbol.Width = 12
        simpleMarkerSymbol.Transparency = 50

        newSimpleRenderer.Symbol = simpleMarkerSymbol

        ' The FindAddressTask base class generates a FeatureGraphicsLayer with a layer format.
        ' The layer format will be used to change the symbology and attributes displayed as results.
        Dim resultLayerFormat As LayerFormat = LayerFormat.GetDefault(matchedResultsLayer)

        ' If results are shown as map tips, client graphics are used to render results.  If not, Web-tier graphics
        ' are used.  Web-tier graphics are not interactive, thus the highlight renderer is not used.
        resultLayerFormat.Renderer = newSimpleRenderer
        ' Use the HighlightRenderer defined in the page markup.
        resultLayerFormat.HighlightRenderer = Me.HighlightRenderer

        ' Create a collection of fields to define those you want to alias and render visible in 
        ' task results and the map tips callout window.
        Dim fieldsCollection As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection()

        ' If specified, the field will be visible and its name will be aliased.  
        ' The first parameter is the actual field name.  The second parameter is the alias name.
        fieldsCollection.Add("Score", "SCORE")

        ' Iterate through the fields in the layer format and set properties. Assign alias names and visibility.
        For Each fieldInfo As FieldInfo In resultLayerFormat.Fields
          Dim fieldDisplayed As Boolean = False
          Dim i As Integer = 0
          Do While i < fieldsCollection.Keys.Count
            If fieldsCollection.GetKey(i) = fieldInfo.Name Then
              fieldInfo.Alias = fieldsCollection.GetValues(i)(0)
              fieldInfo.Visible = True
              fieldDisplayed = True
              Exit Do
            End If

            If (Not fieldDisplayed) Then
              fieldInfo.Visible = False
            End If
            i += 1
          Loop
        Next fieldInfo

        ' Define the primary display fields in the title of the map tip callout and the parent node for each result row in task results. 
        resultLayerFormat.Title = "{Match_addr}"

        ' Once finished modifying the layer format, apply it to the graphics layer. 
        resultLayerFormat.Apply(matchedResultsLayer)
      End If
    End Sub
    #End Region
  End Class
End Namespace