C# ArcGIS 三维地图 arcgloblecontrol 基础操作 加载地图 漫游 放大 缩小

最近在调研arcgis地图,就把一些自己写的基本的操作po一下,希望对刚刚开始接触到arcgis的童鞋有点帮助,大神请指正吐槽。
效果就是这样滴:
C# ArcGIS 三维地图 arcgloblecontrol 基础操作 加载地图 漫游 放大 缩小_第1张图片
正文:
引入命名空间:

using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.GlobeCore;

全局变量:

private ISceneViewer m_ActiveView;
private ICamera m_Camera;

加载地图:

if (axGlobeControl1.Check3dFile(filePath))
{
    axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
    axGlobeControl1.Load3dFile(filePath);
    axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
    MessageBox.Show(filePath + "不是有效的地图文件");
}
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(axGlobeControl1_OnMouseWheel);

鼠标滚动放大缩小事件:

        private void axGlobeControl1_OnMouseWheel(object sender, MouseEventArgs e)
        {
            //将axGlobeControl1相对于软件的坐标,变换成屏幕坐标
            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 xo, yo, zo;
                pGlobeCamera.GetObserverLatLonAlt(out xo, out yo, out zo);
                zo = zo * (1 + scale);
                pGlobeCamera.SetObserverLatLonAlt(xo, yo, zo);
            }
            else
            {
                pCamera.ViewingDistance += pCamera.ViewingDistance * scale;
            }
            axGlobeControl1.GlobeDisplay.RefreshViewers();
        }

radial菜单实现几个功能:
需要注意,地图是默认没有开启漫游的,所以需要axGlobeControl1.Navigate = true。

                switch (item.Text)
                {
                    case "漫游" :
                        axGlobeControl1.Navigate = true;
                        //axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
                        break;
                    case "放大":
                        double vfa = m_Camera.ViewFieldAngle;
                        m_Camera.ViewFieldAngle = vfa * 0.9;
                        m_ActiveView.Redraw(false);
                        break;
                    case "缩小":
                        double vfa1 = m_Camera.ViewFieldAngle;
                        m_Camera.ViewFieldAngle = vfa1 * 1.1;
                        m_ActiveView.Redraw(false);
                        break;
                    case "3D":
                        axGlobeControl1.Navigate = true;
                        //axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
                        break;
                }

你可能感兴趣的:(桌面应用)