分享

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

 五行和谐 2014-11-06
    

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;
                }
                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();
            }
        }
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多