在MainForm.cs文件中添加以下代码:
private void MainForm_Load(object sender, EventArgs e)
{
//向Arcglobe中添加鼠标滚轮放大缩小功能09.4.20刘现印添加
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(axGlobeControl1_OnMouseWheel);
}
private void axGlobeControl1_OnMouseWheel(object sender, MouseEventArgs e)
{
try
{
Cursor.Current = new System.Windows.Forms.Cursor(@"..\..\Resources\ZOOMINOUT.CUR");//将鼠标样式变换为自定义的鼠标样式
//m_cursor = new System.Windows.Forms.Cursor(@"..\..\Resources\ZOOMINOUT.CUR");
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
{
}
}
/// <summary>
/// 其中UnitSacleToMeter方法为获取单位转换为米的系数
/// </summary>
/// <param name="unit"></param>
/// <returns></returns>
public static double UnitSacleToMeter(esriUnits unit)
{
switch (unit)
{
case esriUnits.esriKilometers:
return 1000;
case esriUnits.esriMeters:
return 1;
default:
return -1;
}
}