http://anshien.blog.163.com/blog/static/16996630820107309045137/
在GIS开发过程中,难免会遇到各种各样的需求,而作为程序员的我们就必须要想方设法把这些需求转换为功能实现,遇到奇怪的要求只能一边郁闷一边着手。。。
抱怨到此为止,由此入正题。之前有遇到MapControl与PageLayoutControl的同步问题,这倒不是什么难题,ArcGISEngine的SDK中有实例介绍。但这次是MapControl与GlobeControl的同步。经过一段时间的研究,终是找到了解决办法,虽然有些笨拙,但为后来者提供学习还是可以的,望见谅!以下是实例代码:
IScene scene = GlobeControl.Globe.GlobeDisplay.Scene;
ISceneViewer sceneViewer = GlobeControl.Globe.GlobeDisplay.ActiveViewer;
IGlobeCamera pGlobeCamera = sceneViewer.Camera as IGlobeCamera;
IGlobeViewUtil pGlobeViewUtil = pGlobeCamera as IGlobeViewUtil;
IEnvelope pEnvelope = new EnvelopeClass();
pGlobeViewUtil.QueryVisibleGeographicExtent(pEnvelope);//得到GlobeControl的Extent
IPoint minPoint = new PointClass();
minPoint = GetProjectPoint(pEnvelope.XMin, pEnvelope.YMin);//获得从投影变换后的得到的平面坐标
(minPoint as IZAware).ZAware = true;
minPoint .Z = pEnvelope.ZMin;
IPoint maxPoint = new PointClass();
maxPoint = GetProjectPoint(pEnvelope.XMax, pEnvelope.YMax);
(maxPoint as IZAware).ZAware = true;
maxPoint.Z = pEnvelope.ZMax;
IEnvelope GeoEnvelope = new EnvelopeClass();
//设置平面Extent
GetEnvelope(minPoint,maxPoint,out GeoEnvelope);
//将得到的Envelope赋值给MapControl
MapControl.ActiveView.Extent = GeoEnvelope;
MapControl.ActiveView.Activate(MapControl.hWnd);
MapControl.ActiveView.Refresh();
简单介绍这段程序的使用,当在TapControl中从GlobeControl到MapControl的切换时,以上的代码就能实现位置同步。
而从MapControl到GlobeControl即可用IGlobeCamera.SetToZoomToExtents方法就能够实现。