AE+C#控制Globe操作范围
转自:http://www.gisall.com/html/72/124272-6934.html
在实际的Globe操作过程中,都希望能够控制当前场景的范围,即使是误操作超出了范围也能够快速的自动的回到初始的范围。以下代码根据图层的范围控制显示操作的范围,一旦超出图层的范围,根据重绘事件监听,将当前地图范围重置到初始化范围。
系统环境:Win7 64位旗舰版
GIS环境:ArcEngine 10 sp4
开发环境:VS 2012 SP1 C#
1、在frmMain主窗体中声明IGlobeDisplayEvents_Event事件
private IGlobeDisplayEvents_Event m_pGlobeDisplayEvents = null;
2、在窗体初始化的时候,对m_pGlobeDisplayEvents也进行初始化
public frmMain()
{
InitializeComponent();
IGlobe pGlobe = globeCtrl3D.Globe;// globeCtrl3D为Globe控件
m_pGlobeDisplayEvents = pGlobe.GlobeDisplay as IGlobeDisplayEvents_Event;
m_pGlobeDisplayEvents.AfterDraw += new IGlobeDisplayEvents_AfterDrawEventHandler(m_pGlobeDisplayEvents_AfterDraw);
}
3、重写m_pGlobeDisplayEvents_AfterDraw事件
public void 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;
// 以下判断当前操作是否在图层范围内,高度控制在0至20公里(可以根据实际情况设置,此时为地上模式;如果想要地下模式可以将其改为负数)
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;
}
}
4、App.Config中的初始化参数为
<appSettings>
<!--初始化的位置-->
<add key="ObserverLatDD" value="-0.056946961416494392" />
<add key="ObserverLonDD" value="121.49905414870099" />
<add key="ObserverAltKMs" value="3.9120639485526882" />
<add key="TargetLatDD" value="-0.028060602957429747" />
<add key="TargetLonDD" value="121.49892786453003" />
<add key="TargetAltKMs" value="0.5625919130259821" />
……