ArcGIS Engine (一) 实现二三维地图联动

ArcGIS Engine (一) 实现二三维地图联动

1.效果

每次二维地图刷新时——>三维地图跟随
       三维地图鼠标抬起时——>二维地图跟随

2实现代码

在二维地图的axMapControl1_OnExtentUpdate事件中调用函数或在三维地图的鼠标抬起事件中调用函数。
   //图层更新联动3d-2d   
        private void Synchronization_2DTo3D()
        {
            IActiveView activeView = axGlobeControl1.Globe as IActiveView;
            activeView.Extent = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;
            activeView.Refresh();
        }
        private void Synchronization_3DTo2D()

        {

            IScene scene = axGlobeControl1.Globe.GlobeDisplay.Scene;

            ISceneViewer sceneViewer = axGlobeControl1.GlobeDisplay.ActiveViewer;

            IGlobeCamera globeCamera = sceneViewer.Camera as IGlobeCamera;

            IGlobeViewUtil globeViewUtil = globeCamera as IGlobeViewUtil;



            IEnvelope pEnv = new EnvelopeClass();

            globeViewUtil.QueryVisibleGeographicExtent(pEnv);//得到GlobeControl的Extent

            if (pEnv == null)

            {

                return;

            }



            IPoint observerPoint = new PointClass();

            IPoint targetPoint = new PointClass();

            //获取Target和observer的坐标

            GetObserverTarget(out observerPoint, out targetPoint);

            IPoint point = new PointClass();

            (point as IZAware).ZAware = true;

            point.X = (observerPoint.X + targetPoint.X) / 2;

            point.Y = (observerPoint.Y + targetPoint.Y) / 2;

            point.Z = (observerPoint.Z + targetPoint.Z) / 2;



            pEnv.CenterAt(point);



            axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds = pEnv;

            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);





        }
        private void GetObserverTarget(out IPoint ObserverPoint, out IPoint TargetPoint)

        {

            IGlobeDisplay m_GlobeDisplay = axGlobeControl1.Globe.GlobeDisplay;

            ISceneViewer pSceneViewer = m_GlobeDisplay.ActiveViewer;

            ICamera pCamera = pSceneViewer.Camera;

            IGlobeCamera pGlobeCamera = m_GlobeDisplay.ActiveViewer.Camera as IGlobeCamera;





            ObserverPoint = null;

            TargetPoint = null;



            //获取observer的BLH

            double obsLat, obsLon, obsAltKms;

            pGlobeCamera.GetObserverLatLonAlt(out obsLat, out obsLon, out obsAltKms);



            //获取target的BLH

            double tgtLat, tgtLon, tgtAltKms;

            pGlobeCamera.GetTargetLatLonAlt(out tgtLat, out tgtLon, out tgtAltKms);



            ObserverPoint = new PointClass();

            (ObserverPoint as IZAware).ZAware = true;

            ObserverPoint.PutCoords(obsLon, obsLat);

            ObserverPoint.Z = obsAltKms;



            TargetPoint = new PointClass();

            (TargetPoint as IZAware).ZAware = true;

            TargetPoint.PutCoords(tgtLon, tgtLat);

            TargetPoint.Z = tgtAltKms;

        }

你可能感兴趣的:(ArcGIS,Engine,arcgis,c#)