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();
}
}
}
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();
}
}
}
相关文章推荐
- ArcGIS Engine开发之地图基本操作(4)
- ArcGIS Engine开发之地图基本操作(2)
- aaronyang的百度地图API之LBS云与.NET开发 Javascript API 2.0【基本地图的操作】
- ArcGIS Engine开发之地图基本操作(1)
- ArcGIS Engine开发之地图基本操作(1)
- ArcGIS Engine开发之地图基本操作(3)
- 最新基于高德地图的android进阶开发(5)地图的基本操作、事件监听、用户UI、图层选择等
- JNI及Android JNI 开发基本知识和具体操作步骤
- zen-cart基本操作手册(二次开发手册)
- asp.net mvc 2 简简单单做开发 通用增删改基本操作通用页面
- 数据库开发基本操作-配置SQL Server 2005 Express的身份验证方式,以及如何启用sa登录名
- Windows Phone 7(WP7)开发 网络操作(1) HttpWebRequest基本的GET请求
- 深入浅出 Javascript API(二)--地图显示与基本操作
- 数据库开发基本操作-安装Sql Server 2005出现“性能监视器计数器要求”错误解决方法
- 数据库开发基本操作-SQL Server数据库基础知识
- 数据库开发基本操作-SQL Server 2005版本简介
- Windows Phone 7(WP7)开发 网络操作(1) HttpWebRequest基本的GET请求
- (转)基于MapWinGis开发探索(二)——注册、加载、基本操作
- [转]基于Cmockery和TDD开发循环Queue结构和基本操作
- Android引路蜂地图开发示例:基本知识