zoukankan      html  css  js  c++  java
  • 向Arcglobe中添加MouseWheel事件,使其具有鼠标放大缩小功能。

     在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;
                }
            }

  • 相关阅读:
    C#中处理鼠标和键盘的事件
    C#中处理鼠标和键盘的事件
    C#中处理鼠标和键盘的事件
    mpich2安装
    算法题推箱子
    LINUX终端下windows盘的位置
    Linux头文件和库文件添加环境变量与GCC编译器添加INCLUDE与LIB环境变量
    第九章顺序容器重学C++之《 C++ PRIMER》
    sed中使用变量
    抛出异常
  • 原文地址:https://www.cnblogs.com/xianyin05/p/1439510.html
Copyright © 2011-2022 走看看