原文转自:http://blog.csdn.net/wufeishimeng/article/details/5809732
#region 鹰眼图
IElement pOverViewElement = null;//鹰眼图Element
IEnvelope pCurrentEnveop = null;
bool IsMove = false;
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
if (pOverViewElement != null)
{
upDataOverViewMap();
}
}
private IElement InitOverViewMap()
{
if (axMapControl1.DocumentFilename == null) { Tools.ShowInfoWindow("当前未加载地图",1); return null; }
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
axMapControl2.Extent = axMapControl2.FullExtent;
axMapControl2.OnMouseMove += new IMapControlEvents2_Ax_OnMouseMoveEventHandler(axMapControl2_OnMouseMove);
axMapControl2.OnMouseDown += new IMapControlEvents2_Ax_OnMouseDownEventHandler(axMapControl2_OnMouseDown);
axMapControl2.OnMouseUp += new IMapControlEvents2_Ax_OnMouseUpEventHandler(axMapControl2_OnMouseUp);
pCurrentEnveop = axMapControl1.Extent;
IEnvelope pEnv = axMapControl1.Extent;
pEnv.Expand(3, 3, true);
axMapControl2.Extent = pEnv;
IRgbColor pColor = new RgbColorClass();
IRectangleElement pPolygonElement = new RectangleElementClass();
ISimpleLineSymbol pLineSym = new SimpleLineSymbolClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pLineSym.Color = pColor;
pLineSym.Width = 2;
ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass();
pColor.Transparency = 0;
pFillSym.Color = pColor;
pFillSym.Outline = pLineSym;
((IFillShapeElement)pPolygonElement).Symbol = pFillSym;
((IElement)pPolygonElement).Geometry = axMapControl1.Extent;
axMapControl2.ActiveView.GraphicsContainer.DeleteAllElements();
axMapControl2.ActiveView.GraphicsContainer.AddElement((IElement)pPolygonElement, 0);
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
return (IElement)pPolygonElement;
}
void axMapControl2_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
IsMove = false;
upDataMainMap();
}
void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IsMove = true;
}
void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (IsMove)
{
IPoint cPt = new PointClass();
cPt.X = e.mapX; cPt.Y = e.mapY;
pCurrentEnveop.CenterAt(cPt);
pOverViewElement.Geometry = pCurrentEnveop;
axMapControl2.ActiveView.GraphicsContainer.UpdateElement(pOverViewElement);
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
private void upDataOverViewMap()
{
pCurrentEnveop = axMapControl1.Extent;
IEnvelope pEnv = axMapControl1.Extent;
pEnv.Expand(3, 3, true);
axMapControl2.Extent = pEnv;
pOverViewElement.Geometry = axMapControl1.Extent;
axMapControl2.ActiveView.GraphicsContainer.UpdateElement(pOverViewElement);
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private void upDataMainMap()
{
axMapControl1.Extent = pCurrentEnveop;
}
private void picture_CloseOverMap_Click(object sender, EventArgs e)
{
OverViewWindow.Visible = false;
axMapControl2.ActiveView.GraphicsContainer.DeleteAllElements();
pOverViewElement = null;//鹰眼图Element
pCurrentEnveop = null;
}
private void btn_OverViewMap_Click(object sender, EventArgs e)
{
pOverViewElement = InitOverViewMap();
if (pOverViewElement == null) return;
OverViewWindow.Visible = true;
}
#endregion