向地图中添加地图资源
这段代码是用来从本地文件中读取一个文件,然后放入MAP1控件中
IGISFunctionality functionality = (IGISFunctionality)this.Map1.GetFunctionality(0);
MapResourceLocal gisRes = functionality.Resource as MapResourceLocal;
IServerContext mapContext = gisRes.ServerContextInfo.ServerContext;
IWorkspaceFactory pWsFactory = (IWorkspaceFactory)mapContext.CreateObject("esriDataSourcesFile.ShapefileWorkspaceFactory");
IFeatureWorkspace pFeatureWsp = (IFeatureWorkspace)pWsFactory.OpenFromFile(@"D:\GIS-Data\", 0);
IFeatureLayer pFeaLayer = (IFeatureLayer)mapContext.CreateObject("esriCarto.FeatureLayer");
pFeaLayer.FeatureClass = pFeatureWsp.OpenFeatureClass("Cities.shp");
pFeaLayer.Name = "world30";
pFeaLayer.Visible = true;
IMapServerObjects mso = (IMapServerObjects)gisRes.MapServer;
string resStr = gisRes.DataFrame;
IMap map = mso.get_Map(resStr);
map.AddLayer(pFeaLayer);
map.MoveLayer(pFeaLayer, 0);
gisRes.RefreshServerObjects();
Map1.Refresh();