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

ArcEngine 鹰眼功能C#实现

2016-05-08 23:34 561 查看
ArcEngine开发之鹰眼功能C#实现

鹰眼作为AE系统一项基本功能,经常见于AE开发中。网上鹰眼功能实现大同小异,本文所写示例仅作参考及记录。

一、效果图



二、控件说明

基本AE框架,包括菜单(MenuStrip)、工具栏(AxToolbarControl)、图层目录(AxTOCControl)、数据视图(axMapControl1)、鹰眼视图(axMapControl2)。

布局上述框架的小细节:

1、在空白窗体中先添加MenuStrip;

2、添加AxToolbarControl,Dock属性设为Top;

3、添加SplitContainer1,Dock自动为Fill;

4、在SplitContainer1.Panel1(左面板)添加SplitContainer2容器,并修改其Orientation属性为“水平”;

5、在SplitContainer1.Panel2(右面板)添加AxMapControl1控件,Dock属性设为Fill,用做数据视图;

6、在SplitContainer2.Panel1添加AxTOCControl控件,在SplitContainer2.Panel2添加AxMapControl2控件,Dock属性设为Fill,用做鹰眼视图;

三、关键步骤

鹰眼功能实现主要在axMapControl1(主视图)和axMapControl2(鹰眼视图)的相应响应事件中操作,主要是axMapControl1的OnExtentUpdated、OnMapReplaced事件,axMapControl2的OnMouseDown、OnMouseMove事件。其关键代码如下:

private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
IRectangleElement pRectangleEle = new RectangleElementClass();
IElement pElement = pRectangleEle as IElement;
pElement.Geometry = pEnvelope;

IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 255;

ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = 3;
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 = pElement as IFillShapeElement;
pFillShapeEle.Symbol = pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
axMapControl2.Map = new MapClass();
if (axMapControl1.LayerCount > 0)
{
for(int i=0;i<=axMapControl1.Map.LayerCount-1;++i)
{
axMapControl2.AddLayer(axMapControl1.get_Layer(i));
}
axMapControl2.Extent = axMapControl1.Extent;
}
}

private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2.Map.LayerCount > 0)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
else if (e.button == 2)
{
IEnvelope pEnv = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnv;
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
}

private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
四、其他说明

1、鹰眼按需显示及隐藏

现在希望鹰眼控件默认隐藏,只有在点击鹰眼功能时才予以显示。实现思路:设置splitContainer2.Panel2Collapsed默认属性为true,在响应鹰眼点击事件时更改该属性。(提示:由于鹰眼功能实现需要axMapControl2的部分响应事件,建议在先生成相应响应事件之后再修改该属性)

2、axTOCControl控件图层不显示问题

即使axTOCControl在控件中绑定了axMapControl控件,但实际运行时图层目录并不显示,解决方法是需要在程序中手动添加绑定。

axTOCControl1.SetBuddyControl(axMapControl1);


完整示例源码,感兴趣的可以参考。示例源码:http://download.csdn.net/detail/sean4m/9513918
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: