⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appstatemanager.vb.exclude

📁 Get Map Coordinat by click on map
💻 EXCLUDE
字号:
'//////////////////////////////////////////////////////////////////////////////////////////////
'//
'//   (c) Pitney Bowes MapInfo Corporation, 2008.  All rights reserved.
'//
'//   This software is only provided as a demonstration by MapInfo.  
'//   No licence or other right is granted.  
'//   No use, transmission or copying is permitted.
'//
'//   This software is provided by MapInfo "as is" and any express or implied warranties, 
'//   including, but not limited to, the implied warranties of merchantability and fitness 
'//   for a particular purpose are disclaimed.  In no event shall MapInfo be liable for any 
'//   direct, indirect, incidental, special, exemplary, or consequential damages (including, 
'//   but not limited to, procurement of substitute goods or services; loss of use, data or
'//   profits; or business interruption) however caused and whether in contract, strict 
'//   liability, or tort (including negligence) arising in any way out of the use of this 
'//   software, even if advised of the possibility of such damage.
'//
'//////////////////////////////////////////////////////////////////////////////////////////////

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports MapInfo.Engine
Imports MapInfo.GeomeTry
Imports MapInfo.Mapping
Imports MapInfo.WebControls

'/ <summary>
'/ Summary description for AppStateManager
'/ </summary>
Namespace ApplicationStateManager
    '/ <summary>
    '/ State management can be complex operation. It is efficient to save and restore what is needed.
    '/ The method used here is described in the BEST PRACTISES documentation. This is a template application
    '/ which changes zoom, center, default selection and layer visibility. Hence we save and restore only these objects.
    '/ </summary>
    <Serializable()> _
    Public Class AppStateManager
        Inherits StateManager

        Public Sub New()
        End Sub



        ' Restore the state
        Public Overrides Sub RestoreState()
            Dim mapAlias As String = ParamsDictionary(ActiveMapAliasKey)
            Dim map As Map = GetMapObj(mapAlias)

            ' If this is a clean pooled object save the default state for new users to 
            ' access later.
            If (Not IsDirtyMapXtremeSession(map)) Then

                SaveDefaultState(map)
            End If

            ' If it was user's first time and the session is dirty, restore the default state.
            If IsUsersFirstTime() Then
                If IsDirtyMapXtremeSession(map) Then
                    RestoreDefaultState(map)
                End If
            Else
                ' If this is an existing user then restore the last state they saved
                ' Make sure to also check if this is a clean or dirty pooled object, you may
                ' have to restore some base state or tables prior to restoring users state. The best
                ' practice is to save all modified or added MapXtreme objects to the users state
                ' and restore them in the correct order. But in some instances clean up or
                ' initialization of the pooled MapXtreme Session may be necessary
                If (IsDirtyMapXtremeSession(map)) Then
                    ' TODO: Manual work to prepare the dirty Pooled MapXtreme Session instance
                Else
                    ' TODO: Manual work to prepare the clean Pooled MapXtreme Session instance
                End If
                ' If it is not user's first time then restore the last state they saved
                RestoreZoomCenterState(map)
                ' Just by deserializing the binary stream we reset the MapFactory Deault layers collection
                ' Any MapXtreme class that supports the ISerializable interface will automatically be 
                ' restored to the current MapXtreme Session.
                ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Layers")
                ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Selection")
            End If
        End Sub

        ' Save the users current state
        Public Overrides Sub SaveState()
            Dim mapAlias As String = ParamsDictionary(ActiveMapAliasKey)
            Dim map As Map = GetMapObj(mapAlias)

            If Not map Is Nothing Then
                SaveZoomCenterState(map)
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers, "Layers")
                ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Selections.DefaultSelection, "Selection")

                ' Mark the users HTTPSession as dirty
                HttpContext.Current.Session("UserDirtyFlag") = True
            End If
        End Sub


        ' Check if this is user's first time accessing this page. 
        Private Function IsUsersFirstTime() As Boolean
            Return (HttpContext.Current.Session("UserDirtyFlag") Is Nothing)
        End Function

        ' This method checks if the mapinfo session from the pool is dirty or clean
        Private Function IsDirtyMapXtremeSession(ByVal map As Map) As Boolean
            ' Check if the MapXtreme session is dirty

            Return (Not (MapInfo.Engine.Session.Current.CustomProperties("DirtyFlag") Is Nothing))
        End Function

        ' When the MapXtreme Session is not dirty save the initial state of this session read from the 
        ' initial workspace from the web.config.
        Private Sub SaveDefaultState(ByVal map As Map)
            Dim application As HttpApplicationState = HttpContext.Current.Application
            If application("DefaultZoom") Is Nothing Then
                ' Store default selection
                application("DefaultSelection") = ManualSerializer.BinaryStreamFromObject(MapInfo.Engine.Session.Current.Selections.DefaultSelection)
                ' Store layers collection
                application("DefaultLayers") = ManualSerializer.BinaryStreamFromObject(map.Layers)
                ' Store the original zoom and center.
                application("DefaultCenter") = map.Center
                application("DefaultZoom") = map.Zoom
            End If
            ' This pooled MapXtreme Session instance should be marked as dirty
            MapInfo.Engine.Session.Current.CustomProperties.Add("DirtyFlag", True)
        End Sub

        ' When session is dirty but it is first time for user, this will be applied to give users it's initial state
        Private Sub RestoreDefaultState(ByVal map As Map)
            Dim application As HttpApplicationState = HttpContext.Current.Application
            ' Get the default layers, center, and zoomfrom the Application. Clear Layers first, 
            'this resets the zoom and center which we will set later
            map.Layers.Clear()

            ' Just by deserializing the binary stream we reset the MapFactory Deault layers collection
            ' Any MapXtreme class that supports the ISerializable interface will automatically be 
            ' restored to the current MapXtreme Session. 
            Dim bytes() As Byte = CType(application("DefaultLayers"), Byte())
            Dim obj As Object = ManualSerializer.ObjectFromBinaryStream(bytes)

            ' Deserialzing rules are the same for the default selection
            bytes = CType(application("DefaultSelection"), Byte())
            obj = ManualSerializer.ObjectFromBinaryStream(bytes)

            ' For zoom and center, these are simple types and need to be assigned to the map object.
            map.Zoom = CType(application("DefaultZoom"), MapInfo.GeomeTry.Distance)
            map.Center = CType(application("DefaultCenter"), DPoint)
        End Sub

        ' Return the Map from the Sessions MapFactory based on Alias. If not found return 
        ' the first map in the collection.
        Private Function GetMapObj(ByVal mapAlias As String) As Map

            Dim map As Map
            If (mapAlias Is Nothing) Then
                map = MapInfo.Engine.Session.Current.MapFactory(0)
            ElseIf (mapAlias.Length <= 0) Then
                map = MapInfo.Engine.Session.Current.MapFactory(0)
            Else
                map = MapInfo.Engine.Session.Current.MapFactory(mapAlias)
                If map Is Nothing Then
                    map = MapInfo.Engine.Session.Current.MapFactory(0)
                End If
            End If
            Return map
        End Function
    End Class
End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -