MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存
以下代碼位于AppStateManager.cs文件中:
// Restore the state
??????? public override void RestoreState()
??????? {
??????????? string mapAlias = ParamsDictionary[ActiveMapAliasKey] as string;
??????????? Map map = GetMapObj(mapAlias);
??
??????????? // If it was user's first time and the session was not dirty then save this default state to be applied later.
??????????? // If it was a users's first time and the session was dirty then apply the default state saved in above step to give users a initial state.
??????????? if (IsUsersFirstTime())
??????????? {
??????????????? if (IsDirtyMapXtremeSession(map))
??????????????? {
??????????????????? RestoreDefaultState(map);
??????????????? }
??????????????? else
??????????????? {
??????????????????? SaveDefaultState(map);
??????????????? }
??????????? }
??????????? else
??????????? {
??????????????? // If it is not user's first time then restore the last state they saved
??????????????? RestoreZoomCenterState(map);
???????????????? //恢復臨時圖層Animation的狀態
??????????????? if (HttpContext.Current.Session["Animation" + "Layer"] != null)
?????????????? {
?????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Animation" + "Table");
?????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Animation" + "Layer");
??????????????? }
????????????? //恢復標注圖層jcbz的狀態
??????????????? if (HttpContext.Current.Session["jcbz" + "Layer"] != null)
??????????????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("jcbz" + "Layer");
????? ????????? //恢復臨時圖層Tm的狀態
??????????????????????????? if (HttpContext.Current.Session["Tm" + "Layer"] != null)
??????????????? {
??????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Tm" + "Table");
??????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Tm" + "Layer");
??????????????? }
?????????????????????????????? // Just by setting it to temp variables the objects are serialized into session. There is no need to set them explicitly.
??????????????? for (int i = 0; i < map.Layers.Count ;i++ )
?????????????????????? if(map.Layers[i]!=null)????????????????? //必須加這條語句,否則老是在這里出現錯誤
?????????????????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession(map.Layers[i].Name+"Layer");
????????????????????? //恢復地圖中選中的圖元對象
??????????????? ManualSerializer.RestoreMapXtremeObjectFromHttpSession("Selection");
??????????? }
??????? }
??????? // Save the state
??????? public override void SaveState()
??????? {
??????????? string mapAlias = ParamsDictionary[ActiveMapAliasKey] as string;
??????????? Map map = GetMapObj(mapAlias);
??????????? if (map != null)
??????????? {
??????????????? SaveZoomCenterState(map);
????????????? //判斷地圖中是否有Animation圖層,有的話保存狀態
??????????????? if (map.Layers["Animation"] != null)
??????????????? {
??????????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Catalog["Animation"], "Animation" + "Table");
??????????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers["Animation"], "Animation" + "Layer");
??????????????? }
???????????? //判斷地圖中是否有Tm圖層,有的話保存狀態
??????????????? if (map.Layers["Tm"] != null)
??????????????? {
??????????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Catalog["Tm"], "Tm" + "Table");
??????????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers["Tm"], "Tm" + "Layer");
??????????????? }
?????????????? //遍歷各圖層,有層名為jcbz的層則保存該標注圖層的狀態
??????????????? for (int i = 0; i < map.Layers.Count; i++)
??????????????????? if (map.Layers[i].Name == "jcbz")
??????????????????? {
????????????????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers[i], "jcbz" + "Layer");
??????????????????????? break;
??????????????????? }
??????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(map.Layers, "Layers");
??????????????? ManualSerializer.SaveMapXtremeObjectIntoHttpSession(MapInfo.Engine.Session.Current.Selections.DefaultSelection, "Selection");
??????????? }
??????? }
總結
以上是生活随笔為你收集整理的MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 指令篇
- 下一篇: [原创][连载].基于SOPC的简易数码