ArcEngine Started - Controls the early experience

origin

Personal summary in order, the way to practice writing, For me and for you like me!

aims

I have been very much agree with the ancients said 君子性非异也,善假于物也, the main purpose of this article is to tell the reader how to use ArcEngine help to learn about the controls, how to better read the help.

  1. How to learn to use help, you can find relevant content and controls in Help.
  2. Each control is to understand why use, this article does not describe specific details.
  3. Learn control class which implements the interface and which methods.
  4. Tentative write the code, familiar with the controls.

Acquaintance

Brief introduction

Use Winfrom development, often used map control, understand the common map control is one of the compulsory introductory lessons.
Commonly used controls are as follows:

  • MapControl (map control, mainly used to display map)
  • PageLayoutControl (page layout controls, primarily used to print the output map)
  • GlobeControl (This article does not describe)
  • SceneControl (This article does not describe)
  • ToCControl (mainly used to display the list of layers (map data directory tree))
  • ToolbarControl (Map Toolbar provides some small tools)
  • SymbologyControl (map symbols Controls)

Resources

  1. Local resources (an article can not find help see)
    Here Insert Picture Description
  2. ArcGIS Engine Getting Started tutorial chapter _ _ Creating Engine applications
  3. Reference "ArcGIS Engine 10 developers update" first created in a desktop application (requires e-book can be added to Q group to download)

Knife Kaiushi

Correspondence between ArcMap and controls ArcEngine.
Here Insert Picture Description

Common Controls

Click vs: View - "Toolbox -" ArcGIS Windows Forms. After these controls default to generate the control instances are named with the prefix objects ax, such as axMapcContorl1,axPageLayoutControl1
Here Insert Picture Description


强烈建议参考李崇贵的《ArcGIS Engine 组件式开发及应用》学习,个人觉得他们写的还是不错的,需要资源的加Q群自取。


LicenseControl

Here Insert Picture Description
左侧为产品许可级别右侧许可扩展
注意:左侧主许可是单选,如果选中了多个,则默认为第一个。由于下面Basic、Standard和Advanced许可是Desktop产品的许可,而LicenseControl控件只能在Engine产品下使用,所以使用LicenseControl控件无法初始化Basic、Standard和Advanced许可,但可以使用代码进行初始化。右侧扩展许可是可以多选的。一个程序只能初始化一次许可,或者使用LicenseControl控件,或者使用代码,代码初始化许可如下:

绑定产品:

/* 这里是绑定一个产品,即Engine程序调用哪个安装产品下的资源,绑定Engine,即调用Engine安装目录的资源,绑定Desktop,
即调用Desktop安装目录下的资源,绑定EngineOrDesktop,即优先寻找机器上有没有安装Engine,有的话绑定Engine,
没有再绑定Desktop。而LicenseControl控件是初始化许可,这两者一定要加以区别。*/

if (!RuntimeManager.Bind(ProductCode.Engine))
{
    if (!RuntimeManager.Bind(ProductCode.Desktop))
    {
        MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
        return;
    }
}

初始化许可:

IAoInitialize m_AoInitialize = new AoInitializeClass(); 
esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
    licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
    if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
    {
        licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
        if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
        {
            XtraMessageBox.Show("获取ARCGIS授权失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }
    }
}
// 检出扩展许可
licenseStatus = m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
licenseStatus = m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);

个人经验:不建议使用LicenseControl控件,建议使用代码初始化许可。

MapControl

MapControl控件主要用来加载显示地图数据,对应ArcMap中的数据视图
Here Insert Picture Description
MapControl类封装了Map对象,并提供相应的属性、方法、事件,它可以实现以下功能:

  1. 地图显示;
  2. 地图的放大、缩小和漫游;
  3. 控制地图上鼠标显示的样式;
  4. 生成点线面等图形元素;
  5. 识别地图上选中的元素,并进行属性查询;
  6. 标注地图元素等;
  7. 监听地图事件;

PageLayoutControl

PageLayoutControl控件主要用于制图,对应ArcMap的布局视图,利用该控件可以方便地操作各种元素对象,以便产生精美的地图。
Here Insert Picture Description
PageLayoutControl封装了PageLayout类,PageLayout提供了在布局视图中控制元素的属性和方法。除此之外,还有Printer属性用于处理地图打印时的系列设置、Page属性用于处理控件的页面效果、Element属性用于管理控件的地图元素。

关于MapControl和PageLayoutControl实现鹰眼功能的代码网上有很多, 官方示例代码
Here Insert Picture Description

TOCControl

TOCControl以树形结构显示其“伙伴控件“”的地图、图层和符号体系,该控件通过ITOCBuddy接口来访问其伙伴控件。
Here Insert Picture Description

SymbologyControl

SymbologyControl主要是用来显示*.ServerStyle(ArcEngine)和*.Style(ArcMap)文件的符号目录。该控件允许用户选择一个符号应用到一部分程序上,比如图层的符号,Element的符号等等。
注意

  • *.Style文件只适用于Desktop产品。
  • *.ServerStyle文件适用于所有的产品。(位于:<install_location>\ArcGIS<EngineVersion>\Styles)
    Here Insert Picture Description
    加载ServerStyle文件
axSymbologyControl1.LoadStyleFile(@"myInstallLocation\ArcGIS\Engine10.2\Styles\ESRI.ServerStyle");

示例:

IStyleGalleryItem serverStyleGalleryItem = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass).GetSelectedItem();
System.Windows.Forms.MessageBox.Show(serverStyleGalleryItem.Name);

ToolbarControl

ToolbarControl need to bind buddy control (MapControl / PageLayoutControl / GlobeControl / SceneControl ), you can use SetBuddyControlthe method of dynamic binding, ToolbarControl the equivalent of many Commands, Tool Control, Menus, Palettes ( color palette) container.
Here Insert Picture Description
This mainly related to ToolbarControl, ToolbarItem, ToolbarMenu, CommandPool, Customizedialog, MissingCommand.
Here Insert Picture Description

Sample code:

// 绑定伙伴控件
axToolbarControl1.SetBuddyControl(axMapControl1);
// 添加打开文档命令
axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand",  - 1,  - 1, false, 0, esriCommandStyles.esriCommandStyleIconAndText);
//添加地图放大命令
axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool",  - 1,  - 1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
//添加地图缩小命令
axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool",  - 1,  - 1, false,  0, esriCommandStyles.esriCommandStyleIconOnly);
//添加地图全图命令
axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand",  - 1,  - 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);

Guess you like

Origin blog.csdn.net/yh0503/article/details/88377736