基于C#的ArcEngine二次开发教程(07):添加数据、视图缩放和全景视图的代码实现及分析

目录

1 两种接口

1.1 ICommand接口

1.2 ITool接口

2 代码实现与分析

2.1  数据添加功能

2.2 视图缩小和放大功能

2.3 全景视图

3 效果展示


界面设计接博文: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接口,点击后可直接使用,包括以下成员:

Read-only propertyBitmapThe bitmap that is used as the icon on this command.
Read-only propertyCaptionThe caption of this command.
Read-only propertyCategoryThe name of the category with which this command is associated.
Read-only propertyCheckedIndicates if this command is checked.
Read-only propertyEnabledIndicates if this command is enabled.
Read-only propertyHelpContextIDThe help context ID associated with this command.
Read-only propertyHelpFileThe name of the help file associated with this command.
Read-only propertyMessageThe statusbar message for this command.
Read-only propertyNameThe name of this commmand.
MethodOnClickOccurs when this command is clicked.
MethodOnCreateOccurs when this command is created.
Read-only propertyTooltipThe tooltip for this command.

1.2 ITool接口

ITool接口,需先激活然后在再使用

Read-only propertyCursorThe mouse pointer for this tool.
MethodDeactivateCauses the tool to no longer be the active tool.
MethodOnContextMenuContext menu event occured at the given xy location.
MethodOnDblClickOccurs when a mouse button is double clicked when this tool is active.
MethodOnKeyDownOccurs when a key on the keyboard is pressed when this tool is active.
MethodOnKeyUpOccurs when a key on the keyboard is released when this tool is active.
MethodOnMouseDownOccurs when a mouse button is pressed when this tool is active.
MethodOnMouseMoveOccurs when the mouse is moved when this tool is active.
MethodOnMouseUpOccurs when a mouse button is released when this tool is active.
MethodRefreshOccurs 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 效果展示

 

  • 8
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小薛引路

喜欢的读者,可以打赏鼓励一下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值