开发系统的时候,一定也会考虑鹰眼的实现,鹰眼对整个研究区域有一个整体的轮廓。所以,鹰眼对一个系统来说还是很有必要的。但是找过网上很多代码,大同小异,可最后出现的成果并不是我想要的,终于,get到了心仪的鹰眼,很简单的代码分享给大家。
下图为最终成果图,加载了一个简单的数据试验一下。
分析:主图更新地图或改变显示范围,鸟瞰图随之发生变化;点击鸟瞰图,主图移动到相应的范围进行显示,鸟瞰图上面有红色矩形框。
下面是代码部分。
首先拖入两个MapControl控件,主窗体控件是axMapControl1,鹰眼窗体控件是axMapControl2。
第一步,在axMapControl1属性事件中找到OnExtentUpdated,双击进入代码编写。
private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope pEnvelope = e.newEnvelope as IEnvelope ;
IGraphicsContainer pContainer = axMapControl2.ActiveView.GraphicsContainer;
pContainer.DeleteAllElements();
IRectangleElement pRect = new RectangleElement() as IRectangleElement;
IElement pElement = pRect as IElement;
pElement.Geometry = pEnvelope;
IFillShapeElement shapeElement = pElement as IFillShapeElement;
//鹰眼窗体里的红色线框设置
IFillSymbol fill = new SimpleFillSymbol();
IRgbColor color = new RgbColor() as IRgbColor ;
color.Transparency = 0;
fill.Color = color ;
ILineSymbol line=new SimpleLineSymbol() ;
color.Red = 255;
color.Blue = 0;
color.Green = 0;
color.Transparency = 255;
line.Color = color;
line.Width = 2;
fill.Outline = line;
shapeElement.Symbol = fill;
pContainer.AddElement(pElement, 0);
axMapControl2.ActiveView.Refresh();//刷新
}
第二步,在axMapControl1属性事件中找到OnMapReplaced事件,双击进入代码编写。
private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
for (int i = 0; i < axMapControl1.Map.LayerCount ; i++)
{
axMapControl2.AddLayer(axMapControl1.Map.get_Layer(i));
}
axMapControl2.Extent = axMapControl1.Extent;
axMapControl2.ActiveView.Refresh();
}
第三步,在axMapControl2属性事件中找到OnMouseDown事件,双击进入代码编写。
private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button ==1)
{
IPoint point=new ESRI .ArcGIS .Geometry .Point ();
point.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(point);
axMapControl1.ActiveView.Refresh();
}
}
注:转载请注明出处