怎样在没有授权的状态下开发ArcGISEngine
怎样在没有授权的状态下开发ArcGIS Engine 102010年09月29日 下午 11:22很微妙的一点技巧。ArcGIS Engine 10的授权方式发生了变化,以前我经常安装好ArcGIS Desktop后直接进行ArcGIS Engine的授权进行开发,现在不能简单的采用这种方式了。
因为没有Developrt Kit的授权,所以ArcGIS Engine的Control在设计环境下是不好用的,总是提示未授权,但可以试着编译一下。编译了几个ArcObjectsNet中的示例程序,没有问题,但运行时却又不同的效果。有的程序运行是正常的(使用ArcGIS Desktop的授权),而有的提示授权错误。在排除了授权方式的不同后,很难找出运行失败的原因。
折腾了半天,有点眉目了。根据调试,出错的地方是
((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit();(不仅是这个控件,其他的也有可能发生的)
还是跟控件的使用相关,但为什么有的程序没有问题呢,比较一下这些程序的异同发现在.resx文件中的OcxState的value是有差别的,试着将axLicenseControl1和axMapControl1的OcxState修改成运行正常的程序中的value,呵呵,编译后运行正常了。不再深究其原因。
这样的话,这些控件只是不能可视化设计了(或者忍受不住弹出的未授权对话框以及定时关闭的风险),并不影响程序的编写以及编译运行。另外看WPF方式开发的程序没有直接使用控件进行可视化设计,兴许也是一种值得研究的方向。
最后,没有AGERuntime的授权也没关系,咱有AGD的授权啦~
怎样在没有授权的状态下开发ArcGIS Engine 10 - 22010年10月03日 下午 01:58上一篇是使用向导创建了MapControlApplication之后,修改已经创建完成的程序采用的方法。今天在新建了一个
的WindowsFormApplication之后,添加AGE的各个Control,在resx文件中根本不产生相关信息,可能是因为没有AGED授权的缘故。没关系,没有就没有吧,好像不影响程序的运行。在VS中进行窗口设计时状态如下图。
这个窗口很恐怖吧,所有的AGE控件上都有一堆文字提示你没有授权的问题。此外比较麻烦的是,系统不住的弹出未授权的警告信息(要想办法去掉,否则没办法玩)。
在开发过程中,如果使用了LicenseControl,大概一分钟左右,VS会提示你AGER没有授权,然后直接关闭VS。这个问题处理方法到也简单。实际上因为咱根本没有AGED授权,使用LicenseControl也是白搭,那就不要用了,采用Program的方
式来进行授权就好了。直接在Program.cs中Main函数一开始的地方加入代码(不知道怎样贴代码才会漂亮一点):
if (!RuntimeManager.Bind(ProductCode.Engine))
{
if (!RuntimeManager.Bind(ProductCode.Desktop))
{
MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
return;
}
}
AoInitialize aoi = new AoInitializeClass();
//more license choices could be included here
esriLicenseProductCode productCode
= esriLicenseProductCode.esriLicenseProductCodeArcInfo;
if (aoi.IsProductCodeAvailable(productCode) ==
esriLicenseStatus.esriLicenseAvailable)
{
aoi.Initialize(productCode);
}
注意在这里,使用esriLicenseProductCodeArcInfo
示使用ARC/INFO的授权来运行程序,咱没有AGER的授权。
因为没有AGED的授权,所有空间的属性页面中不提供对控件的属性设置了,如工具条根本就没有办法在上面添加工具。所有的属性设置及相应的一些操作都必须采用Program的方式来进行。如设置Buddy以及添加工具:
axTOCControl1.SetBuddyControl(axMapControl1);
axToolbarControl1.SetBuddyControl(axMapControl1);
//Add generic commands
axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map navigation commands
axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
//Add map inquiry commands
axToolbarControl1.AddItem("esriControls.ControlsMapIdentifyTool", -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapFindCommand", -1, -1,
false, 0, esriCommandStyles.esriCommandStyleIconOnly);
axToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", -1, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);
呵呵,这样编译一下程序也可以运行了,运行结果如下图:
咱穷人就这样使用上AGE了。