首页
Web开发
Windows程序
编程语言
数据库
移动开发
系统相关
微信
其他好文
会员
首页
>
其他好文
> 详细
Arcengine编辑代码
时间:
2015-07-26 05:58:44
阅读:
758
评论:
0
收藏:
0
[点我收藏+]
标签:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
namespace Demo2
{
public sealed partial class MainForm : Form
{
#region private members
private IMapControl3 m_mapControl = null;
private string m_mapDocumentName = string.Empty;
private IToolbarMenu m_toolbarMenu;
#endregion
#region class constructor
public MainForm()
{
InitializeComponent();
}
#endregion
private void MainForm_Load(object sender, EventArgs e)
{
m_mapControl = (IMapControl3) axMapControl1.Object;
//Load the Data into the MapControl1
string sFilePath = @"C:ConferenceDataDemo Editing.mxd";
if (m_mapControl.CheckMxFile(sFilePath))
{
m_mapControl.LoadMxFile(sFilePath, null, null);
}
else
MessageBox.Show(sFilePath + " is not a valid ArcMap document");
#region setup toolbar visibility
menuSaveDoc.Enabled = false;
editingToolStripMenuItem.Checked = true;
inkToolStripMenuItem.Checked = false;
GenericToolStripMenuItem.Checked = false;
navigationToolStripMenuItem.Checked = true;
axEditorToolbar.Visible = true;
axNavigationToolbar.Visible = true;
axExtraEditorToolbar.Visible = false;
axInkToolbar.Visible = false;
#endregion
//EditorToolbar
axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingAttributeCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsEditingSketchPropertiesCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//ExtraEditorToolbar
axExtraEditorToolbar.AddItem(new EditPropertiesCmd(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCutCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsEditingPasteCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsEditingCopyCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axExtraEditorToolbar.AddItem("esriControls.ControlsEditingClearCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Create a popup menu
m_toolbarMenu = new ToolbarMenuClass();
m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
//Share the Command Pool
m_toolbarMenu.CommandPool = axEditorToolbar.CommandPool;
}
#region Main Menu event handlers
private void menuNewDoc_Click(object sender, EventArgs e)
{
//execute New Document command
ICommand command = new CreateNewDocument();
command.OnCreate(m_mapControl.Object);
command.OnClick();
}
private void menuOpenDoc_Click(object sender, EventArgs e)
{
//execute Open Document command
ICommand command = new ControlsOpenDocCommandClass();
command.OnCreate(m_mapControl.Object);
command.OnClick();
}
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("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();
}
}
private void menuSaveAs_Click(object sender, EventArgs e)
{
//execute SaveAs Document command
ICommand command = new ControlsSaveAsDocCommandClass();
command.OnCreate(m_mapControl.Object);
command.OnClick();
}
private void menuExitApp_Click(object sender, EventArgs e)
{
//exit the application
Application.Exit();
}
#endregion
//listen to MapReplaced evant in order to update the statusbar and the Save menu
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
//get the current document name from the MapControl
m_mapDocumentName = m_mapControl.DocumentFilename;
//if there is no MapDocument, diable the Save menu and clear the statusbar
if (m_mapDocumentName == string.Empty)
{
menuSaveDoc.Enabled = false;
statusBarXY.Text = string.Empty;
}
else
{
//enable the Save manu and write the doc name to the statusbar
menuSaveDoc.Enabled = true;
statusBarXY.Text = Path.GetFileName(m_mapDocumentName);
}
}
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
statusBarXY.Text = string.Format("{0}, {1} {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));
}
private void editingToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axEditorToolbar.Visible == false)
{
axEditorToolbar.Visible = true;
editingToolStripMenuItem.Checked = true;
}
else
{
axEditorToolbar.Visible = false;
editingToolStripMenuItem.Checked = false;
}
}
private void inkToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axInkToolbar.Visible == false)
axInkToolbar.Visible = true;
else
axInkToolbar.Visible = false;
}
private void navigationToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axNavigationToolbar.Visible == false)
axNavigationToolbar.Visible = true;
else
axNavigationToolbar.Visible = false;
}
private void bookmarksToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axExtraEditorToolbar.Visible == false)
axExtraEditorToolbar.Visible = true;
else
axExtraEditorToolbar.Visible = false;
}
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 2) m_toolbarMenu.PopupMenu(e.x, e.y, axMapControl1.hWnd);
}
}
}
Arcengine编辑代码
标签:
原文地址:http://www.cnblogs.com/gisoracle/p/4676941.html
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年07月29日 (22)
2021年07月28日 (40)
2021年07月27日 (32)
2021年07月26日 (79)
2021年07月23日 (29)
2021年07月22日 (30)
2021年07月21日 (42)
2021年07月20日 (16)
2021年07月19日 (90)
2021年07月16日 (35)
周排行
更多
分布式事务
2021-07-29
OpenStack云平台命令行登录账户
2021-07-29
getLastRowNum()与getLastCellNum()/getPhysicalNumberOfRows()与getPhysicalNumberOfCells()
2021-07-29
【K8s概念】CSI 卷克隆
2021-07-29
vue3.0使用ant-design-vue进行按需加载原来这么简单
2021-07-29
stack栈
2021-07-29
抽奖动画 - 大转盘抽奖
2021-07-29
PPT写作技巧
2021-07-29
003-核心技术-IO模型-NIO-基于NIO群聊示例
2021-07-29
Bootstrap组件2
2021-07-29
友情链接
兰亭集智
国之画
百度统计
站长统计
阿里云
chrome插件
新版天听网
关于我们
-
联系我们
-
留言反馈
© 2014
mamicode.com
版权所有 联系我们:gaon5@hotmail.com
迷上了代码!