分类: ArcEngine
- 使用globe和scene控件开发时,要实现像桌面版arcglobe和arcscene中使用鼠标中键进行缩放的功能,需要自己重载OnMouseWheel事件,实现代码如下:
- scene控件下的
- private void SceneControl_OnMouseWheel(object sender, MouseEventArgs e)
- {
- try
- {
- System.Drawing.Point pSceLoc = m_SceneCtrl.PointToScreen(this.m_SceneCtrl.Location);
- System.Drawing.Point Pt = this.PointToScreen(e.Location);
- if (Pt.X < pSceLoc.X || Pt.X > pSceLoc.X + m_SceneCtrl.Width || Pt.Y < pSceLoc.Y || Pt.Y > pSceLoc.Y + m_SceneCtrl.Height)
- {
- return;
- }
- double scale = 0.2;
- if (e.Delta < 0) scale = -0.2;
- ICamera pCamera = m_SceneCtrl.Camera;
- IPoint pPtObs = pCamera.Observer;
- IPoint pPtTar = pCamera.Target;
- pPtObs.X += (pPtObs.X - pPtTar.X) * scale;
- pPtObs.Y += (pPtObs.Y - pPtTar.Y) * scale;
- pPtObs.Z += (pPtObs.Z - pPtTar.Z) * scale;
- pCamera.Observer = pPtObs;
- m_SceneCtrl.SceneGraph.RefreshViewers();
- }
- catch
- {
- }
- }
- <pre name="code" class="csharp">globe控件下的
- private void axGlobeControl1_OnMouseWheel(object sender, MouseEventArgs e)
- {
- try
- {
- System.Drawing.Point pSceLoc = axGlobeControl1.PointToScreen(axGlobeControl1.Location);
- System.Drawing.Point Pt = this.PointToScreen(e.Location);
- if (Pt.X < pSceLoc.X || Pt.X > pSceLoc.X + axGlobeControl1.Width || Pt.Y < pSceLoc.Y || Pt.Y > pSceLoc.Y + axGlobeControl1.Height)
- {
- return;
- }
- double scale = 0.2;
- if (e.Delta < 0) scale = -scale;
- IGlobeCamera pGlobeCamera = axGlobeControl1.GlobeCamera;
- ICamera pCamera = pGlobeCamera as ICamera;
- IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay;
- if (pGlobeCamera.OrientationMode == esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal)
- {
- double zt, xo, yo, zo;
- pGlobeCamera.GetObserverLatLonAlt(out xo, out yo, out zo);
- pGlobeDisplay.GetSurfaceElevation(xo, yo, true, out zt);
- IPoint pObserver = new PointClass();
- pObserver.PutCoords(xo, yo);
- double zt1 = zt * (UnitSacleToMeter(axGlobeControl1.Globe.GlobeUnits));
- zo = (zo - zt1) * (1 + scale);
- pGlobeCamera.SetObserverLatLonAlt(xo, yo, zo);
- }
- else
- {
- pCamera.ViewingDistance += pCamera.ViewingDistance * scale;
- }
- axGlobeControl1.GlobeDisplay.RefreshViewers();
- }
- catch
- {
- }
- }
- 其中UnitSacleToMeter方法为获取单位转换为米的系数
- public static double UnitSacleToMeter(esriUnits unit)
- {
- switch (unit)
- {
- case esriUnits.esriKilometers:
- return 1000;
- case esriUnits.esriMeters:
- return 1;
- default:
- return -1;
- }
- }</pre><br>
- <pre></pre>
- <span style="font-family:Verdana,Helvetica,Arial,sans-serif; color:#444444"><span style="font-size:14px; line-height:22px"></span></span><pre name="code" class="csharp">private void MainForm_Load(object sender, EventArgs e)
- {
- this.MouseWheel += new System.Windows.Forms.MouseEventHandler(m_SceneCtrl_OnMouseWheel);
- }</pre>重载此事件
- <pre></pre>