GIS二次开发:实验一 ArcGIS Engine 开发初步

实验一 ArcGIS Engine 开发初步

一、实验目的

  1. 掌握ArcGIS Engine的安装;
  2. 熟悉ArcGIS Engine中几个常用的控件;
  3. 搭建第一个简单的ArcGIS Engine 程序;
  4. 通过ICommand接口添加地图浏览工具。

二、实验仪器与设备

计算机、visual studio 软件、ArcGIS engine 开发包

三、实验内容与步骤

  1. ArcGIS engine安装及环境配置。
    (1)安装ArcGIS License Manager

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(2)安装ArcGIS Engine 10.2,选择以下路径中的ESRI.exe 点击安装:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(3)打开ArcGIS管理器导向,选择ArcGIS Engine浮动:
在这里插入图片描述

  1. 搭建简单的ArcGIS Engine 程序
    (1)启动Visual Studio 2012,创建gis3.1工程
    在这里插入图片描述

(2)选择需要添加的ArcGIS引用项,在【License Checking】选项页中选择需要的软件许可授权和扩展模块许可授权。
在这里插入图片描述

(3)在【工具箱】面板中找到【ArcGIS Windows Forms】选项卡,此选项卡中包含有ArcGIS Engine中所有的可视化控件,选择需要的控件添加到【gis3.1】窗体中。
在这里插入图片描述

(4)添加地图浏览工具,打开工具条属性,执行以下操作。
在这里插入图片描述

(5)选中TOCControl控件,单击鼠标右键,选择【属性】,弹出对话框,在【General】选项卡的“Buddy”下拉列表中选择与其绑定的MapControl地图控件,这样当程序运行时TOCControl控件才可以与地图控件进行联动。
在这里插入图片描述

(6)选中MapControl控件,单击鼠标右键,选择【属性】,弹出对话框,在对话框中选择程序运行时加载的*.mxd地图文档,点击【确定】按钮完成对*.mxd文档的关联。
在这里插入图片描述

  1. 地图浏览工具的添加
    (1)在窗口中添加自定义工具条及相应按钮:
    在这里插入图片描述

(2)分别实现对应按钮的事件响应代码:

/// <summary>
/// 工具条
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// 打开文件夹
private void buttonI_opendata_Click(object sender, EventArgs e)
{
    
    
    ICommand pcommand = new ControlsAddDataCommandClass();
    pcommand.OnCreate(axMapControl1.Object);
    pcommand.OnClick();
    updatalayernametoconbox();
}
/// <summary>
/// 默认鼠标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_default_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        axMapControl1.CurrentTool = null;
        axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
    }
    else
    {
    
    
        axPageLayoutControl1.CurrentTool = null;
        axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
    }
}
/// <summary>
/// 漫游
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_pan_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        ICommand pcommand = new ControlsMapPanToolClass();
        pcommand.OnCreate(axMapControl1.Object);
        axMapControl1.CurrentTool = pcommand as ITool;
    }
    else
    {
    
    
        ICommand pcommand = new ControlsMapPanToolClass();
        pcommand.OnCreate(axPageLayoutControl1.Object);
        axPageLayoutControl1.CurrentTool = pcommand as ITool;
    }
}
/// <summary>
/// 放大
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_zoomin_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        ICommand pcommand = new ControlsMapZoomInToolClass();
        pcommand.OnCreate(axMapControl1.Object);
        axMapControl1.CurrentTool = pcommand as ITool;
    }
    else
    {
    
    
        ICommand pcommand = new ControlsMapZoomInToolClass();
        pcommand.OnCreate(axPageLayoutControl1.Object);
        axPageLayoutControl1.CurrentTool = pcommand as ITool; 
    }
}
/// <summary>
/// 缩小
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_zoomout_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        ICommand pcommand = new ControlsMapZoomOutToolClass();
        pcommand.OnCreate(axMapControl1.Object);
        axMapControl1.CurrentTool = pcommand as ITool;
    }
    else            
    {
    
    
        ICommand pcommand = new ControlsMapZoomOutToolClass();
        pcommand.OnCreate(axPageLayoutControl1.Object);
        axPageLayoutControl1.CurrentTool = pcommand as ITool;
    }

}
/// <summary>
/// 全局
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_fullscreen_Click(object sender, EventArgs e)
{
    
               
        ICommand pcommand = new ControlsMapFullExtentCommandClass();
        pcommand.OnCreate(axMapControl1.Object);
        pcommand.OnClick();            
}
/// <summary>
/// 前一视图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_preview_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        ICommand pcommand = new ControlsMapZoomToLastExtentForwardCommandClass();
        pcommand.OnCreate(axMapControl1.Object);
        pcommand.OnClick();
    }
    else
    {
    
    
        ICommand pcommand = new ControlsMapZoomToLastExtentForwardCommandClass();
        pcommand.OnCreate(axPageLayoutControl1.Object);
        pcommand.OnClick();
 
    }
}
/// <summary>
/// 后一视图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_aftview_Click(object sender, EventArgs e)
{
    
    
    if (m_ControlsSynchronizer.ActiveViewType == "MapControl")
    {
    
    
        ICommand pcommand = new ControlsMapZoomToLastExtentBackCommandClass();
        pcommand.OnCreate(axMapControl1.Object);
        pcommand.OnClick();
    }
    else
    {
    
    
        ICommand pcommand = new ControlsMapZoomToLastExtentBackCommandClass();
        pcommand.OnCreate(axPageLayoutControl1.Object);
        pcommand.OnClick();
    }

}
/// <summary>
/// 测量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonI_measure_Click(object sender, EventArgs e)
{
    
    
    ICommand pcommand = new ControlsMapMeasureToolClass();
    pcommand.OnCreate(axMapControl1.Object);
    axMapControl1.CurrentTool = pcommand as ITool;
}
/// <summary>
/// 鼠标移动显示坐标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
    
    
    
    toolStripStatusLabel2.Text = "x=" + e.mapX.ToString() + ",y=" + e.mapY.ToString();
    if (axMapControl1.LayerCount != 0)
    {
    
    
        
        //ShowTips显示的要素类
        IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
        if (pFeatureLayer is IFeatureLayer)
        {
    
    
            pFeatureLayer.DisplayField = "DDMM"; //ShowTips显示的字段名称
            //pFeatureLayer.DisplayField = "Shape";
            //pFeatureLayer.DisplayField = "OBJECTID";
            //pFeatureLayer.DisplayField = "Shape_Leng";
            //pFeatureLayer.DisplayField = "Shape_Area";
            //将两个ShowTips属性设置为true
            pFeatureLayer.ShowTips = true;
            axMapControl1.ShowMapTips = true;
        }
    }

}

四、实验结果
1.文件加载
在这里插入图片描述

2.放大
在这里插入图片描述

3.缩小
在这里插入图片描述

4.全局
在这里插入图片描述

5.测量
在这里插入图片描述

五、实验心得与体会

1.学会了在Visual Studio中安装部署ArcGIS engine,并且使用ArcGIS控件创建一个小程序。
2.学会了使用ArcGIS控件创建一个工具条,以及自己创建一个工具条两种方法。
3.对ArcGIS engine的理解进一步加深。

猜你喜欢

转载自blog.csdn.net/chengzilhc/article/details/124557498