三種方法加載MXD文檔 (LoadMxFile方法和IMapDocument方法和IMapDocument方法)


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

 #region IMapDocument方法加載Mxd文檔文件

        private void iMapDocument方法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)) //檢查地圖文檔有效性
                    {
                        //將數據載入pMapDocument並與Map控件關聯
                        IMapDocument pMapDocument = new MapDocument();//using ESRI.ArcGIS.Carto;
                        pMapDocument.Open(pFileName, ""); //獲取Map中激活的地圖文檔 mainMapControl.Map = pMapDocument.ActiveView.FocusMap; mainMapControl.ActiveView.Refresh();
                    }
                    else
                    {
                        MessageBox.Show(pFileName + "是無效的地圖文檔!", "信息提示");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("打開地圖文檔失敗" + ex.Message);
            }
        }
        #endregion


 #region ControlsOpenDocCommandClass加載地圖

        private void controlsOpenDocCommandClass方法ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ICommand command = new ControlsOpenDocCommandClass(); command.OnCreate(mainMapControl.Object); command.OnClick();
        }

        #endregion

 

 
         

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM