关闭

ArcgisEngine开发之地图的基本操作

254人阅读 评论(0) 收藏 举报
分类:

1、新建一个C#窗体项目,添加一个axMapControl、axLicenseControl以及5个Button按钮,如图所示:

2、代码

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.Geometry;

namespace BasicOperation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //定义一个标记,用来标记对地图的操作
        int flag = 0;
        //加载地图文件
        private void LoadMapFile()
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Title = "打开地图文档";
            openDialog.Filter = "MapDocument(*.mxd)|*.mxd";
            openDialog.ShowDialog();
            string path = openDialog.FileName;
            if (axMapControl1.CheckMxFile(path))
            {
                axMapControl1.LoadMxFile(path, 0, Type.Missing);
            }
            else
            {
                MessageBox.Show(path + "不是有效的文档!");
            }
        }

        //放大
        private void button1_Click(object sender, EventArgs e)
        {
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerPageZoomIn;
            flag = 1;
        }

        //缩小
        private void button2_Click(object sender, EventArgs e)
        {
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerPageZoomOut;
            flag = 2;
        }

        //漫游
        private void button3_Click(object sender, EventArgs e)
        {
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerPan;
            flag = 3;
        }

        //全图
        private void button4_Click(object sender, EventArgs e)
        {
            axMapControl1.Extent = axMapControl1.FullExtent;
        }

        private void axMapControl1_OnMouseDown(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            //定义一个IEnvelope接口
            /*
             * Envelopes are the rectangular window that contain a specific element.  
             * All Geometry objects have an envelope defined by the XMin, XMax, YMin, and YMax of the object.  
             * Envelopes can also serve as the viewing area for a particular view screen or data frame.
             */
            IEnvelope envelope;
            if (flag == 1)
            {
                envelope = axMapControl1.TrackRectangle();
                axMapControl1.Extent = envelope;
            }
            if (flag == 2)
            {
                envelope = axMapControl1.TrackRectangle();
                envelope = axMapControl1.Extent;
                //缩小
                /*
                 * Expand scales the size of the Envelope.  
                 * If asRatio = FALSE, the expansion is additive. 
                 * If asRatio = TRUE, the expansion is multiplicative.
                 */
                envelope.Expand(2,2,true);
                axMapControl1.Extent = envelope;
            }
            if (flag == 3)
            {
                //envelope = axMapControl1.Extent;
                axMapControl1.Pan();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            LoadMapFile();
        }
    }
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:21274次
    • 积分:1232
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:0篇
    • 译文:51篇
    • 评论:10条
    文章分类
    最新评论