ArcGlobe三维开发之十九——GlobeControl与MapControl的二三维联动

实现思路:2D—>3D,将当前MapControl的可视范围设置为GlobeControl中Extent属性的值;3D--->2D,获取当前GlobeControl的target和observer的Camera的BLH以及当前的图形显示范围,并将其设置为Mapcontrol的显示范围。中心点可取observer、target或者二者的中心点均可。全部代码如下:

   #region 二三维切换及联动

        //3D视图
        private void tabItem_3D_Click (object sender,EventArgs e)
        {
            axToolbarControl_Map.Visible = false;
            axToolbarControl_Globe.Visible = true;
            axTOCControl_Globe.Visible = true;
            axTOCControl_Map.Visible = false;

            statusStripXYZ.Visible = true;
            statusStripXY.Visible = false;

            //2D—>3D联动
            IActiveView avtiveView = m_globeControl.Globe as IActiveView;
            avtiveView.Extent = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;
            avtiveView.Refresh();


        }
        //2D视图
        private void tabItem_2D_Click (object sender,EventArgs e)
        {
            axToolbarControl_Globe.Visible = false;
            axToolbarControl_Map.Visible = true;
            axTOCControl_Globe.Visible = false;
            axTOCControl_Map.Visible = true;
            statusStripXYZ.Visible = false;
            statusStripXY.Visible = true;

            Synchronization_3DTo2D();

        }
        //3D—>2D
        private void Synchronization_3DTo2D ()
        {
            IScene scene = m_globeControl.Globe.GlobeDisplay.Scene;
            ISceneViewer sceneViewer = m_globeControl.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);


        }
        //获取target和observer的坐标
        private void GetObserverTarget (out IPoint ObserverPoint,out IPoint TargetPoint)
        {
            IGlobeDisplay m_GlobeDisplay = m_globeControl.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;
        }
        #endregion
      

你可能感兴趣的:(ArcEngine,GIS,3DGIS,ArcGlobe开发)