Pitney Bowes MapXtreme User Manual

Page 118

Advertising
background image

Chapter 6: Understanding State Management

A Detailed Look at Manual State Management

MapXtreme v7.1

118

Developer Guide

The RestoreState and SaveState methods are used as follows:

1. Each time a client submits a request, the Page_Load method calls RestoreState. RestoreState is

also called each time a map tool is used on the client. The RestoreState method ensures that the
MapXtreme Session object— which was retrieved from the pool in an unknown, possibly "dirty"
state— is restored to a known state, either to the user’s state, if it exists, or to the default state
from Application state.
For example, if the user's map was zoomed in on France the last time the user requested a map,
then the RestoreState method will ensure that the map retrieved from the pool is returned to a
"zoomed in on France" state. This way, the user's session can continue from where it left off.
The following VB code example is from the Thematic sample application’s WebForm1.aspx.vb.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _

System.EventArgs) Handles MyBase.Load

' The first time in
If Session.IsNewSession Then

'//************************************************************
'// You need to follow below lines in your own application.
'//*****************************************************************

Dim stateManager As New AppStateManager

' tell the state manager which map alias you want to use.
' You could also add your own key/value pairs, the value should be
' serializable.

stateManager.ParamsDictionary.Item(AppStateManager.ActiveMapAliasKey)_

= Me.MapControl1.MapAlias

' Put state manager into HttpSession, so we could get it later on from
' different class and requests.

MapInfo.WebControls.StateManager.PutStateManagerInSession_

(stateManager)

Me.InitState()

End If

MapInfo.WebControls.StateManager.GetStateManagerFromSession.RestoreState(
)

PrepareData()
End Sub

2. After the Page_Load method, the application applies whatever business logic is appropriate,

given the nature of the client request.
For example, if the request was generated by the user clicking with the Zoom In tool, the
business logic adjusts the map's center and zoom level.

Advertising