Common Custom tasks
Common_CustomTasks_VBNet\FindNearTask_VBNet\GraphicsResource.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 FindNearTask_VBNet
  ''' <summary>
  ''' Summary description for InputGraphicsLayer
  ''' </summary>
  Friend Class GraphicsResource
    Public Sub New(ByVal resourceName As String, ByVal map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
      Me.ResourceName = resourceName
      Me.initialize(map)
    End Sub

    Public ResourceName As String

    Private Sub initialize(ByVal mapInstance As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)
      Dim resourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = mapInstance.MapResourceManagerInstance.ResourceItems.Find(ResourceName)
      If resourceItem Is Nothing Then
'        #Region "Create graphics resource"
        resourceItem = New ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem()
        resourceItem.Definition = New ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition("<Definition DataSourceDefinition=""In Memory"" DataSourceType=""GraphicsLayer"" Identity="""" ResourceDefinition="""" DataSourceShared=""True""></Definition>")
        resourceItem.Name = ResourceName
        resourceItem.DisplaySettings = New ESRI.ArcGIS.ADF.Web.DisplaySettings()
        resourceItem.DisplaySettings.Visible = True
        resourceItem.DisplaySettings.Transparency = 25
        resourceItem.DisplaySettings.DisplayInTableOfContents = False

        resourceItem.DisplaySettings.ImageDescriptor = New ESRI.ArcGIS.ADF.Web.ImageDescriptor(ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter.FromWebImageFormat(mapInstance.ImageFormat), CInt(Fix(mapInstance.Width.Value)), CInt(Fix(mapInstance.Height.Value)))
        mapInstance.MapResourceManagerInstance.ResourceItems.Insert(0, resourceItem)
        resourceItem.DisplaySettings.ImageDescriptor.TransparentBackground = True
        resourceItem.DisplaySettings.ImageDescriptor.TransparentColor = System.Drawing.Color.FromArgb(1, 1, 1)
        Dim resource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = TryCast(resourceItem.CreateResource(), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
'        #End Region
'        #Region "Add layer to dataset"
        Dim elementGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
        elementGraphicsLayer.TableName = "User Input Graphics Layer"

        resource.Graphics = New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsDataSet()
        resource.Graphics.DataSetName = "FindNearTask Input Graphics"
        resource.Graphics.Tables.Add(elementGraphicsLayer)

        elementGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
        elementGraphicsLayer.TableName = "Buffer Graphics Layer"
        resource.Graphics.Tables.Add(elementGraphicsLayer)

'        #End Region
'        #Region "Initialize resource and functionalities"
        If mapInstance.MapResourceManagerInstance.Initialized Then
          resourceItem.InitializeResource()
        End If
        If mapInstance.InitializedFunctionalities Then
          mapInstance.InitializeFunctionality(resourceItem)
        End If
'        #End Region
      End If
    End Sub

    Public Function GetUserInputLayer(ByVal mapResourceManager As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager) As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer
      Return Me.GetLayer(mapResourceManager, "User Input Graphics Layer")
    End Function

    Public Function GetBufferLayer(ByVal mapResourceManager As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager) As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer
      Return Me.GetLayer(mapResourceManager, "Buffer Graphics Layer")
    End Function

    Private Function GetLayer(ByVal mapResourceManager As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager, ByVal layerName As String) As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer
      Dim resourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = mapResourceManager.ResourceItems.Find(ResourceName)
      If (Not resourceItem.Resource.Initialized) Then
        resourceItem.InitializeResource()
      End If

      Dim resource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = TryCast(resourceItem.Resource, ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
      If Not resource Is Nothing AndAlso Not resource.Graphics Is Nothing AndAlso Not resource.Graphics.Tables(layerName) Is Nothing Then
        Return TryCast(resource.Graphics.Tables(layerName), ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
      End If

      Return Nothing
    End Function

  End Class
End Namespace