鹰眼功能实现(AE+C#)
luyued 发布于 2011-03-17 15:17 浏览 N 次原文地址:http://www.3sfield.com/content.php?id=451
鹰眼是个比较常规的GIS软件功能。
本例需要两个MapControl控件即主控件 AxMapContorl1和鹰眼控件AxmapControl2;要实现这一功能主要保持两个控件显示的数据一致,以及在鹰眼控件的显示方框中让两个控 件数据共享 创建一个项目命名为 lesson6;增加两个MapControl;下面开始实现代码
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;
using ESRI.ArcGIS.Display;
namespace lesson6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadMapDocument();
}
//加载地图文档
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 loadEagleEyeDocument()
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开鹰眼地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
if (axMapControl2.CheckMxFile(filePath))
{
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl2.LoadMxFile(filePath, 0, Type.Missing);
axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(filePath + "不是有效的地图文档");
}
}
private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
loadEagleEyeDocument();
}
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)
{
axMapControl1.Extent = axMapControl1.TrackRectangle();
axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground, null,null);
}
else if (e.button == 2)
{
axMapControl1.Pan();
axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
}
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope envelope = (IEnvelope)e.newEnvelope;
IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView activeView = graphicsContainer as IActiveView;
//在绘制前,清除axMapControl2中的任何图形元素
graphicsContainer.DeleteAllElements ();
IElement element = new RectangleElementClass();
element.Geometry = envelope ;
//设置鹰眼图中的红线
//产生一个线符号对象
ILineSymbol outLineSymbol = new SimpleLineSymbolClass();
outLineSymbol.Width = 2;
outLineSymbol.Color = GetColor(255, 0, 0, 255);
//设置颜色属性
//设置填充符号的属性
IFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = GetColor(9, 0, 0, 0);
fillSymbol.Outline = outLineSymbol ;
IFillShapeElement fillShapeElement = element as IFillShapeElement;
fillShapeElement.Symbol = fillSymbol;
graphicsContainer.AddElement((IElement)fillShapeElement , 0);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private IRgbColor GetColor(int r, int g, int b, int t)
{
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = r;
rgbColor.Green = g;
rgbColor.Blue = b;
rgbColor.Transparency = (byte)t;
return rgbColor;
}
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint point = new PointClass();
point.PutCoords(e.mapX , e.mapY);
axMapControl1.CenterAt(point);
}
}
}
- 07-01· 禁教唐诗算术能还幼儿快
- 07-01· 2011年06月17日
- 07-01· 唐诗宋词英译:李商隐 筹
- 07-01· 仿评《唐诗1000首》第186首
- 07-01· 没事干的时候背背唐诗吧
- 07-01· [转载]唐诗中“斜”字该读
- 07-01· 湖南醴陵瓷业转型升级
- 07-01· 奇瑞风云2两厢黑色|2010款
- 07-01· 摩根士丹利华鑫摩根士丹
- 07-01· 摩根士丹利华鑫近期优选
- 07-01· 中金投行部大摩出售中金
- 07-01· 摩根士丹利招聘6月2日【实
- 07-01· 营养防病圣典
- 07-01· 《博伽梵歌原意》之第十
- 07-01· [不错]斑斓圣典---减肥中常
- 07-01· 武乐圣典《太极武当》:武
- 07-01· 铁血英雄-现阶段战功牌兑
- 07-01· 2011年06月10日【原创】南歌
- 07-01· 【淘宝网信息】- 2010年的
- 07-01· 深圳品牌女装有哪些?