您的位置:首页 > 其它

AE开发中、放大、缩小、漫游、全图的实现

2017-04-17 09:53 344 查看
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using ESRI.ArcGIS.Controls;

using ESRI.ArcGIS.Geometry;

namespace AEKF2

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        //窗体加载地图文档

        private void Form1_Load(object sender, EventArgs e)

        {

            loadMapDocument();

        }

        int flag = 0;

        //放大

        private void button1_Click(object sender, EventArgs e)

        {

            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn;

            flag = 2;

        }

        //缩小

        private void button2_Click(object sender, EventArgs e)

        {

            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut;

            flag = 1;

        }

        //漫游

        private void button3_Click(object sender, EventArgs e)

        {

            axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;

            flag = 3;

        }

        //全图

        private void button4_Click(object sender, EventArgs e)

        {

            axMapControl1.Extent = axMapControl1.FullExtent;

        }

        //打开地图方法

        private void loadMapDocument()

        {

            System.Windows.Forms.OpenFileDialog openFileDialog;

            openFileDialog = new OpenFileDialog();

            openFileDialog.Title = "打开地图文档";

            openFileDialog.Filter = "map document(*.mxd)|*.mxd";

            openFileDialog.ShowDialog();

            string filepath = openFileDialog.FileName;

            if (filepath != "" && filepath != null)

            {

                if (axMapControl1.CheckMxFile(filepath))

                {

                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;

                    axMapControl1.LoadMxFile(filepath, 0, Type.Missing);

                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
4000

                }

                else

                {

                    MessageBox.Show(filepath+"不是有效地图");

                }

            }

        }

        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)

        {

            IEnvelope ipenv;

            if (flag == 2)

            {

                ipenv = axMapControl1.TrackRectangle();

                axMapControl1.Extent = ipenv;

            }

            else if (flag == 1)

            {

                ipenv = axMapControl1.TrackRectangle();

                ipenv = axMapControl1.Extent;

                ipenv.Expand(2, 2, true);

                axMapControl1.Extent = ipenv;

            }

            else if (flag == 3)

            {

                ipenv = axMapControl1.Extent;

                axMapControl1.Pan();

            }

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: