赞
踩
个人总结梳理,顺便练练文笔,For me and for you like me!
我一直很认同古人所说的君子性非异也,善假于物也
,本文主要目的是告诉读者如何使用帮助来学习了解ArcEngine中的控件,怎样更好的阅读帮助。
使用Winfrom开发,经常会用到地图控件,了解常用的地图控件也是入门必修功课之一。
常用控件如下:
ArcMap和ArcEngine中控件的对应关系。
在vs中点击:视图-》工具箱-》ArcGIS Windows Forms。默认添加完这些控件,生成的控件实例对象命名都带前缀ax
,如axMapcContorl1
,axPageLayoutControl1
强烈建议参考李崇贵的《ArcGIS Engine 组件式开发及应用》学习,个人觉得他们写的还是不错的,需要资源的加Q群自取。
左侧为产品许可级别,右侧为许可扩展。
注意:左侧主许可是单选,如果选中了多个,则默认为第一个
。由于下面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控件主要用来加载显示地图数据,对应ArcMap中的数据视图。
MapControl类封装了Map对象,并提供相应的属性、方法、事件,它可以实现以下功能:
PageLayoutControl控件主要用于制图,对应ArcMap的布局视图,利用该控件可以方便地操作各种元素对象,以便产生精美的地图。
PageLayoutControl封装了PageLayout类,PageLayout提供了在布局视图中控制元素的属性和方法。除此之外,还有Printer属性用于处理地图打印时的系列设置、Page属性用于处理控件的页面效果、Element属性用于管理控件的地图元素。
关于MapControl和PageLayoutControl实现鹰眼功能
的代码网上有很多, 官方示例代码
TOCControl以树形结构显示其“伙伴控件“”的地图、图层和符号体系,该控件通过ITOCBuddy接口来访问其伙伴控件。
SymbologyControl主要是用来显示*.ServerStyle
(ArcEngine)和*.Style
(ArcMap)文件的符号目录。该控件允许用户选择一个符号应用到一部分程序上,比如图层的符号,Element的符号等等。
注意:
axSymbologyControl1.LoadStyleFile(@"myInstallLocation\ArcGIS\Engine10.2\Styles\ESRI.ServerStyle");
示例:
IStyleGalleryItem serverStyleGalleryItem = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass).GetSelectedItem();
System.Windows.Forms.MessageBox.Show(serverStyleGalleryItem.Name);
ToolbarControl需要绑定伙伴控件(MapControl/PageLayoutControl/GlobeControl/SceneControl),可以使用SetBuddyControl
方法动态绑定,ToolbarControl相当于是许多Commands、Tool Control、Menus、Palettes(调色板)的容器。
这块主要涉及到ToolbarControl、ToolbarItem、ToolbarMenu、CommandPool、Customizedialog、MissingCommand。
示例代码:
// 绑定伙伴控件
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);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。