小标
2018-12-14
来源 :
阅读 2409
评论 0
摘要:本文主要向大家介绍了C#编程之ArcEngine 鹰眼功能C#实现,通过具体的内容向大家展示,希望对大家学习C#编程有所帮助。
本文主要向大家介绍了C#编程之ArcEngine 鹰眼功能C#实现,通过具体的内容向大家展示,希望对大家学习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);
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C#.NET频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号