LoadMxFile方法加载MXD文档: private void loadMxFile方法ToolStripMenuItem_Click(object sender, EventArgs e) { //加载数据前如果有数据则清空 try { OpenFileDialog pOpenFileDialog = new OpenFileDialog();//打开文件 pOpenFileDialog.CheckFileExists = true;//判断文件存在 pOpenFileDialog.Title = "打开地图文档"; pOpenFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf"; pOpenFileDialog.Multiselect = false; //不允许多个文件同时选择 pOpenFileDialog.RestoreDirectory = true; //存储打开的文件路径 if (pOpenFileDialog.ShowDialog() == DialogResult.OK) { string pFileName = pOpenFileDialog.FileName; if (pFileName == "") { return; } if (mainMapControl.CheckMxFile(pFileName)) //MapControl的CheckMxFile方法检查地图文档是否为效的地图文档,返回值为Bool { ClearAllData(); mainMapControl.LoadMxFile(pFileName);//MapControl的LoadMxFile方法 加载地图文档 } else { MessageBox.Show(pFileName + "是无效的地图文档!", "信息提示"); return; } } } catch (Exception ex) { MessageBox.Show("打开地图文档失败" + ex.Message); } } #region 封装的方法 private void ClearAllData() { if (mainMapControl.Map != null && mainMapControl.Map.LayerCount > 0) { //新建mainMapControl中Map IMap dataMap = new MapClass(); dataMap.Name = "Map"; mainMapControl.DocumentFilename = string.Empty; mainMapControl.Map = dataMap; //新建EagleEyeMapControl中Map IMap eagleEyeMap = new MapClass(); eagleEyeMap.Name = "eagleEyeMap"; EagleEyeMapControl.DocumentFilename = string.Empty; EagleEyeMapControl.Map = eagleEyeMap; } } #endregion
原文地址:https://www.cnblogs.com/gistwz/p/10171711.html
时间: 2024-11-06 10:35:54