//清除地图控件选择的数据; private void toolStripButton8_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.roam; IActiveView ActiveView = axMapControl1.ActiveView; ActiveView.FocusMap.ClearSelection(); ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, ActiveView.Extent); }
//主页加载函数; private void index_Load(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.roam; Form content = new 目录(axMapControl1, toolStripButton6); content.Show(); toolStripButton6.Enabled = false; ToolStripMenuItem1.Enabled = false; }
//保存工具; private void toolStripButton5_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.roam; //检测是否加载图层; if (axMapControl1.LayerCount == 0) { MessageBox.Show("无保存内容!"); return; } IMapDocument mapdocunment = new MapDocumentClass(); saveFileDialog1.Filter = "工程文件mxd|(*.mxd)"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { mapdocunment.Open(saveFileDialog1.FileName); mapdocunment.ReplaceContents(axMapControl1.Map as IMxdContents); mapdocunment.Save(); MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK); } }
//添加数据工具; private void toolStripButton1_Click(object sender, EventArgs e) { index._tool_lable = HmMap.PublicMark.ButtonFunction.roam; openFileDialog1.Title = "打开文件"; openFileDialog1.Filter = "矢量文件(*.shp)|*.shp|ArcMap工程文件(*.mxd)|*.mxd|栅格影像文件|*.bmp;*.tif;*.img;*.jpg"; openFileDialog1.Multiselect = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string [] filename = openFileDialog1.FileNames; //添加矢量文件; if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".shp") { for (int i = 0; i < filename.Length; i++) { string path = System.IO.Path.GetDirectoryName(filename[i]); string filename_1 = System.IO.Path.GetFileName(filename[i]); axMapControl1.AddShapeFile(path, filename_1); } } //添加ArcMaP工程文件; else if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".mxd") { axMapControl1.LoadMxFile(openFileDialog1.FileName); } //加载栅格数据文件; else if (System.IO.Path.GetExtension(openFileDialog1.FileName) == ".tif" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".img" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".bmp" || System.IO.Path.GetExtension(openFileDialog1.FileName) == ".jpg") { for (int i = 0; i < filename.Length; i++) { string path = System.IO.Path.GetDirectoryName(filename[i]); string filename_1 = System.IO.Path.GetFileName(filename[i]); IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory(); IWorkspace pworkspace = pWorkspaceFactory.OpenFromFile(path, 0); IRasterWorkspace pRasterWorkspace = pworkspace as IRasterWorkspace; IRasterDataset prasterdataset = pRasterWorkspace.OpenRasterDataset(filename_1); IRasterPyramid3 jzt; jzt = prasterdataset as IRasterPyramid3; if (jzt != null) { if (!(jzt.Present)) { jzt.Create(); } } IRaster raster; raster = prasterdataset.CreateDefaultRaster(); IRasterLayer rasterLayer; rasterLayer = new RasterLayerClass(); rasterLayer.CreateFromRaster(raster); ILayer layer = rasterLayer as ILayer; axMapControl1.AddLayer(layer); axMapControl1.ActiveView.Refresh(); } } } else { MessageBox.Show("文件打开失败!"); return; } axMapControl1.Refresh(); }
//局部缩小功能 private void toolStripButton10_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.narrow; }
//局部放大功能 private void toolStripButton9_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.enlarge; }
//按位置选择 private void anToolStripMenuItem_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.TrackRectangle; }
//按位置选择 private void 矩形框选择ToolStripMenuItem_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.TrackPolygon; }
//要素识别事件 private void toolStripButton7_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.distinguish; }
//全图显示工具; private void toolStripButton3_Click(object sender, EventArgs e) { index._tool_lable = PublicMark.ButtonFunction.roam; axMapControl1.Extent = axMapControl1.FullExtent; }