目录
界面设计接博文:https://blog.csdn.net/m1m2m3mmm/article/details/93376461#4%20%E5%B0%8F%E7%BB%93
本节讲解使用代码来实现添加数据、视图缩小、视图放大和全景视图功能需引用ESRI.ArcGIS.SystemUI和ESRI.ArcGIS.Controls名称空间
1 两种接口
1.1 ICommand接口
ICommand接口,点击后可直接使用,包括以下成员:
![]() | Bitmap | The bitmap that is used as the icon on this command. |
![]() | Caption | The caption of this command. |
![]() | Category | The name of the category with which this command is associated. |
![]() | Checked | Indicates if this command is checked. |
![]() | Enabled | Indicates if this command is enabled. |
![]() | HelpContextID | The help context ID associated with this command. |
![]() | HelpFile | The name of the help file associated with this command. |
![]() | Message | The statusbar message for this command. |
![]() | Name | The name of this commmand. |
![]() | OnClick | Occurs when this command is clicked. |
![]() | OnCreate | Occurs when this command is created. |
![]() | Tooltip | The tooltip for this command. |
1.2 ITool接口
ITool接口,需先激活然后在再使用
![]() | Cursor | The mouse pointer for this tool. |
![]() | Deactivate | Causes the tool to no longer be the active tool. |
![]() | OnContextMenu | Context menu event occured at the given xy location. |
![]() | OnDblClick | Occurs when a mouse button is double clicked when this tool is active. |
![]() | OnKeyDown | Occurs when a key on the keyboard is pressed when this tool is active. |
![]() | OnKeyUp | Occurs when a key on the keyboard is released when this tool is active. |
![]() | OnMouseDown | Occurs when a mouse button is pressed when this tool is active. |
![]() | OnMouseMove | Occurs when the mouse is moved when this tool is active. |
![]() | OnMouseUp | Occurs when a mouse button is released when this tool is active. |
![]() | Refresh | Occurs when a screen display in the application is refreshed. |
2 代码实现与分析
2.1 数据添加功能
查询帮助文档可知,ControlsAddDataCommandClass类可以浏览和添加数据集
我们需要先创建地图视图对象,然后执行点击操作,代码如下:
private void 添加数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
ICommand addData = new ControlsAddDataCommandClass();
addData.OnCreate(axMapControl1.Object);//钩子函数
addData.OnClick();
}
2.2 视图缩小和放大功能
代码思路为:先判断地图视图有无当前已激活的工具,若没有则调用ICommand和ITool接口创建对象,再将其添加到钩子函数中
用到的实现类:
视图缩小功能:
private void 视图缩小ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool == null)
{
ICommand icc;
ITool tool = new ControlsMapZoomOutToolClass();
axMapControl1.CurrentTool = tool;
icc = tool as ICommand;
icc.OnCreate(axMapControl1.Object);
icc.OnClick();
}
else
{
axMapControl1.CurrentTool = null;
}
}
视图放大功能:
private void 视图放大ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axMapControl1.CurrentTool == null)
{
ICommand icc;
ITool tool = new ControlsMapZoomInToolClass();
axMapControl1.CurrentTool = tool;
icc = tool as ICommand;
icc.OnCreate(axMapControl1.Object);
icc.OnClick();
}
else
{
axMapControl1.CurrentTool = null;
}
}
实现效果:点击菜单项之后,鼠标变成包含+、-的放大镜,实现视图缩放;再次点击,鼠标会返回箭头状态
2.3 全景视图
与数据添加类似,实现接口的类:
实现的代码:
private void 全景视图ToolStripMenuItem_Click(object sender, EventArgs e)
{
ICommand addData = new ControlsMapFullExtentCommandClass();
addData.OnCreate(axMapControl1.Object);//钩子函数
addData.OnClick();
}
3 效果展示