您的位置:首页 > 其它

ArcgisEngine开发之地图的基本操作

2017-01-03 10:30 274 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: