关闭

AE+C#控制Globe操作范围

标签: ArcGISesri
750人阅读 评论(0) 收藏 举报
分类:

在实际的Globe操作过程中,都希望能够控制当前场景的范围,即使是误操作超出了范围也能够快速的自动的回到初始的范围。以下代码根据图层的范围控制显示操作的范围,一旦超出图层的范围,根据重绘事件监听,将当前地图范围重置到初始化范围。

 

    系统环境:Win7 64位旗舰版

       GIS环境:ArcEngine 10 sp4

    开发环境:VS 2012 SP1C#

 

1、在frmMain主窗体中声明IGlobeDisplayEvents_Event事件

 

privateIGlobeDisplayEvents_Eventm_pGlobeDisplayEvents = null;

 

2、在窗体初始化的时候,对m_pGlobeDisplayEvents也进行初始化

 

        public frmMain()

        {

           InitializeComponent();

 

            IGlobe pGlobe = globeCtrl3D.Globe;//globeCtrl3DGlobe控件

            m_pGlobeDisplayEvents= pGlobe.GlobeDisplay asIGlobeDisplayEvents_Event;

           m_pGlobeDisplayEvents.AfterDraw += newIGlobeDisplayEvents_AfterDrawEventHandler(m_pGlobeDisplayEvents_AfterDraw);

           

        }

 

3、重写m_pGlobeDisplayEvents_AfterDraw事件

 

        publicvoid m_pGlobeDisplayEvents_AfterDraw(ISceneViewer pViewer)

        {

            try

            {

                IGlobeCamera pGlobeCamera =globeCtrl3D.GlobeCamera;

                double dObserverLatDD = 0.0;

                double dObserverLonDD = 0.0;

                double dObserverAltKMs = 0.0;

 

               pGlobeCamera.GetObserverLatLonAlt(out dObserverLatDD, out dObserverLonDD, out dObserverAltKMs);

 

                ILayer layer = Common.GlobeUtil.getLayerFromScene(globeCtrl3D.GlobeDisplay.Scene,"bj");//bj为要控制范围的图层,getLayerFromScene为在GlobeControl中获取相应图层的函数,这里不再赘述

                IEnvelope pInitEnvelope =layer.AreaOfInterest;

                double dXMin = pInitEnvelope.XMin;

                double dXMax = pInitEnvelope.XMax;

                double dYMin = pInitEnvelope.YMin;

                double dYMax = pInitEnvelope.YMax;

                  // 以下判断当前操作是否在图层范围内,高度控制在020公里(可以根据实际情况设置,此时为地上模式;如果想要地下模式可以将其改为负数)

                if ((dObserverLatDD < dYMin) || (dObserverLatDD> dYMax) || (dObserverLonDD < dXMin) || (dObserverLonDD > dXMax)

                    ||(dObserverAltKMs > 20) || (dObserverAltKMs < 0))

                {// 以下为获取初始化的操作范围,该范围设置在App.Config

                    double dInitObserverLatDD = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["ObserverLatDD"]);

                    double dInitObserverLonDD = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["ObserverLonDD"]);

                    double dInitObserverAltKMs = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["ObserverAltKMs"]);

                    double dInitTargetLatDD = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["TargetLatDD"]);

                    double dInitTargetLonDD = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["TargetLonDD"]);

                    double dInitTargetAltKMs = Convert.ToDouble(System.Configuration.ConfigurationSettings.AppSettings["TargetAltKMs"]);

 

                   pGlobeCamera.SetObserverLatLonAlt(dInitObserverLatDD,dInitObserverLonDD, dInitObserverAltKMs);

                   pGlobeCamera.SetTargetLatLonAlt(dInitTargetLatDD, dInitTargetLonDD,dInitTargetAltKMs);

                    globeCtrl3D.GlobeDisplay.RefreshViewers();

                }

            }

            catch (Exception ex)

            {

                string msg = ex.Message;

            }

        }

 

4App.Config中的初始化参数为

 

  <appSettings>

    <!--初始化的位置-->

    <addkey="ObserverLatDD"value="-0.056946961416494392" />

    <addkey="ObserverLonDD"value="121.49905414870099" />

    <addkey="ObserverAltKMs"value="3.9120639485526882" />

    <addkey="TargetLatDD"value="-0.028060602957429747" />

    <addkey="TargetLonDD"value="121.49892786453003" />

    <addkey="TargetAltKMs"value="0.5625919130259821" />

……

 

5、以上完成在GlobeControl中控制可操作的范围,如果超出了自动恢复到初始位置。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:418124次
    • 积分:7002
    • 等级:
    • 排名:第3435名
    • 原创:292篇
    • 转载:3篇
    • 译文:1篇
    • 评论:36条
    最新评论