//保存地图文档 public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl) { if (axMapControl == null) { return; } string m_mapDocumentName = axMapControl.DocumentFilename; if (axMapControl.CheckMxFile(m_mapDocumentName)) { //新建地图文档接口 IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //确定文档非只读文件 if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //用当前地图替换文档内容 mapDoc.ReplaceContents((IMxdContents)axMapControl.Map); //保存文档 mapDoc.Save(mapDoc.UsesRelativePaths, false); //关闭文档 mapDoc.Close(); } }
/// <summary> /// 确定之后将文档进行默认保存 /// </summary> /// <param name="mapControlDefault">当前视图mapcontrol</param> /// <returns></returns> public static bool SaveAsMxd(string saveAsPath, IMapControlDefault mapControlDefault, bool useRelativePath) { IMxdContents pMxdContents; pMxdContents = mapControlDefault.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(mapControlDefault.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdContents); pMapDocument.SaveAs(saveAsPath, useRelativePath, false); pMapDocument.Close(); return(true); }
/// <summary> /// 确定之后将文档进行默认保存 /// </summary> /// <param name="mapControlDefault">当前视图mapcontrol</param> /// <returns></returns> public static bool SaveInMxd(IMapControlDefault mapControlDefault) { IMxdContents pMxdContents; pMxdContents = mapControlDefault.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(mapControlDefault.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdContents); try { pMapDocument.Save(true, true); return true; } catch { //MessageBox.Show("当前的文档文件发生共享冲突!请关闭其他打开该文档的应用。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } }
void IGMap.SaveMxd() { if (this._mapHook.CheckMxFile(this._mapHook.DocumentFilename)) { //string a=((IMapDocument)this._mapHook).DocumentFilename; //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(this._mapHook.DocumentFilename, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(this._mapHook.DocumentFilename)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)this._mapHook.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
private void menuSaveDoc_Click(object sender, EventArgs e) { //execute Save Document command if (m_mapControl.CheckMxFile(m_mapDocumentName)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("地图文件已经准备完毕!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } }
/// <summary> /// Save document menu event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks>Save the current MapDocument</remarks> private void menuSaveDoc_Click(object sender, System.EventArgs e) { //make sure that the current MapDoc is valid first if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName)) { //create a new instance of a MapDocument class IMapDocument mapDoc = new MapDocumentClass(); //Open the current document into the MapDocument mapDoc.Open(m_documentFileName, string.Empty); //Replace the map with the one of the PageLayout mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout); //save the document mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } }
/// <summary> /// 保存mxd文档 /// mapControl为地图控件的名称 /// 日期2013-12-13 /// lntu_GISer1 /// </summary> public void SaveMxdFile(AxMapControl mapControl) { IMxdContents pMxdC; pMxdC = mapControl.ActiveView.FocusMap as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); if (mapControl.DocumentFilename != null) { pMapDocument.Open(mapControl.DocumentFilename, ""); pMapDocument.ReplaceContents(pMxdC); if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename)) { MessageBox.Show("当前地图文档为只读文档!"); return; } try { pMapDocument.Save(true, true); MessageBox.Show("地图文档保存成功!"); } catch (Exception e) { MessageBox.Show(e.Message); } } //用当前的文件路径设置保存文件 }
public static void SaveDocument2(AxMapControl axMapControl1) { try { //判断pMapDocument是否为空, //获取pMapDocument对象 IMxdContents pMxdC; pMxdC = axMapControl1.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(axMapControl1.DocumentFilename, ""); IActiveView pActiveView = axMapControl1.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); if (pMapDocument == null) return; //检查地图文档是否是只读 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("本地图文档是只读的,不能保存!"); return; } //根据相对的路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("地图文档保存成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// /// </summary> private void saveMapDocument(AxMapControl pAxMapControl) { IMxdContents pMxdC; pMxdC = pAxMapControl.Map as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(pAxMapControl.DocumentFilename, ""); IActiveView pActiveView = pAxMapControl.Map as IActiveView; pMapDocument.ReplaceContents(pMxdC); if (pMapDocument == null) return; //检查地图文档是否是只读 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("本地图文档是只读的,不能保存!"); return; } //根据相对的路径保存地图文档 pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("地图文档保存成功!"); }
// File menu items void fileToolStripMenuItems_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null) return; ICommand command = null; string itemName = menuItem.Name; switch (itemName) { case "newDocToolStripMenuItem": command = new CreateNewDocCmd(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "openDocToolStripMenuItem": command = new ControlsOpenDocCommandClass(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "saveasStripMenuItem": command = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_MapControl.Object); command.OnClick(); break; case "saveDocToolStripMenuItem": if (m_MapControl.CheckMxFile(m_DocmentFileName)) { IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_DocmentFileName, string.Empty); if (!mapDoc.get_IsReadOnly(m_DocmentFileName)) { mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map); mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); } else MessageBox.Show("Cann't be save because of read-only document"); } break; case "exitDocToolStripMenuItem": DialogResult res = MessageBox.Show("Whether to save the current document?", "AOView", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Yes) { command = new ControlsSaveAsDocCommandClass(); command.OnCreate(axMapControl1.Object); command.OnClick(); } Application.Exit(); break; default: break; } }
public override bool SaveMap(string filePath) { IMapDocument mapDocument = new MapDocumentClass(); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } mapDocument.New(filePath); mapDocument.ReplaceContents((IMxdContents)this._axMapCtrl.Map); mapDocument.Save(mapDocument.UsesRelativePaths, true); mapDocument.Close(); return true; }
public void OnClick() { //// 首先确认当前地图文档是否有效 //if (null != m_pageLayoutControl.DocumentFilename && m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename)) //{ //// 创建一个新的地图文档实例 //IMapDocument mapDoc = new MapDocumentClass(); // 打开当前地图文档 //mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty); // 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分 //mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout); // 保存地图文档 //mapDoc.Save(mapDoc.UsesRelativePaths, false); //mapDoc.Close(); //m_mapDocument = this.hk.Document; //if (m_mapDocument.get_IsReadOnly(m_mapDocument.DocumentFilename)) //{ // MessageBox.Show("This map document is read only!"); // return; //} //m_mapDocument.Save(m_mapDocument.UsesRelativePaths, true); //MessageBox.Show("Changes saved successfully!"); //execute Save Document command //m_mapDocumentName = m_mapControl.DocumentFilename; if (m_mapControl.DocumentFilename != null && m_mapControl.CheckMxFile(m_mapDocumentName)) { //m_mapControl.CheckMxFile(m_mapDocumentName); //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_mapDocumentName, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_mapDocumentName)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); } else { cmd = new ControlsSaveAsDocCommandClass(); cmd.OnCreate(this.m_mapControl); cmd.OnClick(); } }