ArcGIS Engine 开发(一)对地图放大、缩小、漫游、全局等功能

来源:互联网 发布:java开源商城 编辑:程序博客网 时间:2024/04/30 22:52

一:实现功能:地图放大、缩小、漫游、全局

二:运行效果:

三:源代码如下:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Geometry;namespace lesson4{    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 documents(*.mxd)|*.mxd";            openFileDialog.ShowDialog();            string filePath = openFileDialog.FileName;            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)        {            ESRI.ArcGIS.Geometry.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();            }        }    }}

完整的demo可以从我上传的资料下载,也可在线咨询qq937292955


0 0