C annotated example code for the entire of process
- 2020-05-10 18:38:04
- OfStack
axMapControl1 is the master and axMapControl2 is the eagle eye control
Look at the event response
1. Eagle eye map resource loading
privatevoid axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
// When the map of the main map display control is replaced, the eagle eye map is also replaced
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
axMapControl2.Extent = axMapControl2.FullExtent;
}
2. Draw the eagle eye rectangle
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
// Get a new range
IEnvelope pEnv = (IEnvelope)e.newEnvelope;
IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;
IActiveView pAv = pGra as IActiveView;
// Before drawing, clear axMapControl2 Any graphic element in
pGra.DeleteAllElements();
IRectangleElement pRectangleEle = new RectangleElementClass();
IElement pEle = pRectangleEle as IElement;
pEle.Geometry = pEnv;
// Set the red line box in the eagle eye diagram
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 255;
// produce 1 Line symbol object
ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = 2;
pOutline.Color = pColor;
// Set color properties
pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 0;
// Sets the properties of the fill symbol
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;
pFillShapeEle.Symbol = pFillSymbol;
pGra.AddElement((IElement)pFillShapeEle, 0);
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
3. Interact
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint pPt=new PointClass ();
pPt.PutCoords (e.mapX ,e.mapY );
// Change the view range of the master
axMapControl1 .CenterAt (pPt );
}