您的位置:首页 > 编程语言 > C#

看,别人是怎么实现鹰眼的(C#版)!

2012-07-17 20:58 211 查看
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.Carto;

using ESRI.ArcGIS.Display;

using ESRI.ArcGIS.Geometry;

using ESRI.ArcGIS.Controls;

/*

* 鹰眼视图的简单实现,只是通过拖动鹰眼视图的区域实现在主视图中的显示:

*/

namespace OverView

{

public partial class MainForm : Form

{

#region "界面初始化"

public MainForm()

{

InitializeComponent();

}

private void MainForm_Load(object sender, EventArgs e)

{

try

{

string strFileName = Application.StartupPath + @"\数据\房地产策划信息系统.mxd";

//在数据视图中加载地图,供查询操作

if (axMapControl2.CheckMxFile(strFileName))

{

axMapControl2.LoadMxFile(strFileName);

}

else

{

MessageBox.Show("错误的数据路径:" + strFileName);

}

}

catch (Exception ex)

{

MessageBox.Show("Error01 in MainForm.cs" + ex.Message);

}

}

#endregion "界面初始化"

#region "鹰眼地图"

/* 实现功能:

* 1、鹰眼控件会根据主控件的视图范围生成一个来导航

* 2、在鹰眼控件里点击左键移动,红色距形框会跟着鼠标移动,主控件的视图范围会根据红色距形框位置而做出相应的移动

* 3、在鹰眼控件中可以通过按住鼠标右键来拖动,生成一个新的红色距形框,来导航

* 实现步骤如下(通过多个例子综合而成,write by booker,2008.4.12

*/

//1.鹰眼地图资源载入

//当数据视图文档发生变化后,把文档加载到鹰眼视图的地图控件axMapControl1中

private void axMapControl2_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)

{

//加载地图文档到MapControl中

axMapControl1.LoadMxFile(axMapControl2.DocumentFilename, null, null);

//设置MapControl显示范围至数据的全局范围

axMapControl1.Extent = axMapControl1.FullExtent;

}

//2.绘制鹰眼矩形框

private void axMapControl2_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)

{

// 得到新范围

IEnvelope pEnv = (IEnvelope)e.newEnvelope;

IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer;

IActiveView pAv = pGra as IActiveView;

//在绘制前,清除鹰眼axMapControl1中的任何图形元素

pGra.DeleteAllElements();

IRectangleElement pRectangleEle = new RectangleElementClass();

IElement pEle = pRectangleEle as IElement;

pEle.Geometry = pEnv;

//设置鹰眼图中的红线框

IRgbColor pColor = new RgbColorClass();

pColor.Red = 255;

pColor.Green = 0;

pColor.Blue = 0;

pColor.Transparency = 255;

//产生一个线符号对象

ILineSymbol pOutline = new SimpleLineSymbolClass();

pOutline.Width = 2;

pOutline.Color = pColor;

//设置颜色属性

pColor = new RgbColorClass();

pColor.Red = 255;

pColor.Green = 0;

pColor.Blue = 0;

pColor.Transparency = 0;

//设置填充符号的属性

IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

pFillSymbol.Color = pColor;

pFillSymbol.Outline = pOutline;

IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;

pFillShapeEle.Symbol = pFillSymbol;

pGra.AddElement((IElement)pFillShapeEle, 0);

//刷新

pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

}

//3. 实现互动

private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)

{

/*

IPoint pPt = new PointClass();

pPt.PutCoords(e.mapX, e.mapY);

//改变主控件的视图范围

axMapControl2.CenterAt(pPt);

*/

if (e.button == 1)

{

IPoint pPt = new PointClass();

pPt.X = e.mapX;

pPt.Y = e.mapY;

IEnvelope pEnvelope = this.axMapControl1.TrackRectangle();

this.axMapControl2.Extent = pEnvelope;

}

}

private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)

{

if (e.button == 1)

{

IPoint pPt = new PointClass();

pPt.X = e.mapX;

pPt.Y = e.mapY;

//

IEnvelope pEnvelope = this.axMapControl2.Extent as IEnvelope;

pEnvelope.CenterAt(pPt);

this.axMapControl2.Extent = pEnvelope;

}

}

#endregion "鹰眼地图"

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: