private void 添加图层ToolStripMenuItem_Click(object sender, EventArgs e) { //判断地图视图中是否有处于显示状态中的地图 if (this.mapCtrl.ActiveMap == null) { MessageBox.Show("请先在地图视图中显示一幅地图!!!"); return; } //选择待添加的图层 GDBOpenFileDialog ofDlg = new GDBOpenFileDialog(); //ofDlg.Filter = "简单要素类、注记类|sfcls;acls"; if (ofDlg.ShowDialog() != DialogResult.OK) { return; } string fileName = ofDlg.FileName; IVectorCls sfcls = new SFeatureCls(); if (sfcls.Open(fileName)) { MessageBox.Show("打开成功"); } else { MessageBox.Show("打开失败"); } return; this._Tree.WorkSpace.BeginUpdateTree(); //附加矢量图层 VectorLayer vecLayer = new VectorLayer(VectorLayerType.SFclsLayer); vecLayer.AttachData(sfcls); //将图层添加到地图中 vecLayer.Name = sfcls.ClsName; //获取激活地图 Map activeMap = this.mapCtrl.ActiveMap; activeMap.Append(vecLayer); //复位 this.mapCtrl.ActiveMap = activeMap; this.mapCtrl.Restore(); this._Tree.WorkSpace.EndUpdateTree(); return; }
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { //定义数据源 Server svr = new Server(); //连接数据源 if (svr.Connect("MapGISLocal", "", "")) { ; } { //打开数据库 DataBase gdb = svr.OpenGDB("sample"); if (gdb != null) { //打开简单要素类 SFeatureCls sfcls = new SFeatureCls(gdb); if (sfcls.Open("等值线", 0)) { MessageBox.Show("读取数据成功"); //显示简单要素类,实例地图显示控件 //实例化地图显示控件 MapControl mapCtrl = new MapControl(); mapCtrl.Dock = DockStyle.Fill; //添加控件 this.splitContainer1.Panel2.Controls.Add(mapCtrl); //创建图层 VectorLayer layer = new VectorLayer(VectorLayerType.SFclsLayer); if (layer.AttachData(sfcls)) { Map map = new Map(); map.Append(layer); mapCtrl.ActiveMap = map; //复位显示地图 mapCtrl.Restore(); } } } } }