三个方法,搞定engine鹰眼功能,简单易懂
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IEnvelope pEnv = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnv;
axMapControl1.Refresh();
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
IEnvelope pEnv;
pEnv = e.newEnvelope as IEnvelope;
IGraphicsContainer pGraphicsContainer;
IActiveView pActiveView;
pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();//'获取矩形坐标
IRectangleElement pRectangleEle;
pRectangleEle = new RectangleElementClass();
IElement pEle;
pEle = pRectangleEle as IElement;
pEle.Geometry = pEnv;
IRgbColor pColor;
pColor = new RgbColorClass();
pColor.RGB = 255;
pColor.Transparency = 255;
ILineSymbol pOutline;
pOutline = new SimpleLineSymbolClass();
pOutline.Width = 1;
pOutline.Color = pColor;
pColor = new RgbColorClass();
pColor.RGB = 255;
pColor.Transparency = 0;
IFillSymbol pFillSymbol;
pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
//构建矩形元素
IFillShapeElement pFillshapeEle;
pFillshapeEle = pEle as IFillShapeElement;
pFillshapeEle.Symbol = pFillSymbol;
pEle = pFillshapeEle as IElement;
pGraphicsContainer.AddElement(pEle, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
IMap pMap = axMapControl1.Map;
axMapControl2.Map.ClearLayers();
for (int i = pMap.LayerCount - 1; i >= 0; i--)
{
axMapControl2.Map.AddLayer(pMap.get_Layer(i));
}
}