/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add OpenNewMapDocument.OnClick implementation //launch a new OpenFile dialog System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Map Documents (*.mxd)|*.mxd"; dlg.Multiselect = false; dlg.Title = "Open Map Document"; if (dlg.ShowDialog() == DialogResult.OK) { string docName = dlg.FileName; IMapDocument pMapDoc = new MapDocumentClass(); if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName)) { // 以下3.3.3.1代码 /* pMapControl.LoadMxFile(dlg.FileName, null, null); * pMapControl.ActiveView.Refresh(); * pMapDoc.Close(); */ // 以下3.3.3.5代码 pMapDoc.Open(docName, string.Empty); IMap map = pMapDoc.get_Map(0); pMapDoc.SetActiveView((IActiveView)map); pControlsSynchronizer.PageLayoutControl.PageLayout = pMapDoc.PageLayout; pControlsSynchronizer.ReplaceMap(map); pMapDoc.Close(); } } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { //launch a new OpenFile dialog OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Map Documents (*.mxd)|*.mxd"; dlg.Multiselect = false; dlg.Title = "Open Map Document"; if (dlg.ShowDialog() == DialogResult.OK) { string docName = dlg.FileName; IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName)) { mapDoc.Open(docName, string.Empty); // set the first map as the active view IMap map = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)map); m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout; m_controlsSynchronizer.ReplaceMap(map); mapDoc.Close(); m_sDocumentPath = docName; } } }
/// <summary> /// Opens mxd document. /// </summary> /// <param name="sMxdFilePath">The MXD file path.</param> public static void OpenDocument(string sMxdFilePath) { IMapDocument mapDocument = new MapDocumentClass(); if (mapDocument.get_IsPresent(sMxdFilePath) && !mapDocument.get_IsPasswordProtected(sMxdFilePath)) { mapDocument.Open(sMxdFilePath, ""); try { IMap map = mapDocument.get_Map(0); mapDocument.SetActiveView((IActiveView)map); //EnviVars.instance.Synchronizer.PageLayoutControl.PageLayout = mapDocument.PageLayout; //EnviVars.instance.Synchronizer.ReplaceMap(map); EnviVars.instance.MapControl.Map = map; EnviVars.instance.MainForm.Text = sMxdFilePath; } catch (Exception ex) { //_logger.Log(LogLevel.Error, EventType.UserManagement, null, ex); Log.WriteLog(typeof(MapAPI), ex); } finally { mapDocument.Close(); } } }
/// <summary> /// 打开地图文档 /// </summary> /// <param name="docFilePath">文档路径</param> public void OpenMapDocument(string docFilePath) { if (string.IsNullOrEmpty(docFilePath)) { return; } IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.IsPresent[docFilePath] && !mapDoc.IsPasswordProtected[docFilePath]) { mapDoc.Open(docFilePath, string.Empty); // set the first map as the active view IMap map = mapDoc.Map[0]; //设置地图为激活视图 mapDoc.SetActiveView((IActiveView)map); // PageLayoutControl.PageLayout = mapDoc.PageLayout; ReplaceMap(map); mapDoc.Close(); } else { MessageBox.Show(docFilePath + "is Invalid map!", "Information"); } }
public bool SaveMapDocument(IMxdContents pMxdContents, string sFileName, bool bOverwritePrompt, bool bUseRelativePaths, bool bCreateThumnbail, bool bSilent) { try { if (sFileName == null) { sFileName = ""; } if (pMxdContents == null) { MessageBox.Show("地图文档保存失败,Map 内容加载失败。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (string.IsNullOrEmpty(sFileName)) { SaveFileDialog dialog = new SaveFileDialog { DefaultExt = "mxd", FileName = "无标题", Filter = "地图文档 (*.mxd)|*.mxd", OverwritePrompt = bOverwritePrompt, Title = "保存地图到文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } sFileName = dialog.FileName; dialog = null; if (string.IsNullOrEmpty(sFileName)) { return(false); } } else if (((File.Exists(sFileName) & bOverwritePrompt) && !bSilent) && (Interaction.MsgBox("文件 " + sFileName + " 已存在。\r\n是否要替换?", MsgBoxStyle.YesNo, "确认替换") != MsgBoxResult.Yes)) { return(false); } if (File.Exists(sFileName)) { FileSystem.Kill(sFileName); } if (File.Exists(sFileName)) { MessageBox.Show("文件 " + sFileName + " 无法删除。\r\n共享冲突,文件正在使用。", "覆盖文件错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } IMapDocument document = null; document = new MapDocumentClass(); document.New(sFileName); document.ReplaceContents(pMxdContents); document.SetActiveView(pMxdContents.ActiveView); if (!document.get_IsMapDocument(sFileName)) { MessageBox.Show("文件 " + sFileName + " 无法保存。\r\n文件不是 MapDocument 文件。", "保存文件错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法保存。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(false); } document.Save(bUseRelativePaths, bCreateThumnbail); document.Close(); document = null; return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SaveMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public override bool LoadMap(string filePath) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath)) { mapDoc.Open(filePath, string.Empty); // set the first map as the active view IMap map = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)map); this._axLayoutCtrl.PageLayout = mapDoc.PageLayout; this._mapAndLayoutSync.ReplaceMap(map); mapDoc.Close(); this._mapFile = filePath; return true; } else { return false; } /* if (this._axMapCtrl.CheckMxFile(filePath)) { this._axMapCtrl.LoadMxFile(filePath, Type.Missing, Type.Missing); this._axMapCtrl.Enabled = true; this._mapFile = filePath; return true; } else { return false; } */ }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IPageLayoutControl3 pPageLayoutControl = null; try { if (m_hookHelper.Hook is IToolbarControl) { pPageLayoutControl = (IPageLayoutControl3)((IToolbarControl)m_hookHelper.Hook).Buddy; } //In case the container is MapControl else if (m_hookHelper.Hook is IPageLayoutControl3) { pPageLayoutControl = (IPageLayoutControl3)m_hookHelper.Hook; } else { MessageBox.Show("当前界面必须是PageLayoutControl界面!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { if (string.IsNullOrEmpty(m_strDocName)) { OpenFileDialog dlgFile = new OpenFileDialog();//以对话框选择文档路径 dlgFile.Title = "打开一个地图文档"; dlgFile.Filter = "Map Documents(*.mxd)|*.mxd"; if (dlgFile.ShowDialog() == DialogResult.OK) { m_strDocName = dlgFile.FileName; } } IMapDocument mapDoc = new MapDocumentClass(); //地图文档对象 IMap map = null; if (mapDoc.get_IsPresent(m_strDocName) && !mapDoc.get_IsPasswordProtected(m_strDocName)) { mapDoc.Open(m_strDocName, string.Empty); IMaps maps = new Maps(); for (int i = 0; i < mapDoc.MapCount; i++) { maps.Add(mapDoc.get_Map(i)); } // set the first map as the active view map = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)map); m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout; m_controlsSynchronizer.PageLayoutControl.Printer = mapDoc.Printer; m_controlsSynchronizer.PageLayoutControl.DocumentFilename = m_strDocName; //m_controlsSynchronizer.ReplaceMap(map); m_controlsSynchronizer.AddNewMaps(maps); mapDoc.Close(); m_strDocName = string.Empty; } ///////////////////////////// //关闭属性表 if (m_barTable.Visible == true) { if (m_AttributeRemove != null) { m_AttributeRemove.Clear(); m_AttributeRemove.Columns.Clear(); m_barTable.Visible = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "打开地图文档失败"); } }
protected void OpenPastureMapDoc(Pasture pasture) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(pasture.strMapDoc) && !mapDoc.get_IsPasswordProtected(pasture.strMapDoc)) { mapDoc.Open(pasture.strMapDoc, string.Empty); // set the first map as the active view m_pastureMap = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)m_pastureMap); mapDoc.Close(); } }
protected void OpenAdministrativeMapDoc(string adminMapDoc) { IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(adminMapDoc) && !mapDoc.get_IsPasswordProtected(adminMapDoc)) { mapDoc.Open(adminMapDoc, string.Empty); // set the first map as the active view m_adminMap = mapDoc.get_Map(0); mapDoc.SetActiveView((IActiveView)m_adminMap); mapDoc.Close(); m_mapcontrol.Map = m_adminMap; } }