Map Showing Different In One Application MapXtreme

Different maps here means, if we have two or more maps that are not related. For example if the first map appears, then the second map is omitted, or if the maps both show the first map is removed or the first map to use the administrative boundary map are both using the other boundary so that both maps are treated differently. There are at least two ways to make this kind of thing

* Create different MWS file. Each map is made MWS tersediri
* Create a file folder MWS with several aliases.

Here I write about the second way, using a file MWS for some maps.

Preparing File MWS
Note the picture below MWS file. Open the workspace manager, and create a file MWS. By default there is only one folder, "Map1". Add the map layer on Map1. Click the Maps button, and add Map2. In Map2 add other map layers.

Map1

Map 2

There are two folders (mapalias), Map1 and map2. Each folder has a different map layout. We can add another layer in each folder, here I just use a single map layer.

Setting up WebSite Project
Create a new website, use the MapXtreme template. Add the following radio button list on file Mapform.aspx (Default.aspx).
view source
print?
1
2
3
4

At the MapControl, empty property MapAlias. So the code becomes as follows
view source
print?
1

Open the codebehind file, add a method for the event radiobuttonlist
view source
print?
1 Protected Sub RadioButtonList1_SelectedIndexChanged (ByVal sender As Object, ByVal e As System.EventArgs) _
2 Handles RadioButtonList1.SelectedIndexChanged
3 MapControl1.MapAlias ​​= RadioButtonList1.SelectedValue
4 End Sub

And in the Page_Load event, add the following code, to determine which folder alias that will be loaded by mapcontrol first. If not set, usually called the Map1.
view source
print?
1 If Not Page.IsPostBack Then
2 MapControl1.MapAlias ​​= RadioButtonList1.SelectedValue
3 End If

Run the application, the initial display is the map of Java (Map1), all information map1 like coordinate system, the position of center map, zoom range will be stored in the session. When kalimantan selected, the map turned into a central position map kalimantan but still refers to Map1 (Java). Because the information stored in the session information is for map1

When Kalimantan (Map2) is selected, the object map that is stored in the session is still a Java map (Map1), because Map1 and Map2 have the same coordinate system (WGS84) then map2 can be displayed with the map center position in accordance with map1.

This error is caused because the two maps using the same session object. To avoid this error, information of each map is stored in a different session objects. If the application created using state methods manual (StateServer), we need to change the map information storage procedures in the session. Open the file AppStateManager.vb, modifications and RestoreState saveState method, more or less be like this.
view source
print?
01 Public Overrides Sub saveState ()
02 mapAlias ​​Dim As String = ParamsDictionary (ActiveMapAliasKey)
03 Dim map As Map = GetMapObj (mapAlias)
04
05 If Not folder Is Nothing Then
06 If mapAlias ​​= "Map1" Then
07 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (map.Center, "center")
08 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (map.Layers, "Layers")
09 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (_
10 MapInfo.Engine.Session.Current.Selections.DefaultSelection, "Selection")
11 'Mark the users HttpSession as dirty
12 HttpContext.Current.Session ("UserDirtyFlag") = True
13 Else
14 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (map.Center, "center2")
15 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (map.Layers, "Layers2")
16 ManualSerializer.SaveMapXtremeObjectIntoHttpSession (_
17 MapInfo.Engine.Session.Current.Selections.DefaultSelection, "Selection2")
18 'Mark the users HttpSession as dirty
19 HttpContext.Current.Session ("UserDirtyFlag") = True
20 End If
21 End If
22 End Sub
23
24 Public Overrides Sub RestoreState ()
25 mapAlias ​​Dim As String = ParamsDictionary (ActiveMapAliasKey)
26 Dim map As Map = GetMapObj (mapAlias)
27
28 If (Not IsDirtyMapXtremeSession (map)) Then
29 SaveDefaultState (map)
30 End If
31
32 'If it was the user's first-time and the session is dirty, restore the default state.
33 If IsUsersFirstTime () Then
34 If IsDirtyMapXtremeSession (folder) Then
35 RestoreDefaultState (map)
36 End If
37 Else
38 If (IsDirtyMapXtremeSession (map)) Then
39 'TODO: Manual dirty work to prepare the MapXtreme Session instance Pooled
40 Else
41 'TODO: Manual work to prepare the clean Pooled MapXtreme Session instance
42 End If
43
44 If mapAlias ​​= "Map1" Then
45 'RestoreZoomCenterState (map)
46 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("center")
47 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("Layers")
48 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("Selection")
49 Else
50 'RestoreZoomCenterState (map)
51 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("center2")
52 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("Layers2")
53 ManualSerializer.RestoreMapXtremeObjectFromHttpSession ("Selection2")
54 End If
55 End If
56 End Sub

Note on the method saveState (), map and information center of each map layer is stored separately. So when RestoreState run no errors occur as described earlier.

In this way, we can display multiple maps with different themes in one application. Of course the setting in appstate will not be as simple as this if we also implemented in each thematic map.

Note:
If the application is built using a method InProc (HttpSessionState) mapalias use of this possibility will not run smoothly. Because the information stored in the session object in the handle automatically, we do not know what information is stored. Thus, in some experiments I did with the method InProc (HttpSessionState) sometimes runs smoothly but sometimes not as expected.