您的位置:首页 > 服装鞋帽 > 女装 > 鹰眼功能实现(AE+C#)

鹰眼功能实现(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);
}
}
}

图文资讯
广告赞助商