ArcGIS Engine 地图刷新失败的奇怪BUG
ArcGIS Engine算是我的传统艺能,是我学编程后第一个项目使用的GIS开发平台,毕业后用了两年,后来荒废了很久,后来发现AE的项目竟然只有我能做了,不得已捡起来,谁能想到能在地图刷新这样的小功能上还遇到坑。我的代码如下,注释大多是写博客的时候加的:
//地图操作恢复默认 _mapOperate = MapOperate.Default; //当前图形清空 _pGeometry = null; //光标形态恢复默认 this.MapControl_Main.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; //清除选择要素项 this.MapControl_Main.Map.ClearSelection(); //清除临时图形 this.MapControl_Main.ActiveView.GraphicsContainer.DeleteAllElements(); //刷新地图 this.MapControl_Main.Refresh(esriViewDrawPhase.esriViewAll, null, null); //清理系统界面的其他控件 this.ClearControls(); //如果加载了历史数据对比,则卸载历史数据 this.UnloadHistoryMap(); //恢复默认状态,加载临时库 UC_TempData uc_tempData = new UC_TempData(); //系统界面添加临时数据操作控件 this.AddLeftControl(uc_tempData);
|
代码一步步执行没有报错,光标可以恢复默认,界面上的控件重置了,选择实际上清空了,临时图形实际上删除了,但是因为地图不刷新,所以地图看起来不会有任何变化,手动移动一下地图,就会发现实际上都是成功执行了的。
然而,给代码稍微改一下,给地图刷新放在最后,就完全没有问题了。
_mapOperate = MapOperate.Default; _pGeometry = null; this.MapControl_Main.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
this.ClearControls(); this.UnloadHistoryMap(); UC_TempData uc_tempData = new UC_TempData(); this.AddLeftControl(uc_tempData);
this.MapControl_Main.Map.ClearSelection(); this.MapControl_Main.ActiveView.GraphicsContainer.DeleteAllElements(); this.MapControl_Main.Refresh(esriViewDrawPhase.esriViewAll, null, null);
|
至于什么原因就不知道了,猜测是Arcgis Engine 10.2的地图刷新当跟其他的界面刷新重绘碰在一起的时候会发生BUG,不知道其他版本有没有,就此记录一下。