Common CustomDataSource
Common_CustomDataSource_VBNet\CustomDataSource_VBNet\TiledMapDataSource_VBNet\TileFunctionality.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 TiledMapDataSource_VBNet
  Public Class TileFunctionality
    Implements ITileFunctionality
    Private serviceUrl_Renamed As String

    Public ReadOnly Property ImageFormat() As WebImageFormat Implements ITileFunctionality.ImageFormat
      Get
        Return WebImageFormat.JPG
      End Get
    End Property

    Private _tileCacheInfo As TileCacheInfo = Nothing
    Public Sub New(ByVal name_Renamed As String, ByVal resource_Renamed As MapResource, ByVal tileCacheInfo As TileCacheInfo)
      Me.name_Renamed = name_Renamed
      Me.resource_Renamed = resource_Renamed
      _tileCacheInfo = tileCacheInfo
    End Sub

    #Region "ITileFunctionality Members"

    Public Function Draw(ByVal mapFunctionalityName As String, ByVal column As Long, ByVal row As Long, ByVal level As Integer) As ESRI.ArcGIS.ADF.Web.MapImage Implements ITileFunctionality.Draw
      Dim realLevel As Integer = _tileCacheInfo.Levels(level)
      Dim baseUrl As String = _tileCacheInfo.TileUrls(realLevel)
      If String.IsNullOrEmpty(_tileCacheInfo.TileUrlGeneratorAssembly) OrElse String.IsNullOrEmpty(_tileCacheInfo.TileUrlGeneratorClass) Then
        Return Nothing
      End If
      Dim urlGen As ITileUrlGenerator = TryCast(getInstanceOfType (_tileCacheInfo.TileUrlGeneratorAssembly, _tileCacheInfo.TileUrlGeneratorClass), ITileUrlGenerator)
      If urlGen Is Nothing Then
        Return Nothing
      End If

      Dim mapFunc As MapFunctionality = GetMapFunctionality(mapFunctionalityName)
      If mapFunc Is Nothing Then
        Throw New ArgumentException("mapFunctionalityName")
      End If

      serviceUrl_Renamed = urlGen.GetTileUrl (column, row, realLevel, baseUrl, mapFunc.LayerVisibility)

      Return New ESRI.ArcGIS.ADF.Web.MapImage(serviceUrl_Renamed, Nothing)
    End Function

    Public ReadOnly Property ServiceUrl() As String Implements ITileFunctionality.ServiceUrl
      Get
        Return serviceUrl_Renamed
      End Get
    End Property

    Public ReadOnly Property UrlGeneratorJSFunction() As String Implements ITileFunctionality.UrlGeneratorJSFunction
      Get
        Return Nothing
      End Get
    End Property

    #End Region

    #Region "IGISFunctionality Members"
    Private name_Renamed As String = String.Empty
    Private resource_Renamed As IGISResource = Nothing
    Private _webControl As System.Web.UI.WebControls.WebControl

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

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

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

    Private _initialized As Boolean = False

    Public ReadOnly Property Initialized() As Boolean Implements ITileFunctionality.Initialized
      Get
        Return _initialized
      End Get
    End Property

    Public Sub LoadState() Implements ITileFunctionality.LoadState

    End Sub

    Public Sub Initialize() Implements ITileFunctionality.Initialize
      _initialized = True
    End Sub

    Public Sub SaveState() Implements ITileFunctionality.SaveState

    End Sub

    Public Sub Dispose() Implements ITileFunctionality.Dispose
      _initialized = False
    End Sub

    Public Function Supports(ByVal operation As String) As Boolean Implements ITileFunctionality.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

    Private Function getInstanceOfType(ByVal assemblyName As String, ByVal type As String) As Object
      Dim o As Object = Nothing
      Try
        Dim [assembly] As System.Reflection.Assembly = System.Reflection.Assembly.Load(assemblyName)
        o = [assembly].CreateInstance(type)
      Catch e As Exception
        Dim mess As String = e.Message
      End Try
      Return o
    End Function
    #End Region


  End Class
End Namespace