您的位置:首页 > 其它

MapXtreme 操作地图时出现调用目标发生异常的解决方法--地图状态保存

2010-05-26 14:19 525 查看
以下代码位于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 dirtythen apply the default state saved in above step to give users ainitial 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 tempvariables the objects are serialized into session. There is no need toset 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");

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐