globe和scene控件中使用鼠标中键进行缩放的实现代码


分类: ArcEngine
[csharp]  view plain copy
  1. 使用globe和scene控件开发时,要实现像桌面版arcglobe和arcscene中使用鼠标中键进行缩放的功能,需要自己重载OnMouseWheel事件,实现代码如下:  
  2.   
  3. scene控件下的  
  4.   
  5. private void SceneControl_OnMouseWheel(object sender, MouseEventArgs e)  
  6.         {  
  7.             try  
  8.              {  
  9.                 System.Drawing.Point pSceLoc = m_SceneCtrl.PointToScreen(this.m_SceneCtrl.Location);  
  10.                 System.Drawing.Point Pt = this.PointToScreen(e.Location);  
  11.                 if (Pt.X < pSceLoc.X || Pt.X > pSceLoc.X + m_SceneCtrl.Width || Pt.Y < pSceLoc.Y || Pt.Y > pSceLoc.Y + m_SceneCtrl.Height)  
  12.                 {  
  13.                     return;  
  14.                 }  
  15.                 double scale = 0.2;  
  16.                 if (e.Delta < 0) scale = -0.2;  
  17.                 ICamera pCamera = m_SceneCtrl.Camera;  
  18.                 IPoint pPtObs = pCamera.Observer;  
  19.                 IPoint pPtTar = pCamera.Target;  
  20.                 pPtObs.X += (pPtObs.X - pPtTar.X) * scale;  
  21.                 pPtObs.Y += (pPtObs.Y - pPtTar.Y) * scale;  
  22.                 pPtObs.Z += (pPtObs.Z - pPtTar.Z) * scale;  
  23.                 pCamera.Observer = pPtObs;  
  24.                 m_SceneCtrl.SceneGraph.RefreshViewers();  
  25.             }  
  26.             catch  
  27.             {  
  28.             }  
  29.         }  
[csharp]  view plain copy
  1.   
[csharp]  view plain copy
  1. <pre name="code" class="csharp">globe控件下的  
  2.   
  3. private void axGlobeControl1_OnMouseWheel(object sender, MouseEventArgs e)  
  4.         {  
  5.             try  
  6.             {  
  7.                 System.Drawing.Point pSceLoc = axGlobeControl1.PointToScreen(axGlobeControl1.Location);  
  8.                 System.Drawing.Point Pt = this.PointToScreen(e.Location);  
  9.                 if (Pt.X < pSceLoc.X || Pt.X > pSceLoc.X + axGlobeControl1.Width || Pt.Y < pSceLoc.Y || Pt.Y > pSceLoc.Y + axGlobeControl1.Height)  
  10.                 {  
  11.                     return;  
  12.                 }  
  13.   
  14.                 double scale = 0.2;                             
  15.                 if (e.Delta < 0) scale = -scale;  
  16.   
  17.                 IGlobeCamera pGlobeCamera = axGlobeControl1.GlobeCamera;  
  18.                 ICamera pCamera = pGlobeCamera as ICamera;  
  19.                 IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay;  
  20.                 if (pGlobeCamera.OrientationMode == esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal)  
  21.                 {  
  22.                     double zt, xo, yo, zo;  
  23.                     pGlobeCamera.GetObserverLatLonAlt(out xo, out yo, out zo);  
  24.                     pGlobeDisplay.GetSurfaceElevation(xo, yo, trueout zt);  
  25.                     IPoint pObserver = new PointClass();  
  26.                     pObserver.PutCoords(xo, yo);  
  27.                     double zt1 = zt * (UnitSacleToMeter(axGlobeControl1.Globe.GlobeUnits));  
  28.                     zo = (zo - zt1) * (1 + scale);  
  29.                     pGlobeCamera.SetObserverLatLonAlt(xo, yo, zo);  
  30.                 }  
  31.                 else  
  32.                 {  
  33.                     pCamera.ViewingDistance += pCamera.ViewingDistance * scale;  
  34.                 }  
  35.                 axGlobeControl1.GlobeDisplay.RefreshViewers();              
  36.             }  
  37.             catch  
  38.             {  
  39.             }  
  40.         }  
  41.   
  42. 其中UnitSacleToMeter方法为获取单位转换为米的系数  
  43.         public static double UnitSacleToMeter(esriUnits unit)  
  44.         {  
  45.             switch (unit)  
  46.             {  
  47.                 case esriUnits.esriKilometers:  
  48.                     return 1000;  
  49.                 case esriUnits.esriMeters:  
  50.                     return 1;  
  51.                 default:  
  52.                     return -1;  
  53.             }  
  54.         }</pre><br>  
  55. <pre></pre>  
  56. <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)  
  57. {  
  58.              this.MouseWheel += new System.Windows.Forms.MouseEventHandler(m_SceneCtrl_OnMouseWheel);  
  59. }</pre>重载此事件  
  60. <pre></pre> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值