ArcEngine下GlobeControl與MapControl的二三維聯動

實現思路:2D—>3D,將當前MapControl的可視範圍設置爲GlobeControl中Extent屬性的值;3D--->2D,獲取當前GlobeControl的target和observer的Camera的BLH以及當前的圖形顯示範圍,並將其設置爲Mapcontrol的顯示範圍。中心點可取observer、target或者兩者的中心點都可。所有代碼以下:spa

   #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
      
相關文章
相關標籤/搜索