AE地图文档的操作,新建打开保存另存为地图文档的实例
2013-12-04 22:55
429 查看
一个简单的实例,AE地图文档的一些操作,包括新建,打开,保存,另存为地图文档等操作。
功能介绍:新建地图文档,新建之前判断当前是否存在地图文档,如存在则提示是否保存,点击是保存当前文档并新建空白文档;点击否则直接新建地图文档。
打开地图文档,打开一个新的地图文档。如果当前存在地图文档则直接重新加载新打开的地图文档。
保存地图文档,保存当前的地图文档。
另存为地图文档,将当前地图文档另存为一个新的地图文档。
开发环境:ArcObject10.1,VS2010
代码如下:
其中,新建地图文档CreateNewDocument类的代码:
源代码完整实例下载地址:MapDocumentOperation.rar
功能介绍:新建地图文档,新建之前判断当前是否存在地图文档,如存在则提示是否保存,点击是保存当前文档并新建空白文档;点击否则直接新建地图文档。
打开地图文档,打开一个新的地图文档。如果当前存在地图文档则直接重新加载新打开的地图文档。
保存地图文档,保存当前的地图文档。
另存为地图文档,将当前地图文档另存为一个新的地图文档。
开发环境:ArcObject10.1,VS2010
代码如下:
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { //如果当前没有图层,则不操作 if (axMapControl1.Map.LayerCount == 0) { } else { ICommand command = new CreateNewDocument(); command.OnCreate(axMapControl1.Object); command.OnClick(); } } private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { ICommand command = new ControlsOpenDocCommandClass(); command.OnCreate(axMapControl1.Object); command.OnClick(); } private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { string m_currentMapDocument = axMapControl1.DocumentFilename; if (axMapControl1.Map.LayerCount == 0) { MessageBox.Show("没有地图文档需要保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } //execute Save Document command if (axMapControl1.CheckMxFile(m_currentMapDocument)) { //create a new instance of a MapDocument IMapDocument mapDoc = new MapDocumentClass(); mapDoc.Open(m_currentMapDocument, string.Empty); //Make sure that the MapDocument is not readonly if (mapDoc.get_IsReadOnly(m_currentMapDocument)) { MessageBox.Show("Map document is read only!"); mapDoc.Close(); return; } //Replace its contents with the current map mapDoc.ReplaceContents((IMxdContents)axMapControl1.Map); //save the MapDocument in order to persist it mapDoc.Save(mapDoc.UsesRelativePaths, false); //close the MapDocument mapDoc.Close(); MessageBox.Show("保存地图文档成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(m_currentMapDocument + "不是有效的地图文档!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { if (axMapControl1.Map.LayerCount == 0) { MessageBox.Show("没有地图文档需要保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } try { ICommand command = new ControlsSaveAsDocCommandClass(); command.OnCreate(axMapControl1.Object); command.OnClick(); MessageBox.Show("另存为地图文档成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); }
其中,新建地图文档CreateNewDocument类的代码:
/// <summary> /// Summary description for CreateNewDocument. /// </summary> public class CreateNewDocument : BaseCommand { private IHookHelper m_hookHelper = null; //constructor public CreateNewDocument() { //update the base properties base.m_category = ".NET Samples"; base.m_caption = "NewDocument"; base.m_message = "Create a new map"; base.m_toolTip = "Create a new map"; base.m_name = "DotNetTemplate_NewDocumentCommand"; } #region Overridden Class Methods /// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (m_hookHelper == null) m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; } /// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IMapControl3 mapControl = null; //get the MapControl from the hook in case the container is a ToolbarControl if (m_hookHelper.Hook is IToolbarControl) { mapControl = (IMapControl3)((IToolbarControl)m_hookHelper.Hook).Buddy; } //In case the container is MapControl else if (m_hookHelper.Hook is IMapControl3) { mapControl = (IMapControl3)m_hookHelper.Hook; } else { //MessageBox.Show("Active control must be MapControl!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBox.Show("必须是MapControl控件!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //check to see if there is an active edit session and whether edits have been made DialogResult result; IEngineEditor engineEditor = new EngineEditorClass(); if ((engineEditor.EditState == esriEngineEditState.esriEngineStateEditing) && (engineEditor.HasEdits() == true)) { //result = MessageBox.Show("Would you like to save your edits", "Save Edits", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); result = MessageBox.Show("是否保存编辑", "保存编辑", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case DialogResult.Cancel: return; case DialogResult.No: engineEditor.StopEditing(false); break; case DialogResult.Yes: engineEditor.StopEditing(true); break; } } //allow the user to save the current document //DialogResult res = MessageBox.Show("Would you like to save the current document?", "AoView", MessageBoxButtons.YesNo, MessageBoxIcon.Question); DialogResult res = MessageBox.Show("是否保存当前地图文档?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { //launch the save command ICommand command = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_hookHelper.Hook); command.OnClick(); } //create a new Map IMap map = new MapClass(); map.Name = "Map"; //assign the new map to the MapControl mapControl.DocumentFilename = string.Empty; mapControl.Map = map; } #endregion }
源代码完整实例下载地址:MapDocumentOperation.rar
相关文章推荐
- C#中操作Word(2)—— 新建、打开、保存和关闭文档
- C#中操作Excel(2)—— 新建、打开、保存和关闭Excel文档
- Word 2010基本操作——新建文档、保存文档
- ArcEngine数据操作之地图文档数据保存
- java实现记事本基本功能:新建、打开、保存、另存为、退出、替换、全部替换、复制、剪切、粘贴、全选、获取当前时间日期、修改字体、颜色、自动换行等
- AE保存地图文档—锁定冲突异常
- AE+地图文档基本操作
- Qt 文本文件的打开、新建、保存以及另存为
- 为什么新建文本文档中输入“联通”保存,在打开时就是一个废电池的样子?
- ArcEngine数据操作之地图文档数据保存
- richTextBox实现带格式word文档的打开、保存、另存为.
- ae 打开地图文档
- 【QT】QT从零入门教程(五):图像文件操作 [新建打开保存]
- SVG实例--svg编辑器---(打开,保存,新建,拖动)
- Qt 文件的新建、打开、保存、另存为 (改进版本)
- VC 2010 + MFC:自定义文档视图框架,去除新建、保存、打开等菜单功能,让文档程序个性化
- ArcEngine数据操作之地图文档数据保存
- (转)C#操作Excel(创建、打开、读写、保存)几种方法的总结
- 使用XmlDocument操作XML进行查询、增加、修改、删除、保存应用的实例(转载)
- 百度地图Api进阶教程-地图鼠标左右键操作实例和鼠标样式6.html