Common CustomDataSourceCommon_CustomDataSource_VBNet\CustomDataSource_VBNet\REXMLDataSource_VBNet\MapFunctionality.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 System.Web.UI
Imports ESRI.ArcGIS.ADF.Web.Geometry
Imports ESRI.ArcGIS.ADF.Web.SpatialReference
Imports ESRI.ArcGIS.ADF.Web.DataSources
Imports System.Collections
Imports ESRI.ArcGIS.ADF.Web.Display.Graphics
Imports ESRI.ArcGIS.ADF.Web.Display.Drawing
Imports ESRI.ArcGIS.ADF.Web
Namespace REXMLDataSource_VBNet
Public Class MapFunctionality
Implements IMapFunctionality
#Region "Constructor"
Private graphics As GraphicsDataSet = Nothing
Public Sub New(ByVal name_Renamed As String, ByVal resource_Renamed As MapResource)
Me.name_Renamed = name_Renamed
Me.resource_Renamed = resource_Renamed
End Sub
Public ReadOnly Property MapResource() As MapResource
Get
Return TryCast(resource_Renamed, MapResource)
End Get
End Property
#End Region
#Region "IMapFunctionality implementation"
#Region "Private Member Vars"
Private displaySettings_Renamed As DisplaySettings = Nothing
Private webControl_Renamed As System.Web.UI.WebControls.WebControl = Nothing
Private maintainsState_Renamed As Boolean = False
Private spatialReference_Renamed As SpatialReference = Nothing
'private double scale;
'private Dictionary<string, bool> layerVisibility = null;
'private Units units;
#End Region
#Region "Public Properties"
Public ReadOnly Property GraphicsDataSet() As GraphicsDataSet
Get
If (Not maintainsState_Renamed) Then
Dim mr As MapResource = MapResource
If mr Is Nothing Then
Return Nothing
Else
Return mr.Graphics
End If
Else
If Not graphics Is Nothing Then
Return graphics
Else
Dim mr As MapResource = MapResource
If Not mr Is Nothing AndAlso Not mr.Graphics Is Nothing Then
graphics = mr.Graphics.Clone()
End If
Return graphics
End If
End If
End Get
End Property
Public Property MaintainsState() As Boolean Implements IMapFunctionality.MaintainsState
Get
Return maintainsState_Renamed
End Get
Set
maintainsState_Renamed = Value
End Set
End Property
Public Property WebControl() As System.Web.UI.WebControls.WebControl Implements IMapFunctionality.WebControl
Get
Return webControl_Renamed
End Get
Set
webControl_Renamed = Value
End Set
End Property
Public Property DisplaySettings() As DisplaySettings Implements IMapFunctionality.DisplaySettings
Get
If maintainsState_Renamed Then
If displaySettings_Renamed Is Nothing Then
displaySettings_Renamed = CType(MapResource.DisplaySettings.Clone(), DisplaySettings)
End If
Return displaySettings_Renamed
Else
Return MapResource.DisplaySettings
End If
End Get
Set
If maintainsState_Renamed Then
displaySettings_Renamed = Value
Else
MapResource.DisplaySettings = Value
End If
End Set
End Property
Public ReadOnly Property Units() As ESRI.ArcGIS.ADF.Web.DataSources.Units Implements IMapFunctionality.Units
Get
Throw New NotImplementedException()
End Get
End Property
Public ReadOnly Property LayerIDs() As Object()
Get
If GraphicsDataSet Is Nothing OrElse GraphicsDataSet.Tables Is Nothing Then
Return Nothing
End If
'INSTANT VB NOTE: The local variable layerIDs was renamed since Visual Basic will not allow local variables with the same name as their method:
Dim layerIDs_Renamed As Object() = New Object(GraphicsDataSet.Tables.Count - 1){}
Dim i As Integer = 0
Do While i < GraphicsDataSet.Tables.Count
layerIDs_Renamed(i) = GraphicsDataSet.Tables(i).TableName
i += 1
Loop
Return layerIDs_Renamed
End Get
End Property
Public Property SpatialReference() As SpatialReference Implements IMapFunctionality.SpatialReference
Get
Return spatialReference_Renamed
End Get
Set
spatialReference_Renamed = Value
End Set
End Property
Public ReadOnly Property Rotation() As Double Implements IMapFunctionality.Rotation
Get
Return Double.NaN
End Get
End Property
#End Region
#Region "Public Methods"
Public Sub ApplyStateToDataSourceObjects() Implements IMapFunctionality.ApplyStateToDataSourceObjects
If Not GraphicsDataSet Is Nothing Then
If Not DisplaySettings Is Nothing Then
GraphicsDataSet.ImageDescriptor = DisplaySettings.ImageDescriptor
End If
End If
End Sub
Public Sub GetStateFromDataSourceObjects() Implements IMapFunctionality.GetStateFromDataSourceObjects
If Not GraphicsDataSet Is Nothing Then
If Not DisplaySettings Is Nothing Then
DisplaySettings.ImageDescriptor = GraphicsDataSet.ImageDescriptor
End If
End If
End Sub
Public Sub GetLayers(<System.Runtime.InteropServices.Out()> ByRef layerids As String(), <System.Runtime.InteropServices.Out()> ByRef layernames As String()) Implements IMapFunctionality.GetLayers
Throw New NotImplementedException()
End Sub
Public Sub GetVisibleScale(ByVal layerid As String, <System.Runtime.InteropServices.Out()> ByRef minscale As Double, <System.Runtime.InteropServices.Out()> ByRef maxscale As Double) Implements IMapFunctionality.GetVisibleScale
' At a minimum, required for MapTips
minscale = Double.NaN
maxscale = Double.NaN
End Sub
Public Function GetScale(ByVal extent As ESRI.ArcGIS.ADF.Web.Geometry.Envelope, ByVal mapWidth As Integer, ByVal mapHeight As Integer) As Double Implements IMapFunctionality.GetScale
Throw New NotImplementedException()
End Function
Public Function GetCopyrightText() As System.Collections.Generic.Dictionary(Of String, String) Implements IMapFunctionality.GetCopyrightText
Return New Dictionary(Of String, String)()
End Function
Public Function DrawExtent(ByVal extentToDraw As ESRI.ArcGIS.ADF.Web.Geometry.Envelope) As ESRI.ArcGIS.ADF.Web.MapImage Implements IMapFunctionality.DrawExtent
If Not GraphicsDataSet Is Nothing Then
ApplyStateToDataSourceObjects()
Return GraphicsDataSet.DrawExtent(extentToDraw)
Else
Return Nothing
End If
End Function
Private Function getLayer(ByVal layerID As String) As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer
Dim graphicslayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer = CType(GraphicsDataSet.Tables(layerID), ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer)
Return graphicslayer
End Function
Public Function GetLayerVisibility(ByVal layerID As String) As Boolean Implements IMapFunctionality.GetLayerVisibility
Return getLayer(layerID).Visible
End Function
Public Sub SetLayerVisibility(ByVal layerID As String, ByVal visible As Boolean) Implements IMapFunctionality.SetLayerVisibility
getLayer(layerID).Visible = visible
End Sub
#End Region
#End Region
#Region "IGISFunctionality implementation"
Private name_Renamed As String = String.Empty
Private resource_Renamed As IGISResource = Nothing
Private initialized_Renamed As Boolean = False
Public Property Name() As String Implements IMapFunctionality.Name
Get
Return name_Renamed
End Get
Set
name_Renamed = Value
End Set
End Property
Public Property Resource() As IGISResource Implements IMapFunctionality.Resource
Get
Return resource_Renamed
End Get
Set
resource_Renamed = Value
End Set
End Property
Public ReadOnly Property Initialized() As Boolean Implements IMapFunctionality.Initialized
Get
Return initialized_Renamed
End Get
End Property
Public Sub LoadState() Implements IMapFunctionality.LoadState
If resource_Renamed Is Nothing OrElse resource_Renamed.DataSource Is Nothing OrElse resource_Renamed.DataSource.State Is Nothing Then
Throw New Exception("The Resource associated with this functionality is not valid.")
End If
' Shared properties with MapResource
' - Display Settings
' - DataSource objects: GraphicsDataSet
' Shared properties with the DataSource objects
' - DisplaySettings.ImageDescriptor
' Dynamic properties - no need to address these in LoadState.
' - LayerIDs, Scale, Rotation, Extent
' Other properties, we need to store in state.
' - WebControl
' - MaintainsState
' - SpatialReference
' Load previous state if it was saved before.
Dim o As Object = resource_Renamed.DataSource.State(key)
If Not o Is Nothing Then
Dim mf As MapFunctionality = TryCast(o, MapFunctionality)
' Get the "other properties" (as noted above) from stored state.
Me.maintainsState_Renamed = mf.MaintainsState
Me.webControl_Renamed = mf.WebControl
Me.spatialReference_Renamed = mf.spatialReference
' If maintainsState, load this functionalities own copies of the shared properties with the MapResource.
If maintainsState_Renamed Then
displaySettings_Renamed = mf.displaySettings
graphics = mf.graphics
End If
End If
' Load shared properties with datasource objects. These will be initialized with values from the datasource objects
GetStateFromDataSourceObjects()
' Need to do anything here for the dynamic properties: LayerIDs, Scale and Rotation, Extent.
End Sub
Public Sub Initialize() Implements IMapFunctionality.Initialize
initialized_Renamed = True
End Sub
Public Sub SaveState() Implements IMapFunctionality.SaveState
If resource_Renamed Is Nothing Then
Return
End If
If resource_Renamed.DataSource Is Nothing Then
Return
End If
If resource_Renamed.DataSource.State Is Nothing Then
Return
End If
ApplyStateToDataSourceObjects()
resource_Renamed.DataSource.State(key) = Me
End Sub
Public Sub Dispose() Implements IMapFunctionality.Dispose
initialized_Renamed = False
End Sub
Public Function Supports(ByVal operation As String) As Boolean Implements IMapFunctionality.Supports
If operation = "GetScale" Then
Return False
End If
Return True
End Function
#End Region
#Region "Private Properties"
Private ReadOnly Property key() As String
Get
Dim szResource As String = CType(resource_Renamed, Object).GetType().ToString() & ":" & resource_Renamed.Name
Dim szThis As String = Me.GetType().ToString() & ":" & name_Renamed
Return (szResource & "," & szThis)
End Get
End Property
#End Region
End Class
End Namespace