Common CustomDataSource
Common_CustomDataSource_VBNet\CustomDataSource_VBNet\REXMLDataSource_VBNet\MapTocFunctionality.vb
' Copyright 2007 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.Collections.Generic
Imports System.Text
Imports ESRI.ArcGIS.ADF.Web.DataSources
Imports ESRI.ArcGIS.ADF.Web

Namespace REXMLDataSource_VBNet
  Public Class MapTocFunctionality
    Implements IMapTocFunctionality
    #Region "private member variables"
    Private name_Renamed As String = String.Empty
    Private resource_Renamed As IGISResource = Nothing
    Private initialized_Renamed As Boolean = False
    Private mapResource As MapResource
    #End Region

    Public Sub New(ByVal name_Renamed As String, ByVal resource_Renamed As MapResource)
      Me.name_Renamed = name_Renamed
      Me.resource_Renamed = resource_Renamed
      mapResource = resource_Renamed
    End Sub

    #Region "IMapTocFunctionality implementation"
    Public Sub SetLayerVisibility(ByVal mapFunctionalityName As String, ByVal layerID As Object, ByVal visible As Boolean)
      Dim mapFunc As MapFunctionality = GetMapFunctionality(mapFunctionalityName)
      If mapFunc Is Nothing Then
        Throw New ArgumentException("mapFunctionalityName")
      End If
      mapFunc.SetLayerVisibility(layerID.ToString(), visible)
    End Sub

        Public Function GetMapContents(ByVal mapFunctionalityName As String, ByVal format As WebImageFormat, ByVal useMimeData As Boolean, ByVal showAllDataFrames As Boolean) As TocDataFrame() Implements IMapTocFunctionality.GetMapContents
            Dim tocDataFrames As TocDataFrame() = New TocDataFrame(0) {}
            tocDataFrames(0) = New TocDataFrame(resource_Renamed.Name)
            Dim session As System.Web.SessionState.HttpSessionState = Nothing
            Try
                Dim httpContext As System.Web.HttpContext = System.Web.HttpContext.Current
                If Not httpContext Is Nothing Then
                    session = httpContext.Session
                End If
            Catch
            End Try
            Dim swatchInfo As ESRI.ArcGIS.ADF.Web.Display.Swatch.SwatchInfo = New ESRI.ArcGIS.ADF.Web.Display.Swatch.SwatchInfo(10, 10, session)
            For Each table As System.Data.DataTable In mapResource.Graphics.Tables
                tocDataFrames(0).Add(ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer.GetTocLayer(TryCast(table, ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer), swatchInfo))
            Next table
            Return tocDataFrames
        End Function
    #End Region

    #Region "IGISFunctionality implementation"
        Private _webControl As System.Web.UI.WebControls.WebControl

    Public Property WebControl() As System.Web.UI.WebControls.WebControl Implements IMapTocFunctionality.WebControl
      Get
        Return _webControl
      End Get
      Set
        _webControl = Value
      End Set
    End Property

    Public Property Name() As String Implements IMapTocFunctionality.Name
      Get
        Return name_Renamed
      End Get
      Set
        name_Renamed = Value
      End Set
    End Property

    Public Property Resource() As IGISResource Implements IMapTocFunctionality.Resource
      Get
        Return resource_Renamed
      End Get
      Set
        resource_Renamed = Value
      End Set
    End Property

    Public ReadOnly Property Initialized() As Boolean Implements IMapTocFunctionality.Initialized
      Get
        Return initialized_Renamed
      End Get
    End Property

    Public Sub LoadState() Implements IMapTocFunctionality.LoadState
    End Sub

    Public Sub Initialize() Implements IMapTocFunctionality.Initialize
      initialized_Renamed = True
    End Sub

    Public Sub SaveState() Implements IMapTocFunctionality.SaveState
    End Sub

    Public Sub Dispose() Implements IMapTocFunctionality.Dispose
      initialized_Renamed = False
    End Sub

    Public Function Supports(ByVal operation As String) As Boolean Implements IMapTocFunctionality.Supports
      Return True
    End Function
    #End Region

    #Region "private methods"
    Private Function GetMapFunctionality(ByVal name_Renamed As String) As MapFunctionality
      Dim mapFunctionality As MapFunctionality = TryCast(resource_Renamed.Functionalities.Find(name_Renamed), MapFunctionality)
      Return mapFunctionality
    End Function
    #End Region
  End Class
End Namespace