较为完整的鹰眼实现,跟大家共享一下
2011-07-19 22:35
246 查看
主要实现了一下几点: 1.加载mxd文件同步;OnMapReplaced事件 2.加载图层文件同步;OnItemAdded事件 3.TOC中图层勾选状态与鹰眼中图层可见状态同步;ContentsChanged事件 4.鹰眼视图中右键框选主视图中显示区域; 5.鹰眼视图中左键单击确定矩形框中心; 6.TOC右键菜单删除图层;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingESRI.ArcGIS.Carto;
usingSystem.Diagnostics;
usingESRI.ArcGIS.Geometry;
usingESRI.ArcGIS.Display;
usingESRI.ArcGIS.Controls;
namespaceDEMO1
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
}
IActiveViewEvents_EventpAE;
privatevoidaxMapControl1_OnMapReplaced(objectsender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvente)
{
axMapControl2.ClearLayers();//每次主视图地图更换时,清空鹰眼中原有图层
IMappMap=e.newMapasIMap;//参数e是object类型,要进行接口转换
intn=pMap.LayerCount;
for(inti=n-1;i>=0;i--)
{
axMapControl2.AddLayer(pMap.get_Layer(i));
}
this.pAE=e.newMapasIActiveViewEvents_Event;
pAE.ItemAdded+=newIActiveViewEvents_ItemAddedEventHandler(this.OnItemAdded);
pAE.ContentsChanged+=newIActiveViewEvents_ContentsChangedEventHandler(pAE_ContentsChanged);
}
voidpAE_ContentsChanged()
{
IBasicMapmap=null;
ILayerlayer=null;
Objectother=null;
Objectindex=null;
esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;
axTOCControl1.GetSelectedItem(refitem,refmap,reflayer,refother,refindex);
ILayerplayer;
for(inti=0;i<axMapControl2.LayerCount;i++)
{
player=axMapControl2.get_Layer(i);
if(player.Name==layer.Name)
{
if(layer.Visible==true)
player.Visible=true;
else
player.Visible=false;
axMapControl2.Refresh();
break;
}
}
}
privatevoidForm1_Load(objectsender,EventArgse)
{
//用代码设置伙伴控件更保险
axTOCControl1.SetBuddyControl(axMapControl1);
axToolbarControl1.SetBuddyControl(axMapControl1);
//禁用鹰眼MapControl的滚轮放大缩小功能
axMapControl2.AutoMouseWheel=false;
IMappMap;
pMap=axMapControl1.Map;//主视图
pAE=pMapasIActiveViewEvents_Event;
pAE.ItemAdded+=newIActiveViewEvents_ItemAddedEventHandler(this.OnItemAdded);
pAE.ContentsChanged+=newIActiveViewEvents_ContentsChangedEventHandler(pAE_ContentsChanged);
}
privatevoidOnItemAdded(objectitem)
{
ILayerpLayer;
pLayer=itemasILayer;
axMapControl2.AddLayer(pLayer,0);//鹰眼视图
axMapControl2.Refresh();
}
privatevoidaxMapControl1_OnExtentUpdated(objectsender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvente)
{
try
{
ESRI.ArcGIS.Geometry.IEnvelopeenvelope=(ESRI.ArcGIS.Geometry.IEnvelope)e.newEnvelope;
ESRI.ArcGIS.Carto.IGraphicsContainergc=axMapControl2.MapasESRI.ArcGIS.Carto.IGraphicsContainer;
ESRI.ArcGIS.Carto.IActiveViewac=gcasESRI.ArcGIS.Carto.IActiveView;
//在绘制前,清除axMapControl2中的内容
gc.DeleteAllElements();
ESRI.ArcGIS.Carto.IElementelment=newESRI.ArcGIS.Carto.RectangleElementClass();
elment.Geometry=envelope;
//设置鹰眼中的红线
//产生一个线符号对象
ESRI.ArcGIS.Display.ILineSymboloutLineSymbol=newESRI.ArcGIS.Display.SimpleLineSymbolClass();
outLineSymbol.Width=2;
outLineSymbol.Color=GetColor(255,0,0,255);
//设置颜色属性
//设置填充符号的属性
ESRI.ArcGIS.Display.IFillSymbolfillsymbol=newESRI.ArcGIS.Display.SimpleFillSymbolClass();
fillsymbol.Color=GetColor(9,0,0,0);
fillsymbol.Outline=outLineSymbol;
ESRI.ArcGIS.Carto.IFillShapeElementfillshapeelement=elmentasESRI.ArcGIS.Carto.IFillShapeElement;
fillshapeelement.Symbol=fillsymbol;
gc.AddElement((ESRI.ArcGIS.Carto.IElement)fillshapeelement,0);
ac.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics,null,null);
}
catch(ExceptioneCatch)
{
MessageBox.Show(eCatch.ToString()+"\n鹰眼中绘制红色矩形框出错");
}
}
privateESRI.ArcGIS.Display.IRgbColorGetColor(intr,intg,intb,intt)
{
ESRI.ArcGIS.Display.IRgbColorrgb=newESRI.ArcGIS.Display.RgbColorClass();
rgb.Red=r;
rgb.Green=g;
rgb.Blue=b;
rgb.Transparency=(byte)t;
returnrgb;
}
//右键画矩形选定主视图显示范围
privatevoidaxMapControl2_OnMouseDown(objectsender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvente)
{
if(e.button==2)
{
try
{
IPointpPoint=newPointClass();
pPoint.X=e.mapX;
pPoint.Y=e.mapY;
IEnvelopepEnvelop=axMapControl2.TrackRectangle();
axMapControl1.Extent=pEnvelop;
}
catch
{
}
}
}
privatevoidaxMapControl2_OnMouseMove(objectsender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvente)
{
if(e.button==1)
{
try
{
IPointpPoint=newPointClass();
pPoint.X=e.mapX;
pPoint.Y=e.mapY;
IEnvelopepEnvelop=axMapControl1.ExtentasIEnvelope;
pEnvelop.CenterAt(pPoint);
IGraphicsContainerpGraphicContainer=axMapControl2.MapasIGraphicsContainer;
IActiveViewpAV=pGraphicContainerasIActiveView;
pGraphicContainer.DeleteAllElements();
ESRI.ArcGIS.Carto.IElementelment=newESRI.ArcGIS.Carto.RectangleElementClass();
elment.Geometry=pEnvelop;
//设置鹰眼中的红线
//产生一个线符号对象
ESRI.ArcGIS.Display.ILineSymboloutLineSymbol=newESRI.ArcGIS.Display.SimpleLineSymbolClass();
outLineSymbol.Width=2;
outLineSymbol.Color=GetColor(255,0,0,255);
//设置颜色属性
//设置填充符号的属性
ESRI.ArcGIS.Display.IFillSymbolfillsymbol=newESRI.ArcGIS.Display.SimpleFillSymbolClass();
fillsymbol.Color=GetColor(9,0,0,0);
fillsymbol.Outline=outLineSymbol;
ESRI.ArcGIS.Carto.IFillShapeElementfillshapeelement=elmentasESRI.ArcGIS.Carto.IFillShapeElement;
fillshapeelement.Symbol=fillsymbol;
pGraphicContainer.AddElement((ESRI.ArcGIS.Carto.IElement)fillshapeelement,0);
pAV.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics,null,null);
}
catch
{
}
}
}
privatevoidaxMapControl2_OnMouseUp(objectsender,ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvente)
{
if(e.button==1)
{
try
{
IPointpPoint=newPointClass();
pPoint.X=e.mapX;
pPoint.Y=e.mapY;
IEnvelopepEnvelop=axMapControl1.ExtentasIEnvelope;
pEnvelop.CenterAt(pPoint);
axMapControl1.Extent=pEnvelop;
}
catch
{
}
}
}
privatevoid删除图层ToolStripMenuItem_Click(objectsender,EventArgse)
{
if(SelectedLayer!=null)
{
axMapControl1.Map.DeleteLayer(SelectedLayer);
axMapControl2.Map.DeleteLayer(SelectedLayer);
SelectedLayer=null;
}
}
ILayerSelectedLayer;
privatevoidaxTOCControl1_OnMouseDown(objectsender,ITOCControlEvents_OnMouseDownEvente)
{
if(e.button==2)
{
IBasicMapmap=null;
ILayerlayer=null;
Objectother=null;
Objectindex=null;
esriTOCControlItemitem=esriTOCControlItem.esriTOCControlItemNone;
axTOCControl1.HitTest(e.x,e.y,refitem,refmap,reflayer,refother,refindex);
if(item==esriTOCControlItem.esriTOCControlItemLayer)
{
SelectedLayer=layer;
TOCMenuStrip1.Show(axTOCControl1,e.x,e.y);
}
}
}
}
}
相关文章推荐
- 全站ajax.net实现的在线99收藏夹,大家共享!
- 最近学习NFS文件系统的使用,Ubuntu上配置好了,想和Win7共享数据,所以网上搜到了这篇文章。借花献佛,跟大家共享一下:
- 大家一起讨论一下朋友网的人脉关系算法是怎么实现的
- 提供一下 微软 的 SqlHelper 给大家共享
- 关于socket用winform实现简单通信 大牛可绕道 初学者可以看看 我做的时候把客户端窗口隐藏了 大家可以自己改一下
- 好久没写随笔了,最近收到朋友转发的一篇文章,心里产生极大共鸣,与大家共享一下~
- 面试题:较为完整的atoi的实现,奶牛苹果的最小搬运次数
- 今天给大家讲解一下在自定义View中,如何实现画图。
- 全站ajax.net实现的在线99收藏夹,大家共享!
- 今天和大家讲一下按钮怎么实现和隐藏,Visibility的使用
- 看了GAL游戏资源文件黑盒分析,想起以前做的一个提取器,发来大家共享一下
- 非C#的文章,不过大家可以借鉴一下其中思想--用Java实现断点续传(HTTP)
- 今天整理了论坛很多关于dotnet(C#)的试题,大家共享一下
- 期权激励的核心价值是:激励能人,一起和公司共同成长,实现利益共享,有钱大家一起赚(转)
- 一个实现缩略图方式查看的ListView.很不完整,请大家共同完善。
- java实现堆排序算法,和大家分享一下
- 教大家用java实现顶一下踩一下功能
- 家庭有WIFI,可以实现手机浏览电脑中的视频!与大家共享
- dotnet(C#)的面试题,大家共享一下
- 如何实现网间互访(没有网络服务器权限) 大家提提建议 共同探讨一下