//instanciate AppStateManager class AppStateManager myStateManager =new AppStateManager(); //put current map alias to state manager dictionary myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] =this.MapControl1.MapAlias; //put state manager to session StateManager.PutStateManagerInSession(myStateManager);
#region 测试代码
if (myMap !=null) { if (myMap.Layers["TempLayerAlias"] !=null) { myMap.Layers.Remove("TempLayerAlias"); } } // Need to clean up "dirty" temp table left by other customer requests. MapInfo.Engine.Session.Current.Catalog.CloseTable("TempTableAlias"); // Need to clear the DefautlSelection. MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();
// Creat a temp table and AddPintPointCommand will add features into it. MapInfo.Data.TableInfoMemTable ti =new MapInfo.Data.TableInfoMemTable("TempTableAlias"); // Make the table mappable ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateFeatureGeometryColumn(myMap.GetDisplayCoordSys())); ti.Columns.Add(MapInfo.Data.ColumnFactory.CreateStyleColumn());
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti); // Create a new FeatureLayer based on the temp table, so we can see the temp table on the map. myMap.Layers.Insert(0, new FeatureLayer(table, "templayer", "TempLayerAlias"));
IMapLayer lyr = myMap.Layers["TempLayerAlias"]; if (lyr ==null) return; FeatureLayer fLyr = lyr as FeatureLayer;
MapInfo.Geometry.DPoint point =new DPoint(100, 20); MapInfo.Geometry.Point geoPoint =new MapInfo.Geometry.Point(myMap.GetDisplayCoordSys(), point);
// Create a Feature which contains a Point geometry and insert it into temp table. Feature feature =new Feature(geoPoint, vStyle); MapInfo.Data.Key key = fLyr.Table.InsertFeature(feature);
// Now Restore State StateManager.GetStateManagerFromSession().RestoreState(); } }
其他部分的相关代码如下:
Code // At the time of unloading the page, save the state protectedvoid Page_UnLoad(object sender, System.EventArgs e) { if (StateManager.IsManualState()) { StateManager.GetStateManagerFromSession().SaveState(); } }