axMapControl1是主地图 axMapControl2是鹰眼地图
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
//获取地图当前的范围(包络线)
IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
//将鹰眼地图设置为地理容器,再设置为活动视图
IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
//清除鹰眼地图中的任何图形元素
pGraphicsContainer.DeleteAllElements();
//设置矩形范围
IRectangleElement pRectangeEle = new RectangleElementClass();
IElement pElement = pRectangeEle as IElement;
pElement.Geometry = pEnvelope; //创建鹰眼图中的红线框
IRgbColor pColor = new RgbColor();
pColor.Red = ;
pColor.Blue = ;
pColor.Green = ;
pColor.Transparency = ; //创建线符号对象
ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = ;
pOutline.Color = pColor; //设置颜色属性
pColor = new RgbColorClass();
pColor.Red = ;
pColor.Blue = ;
pColor.Green = ;
pColor.Transparency = ; //设置填充符号
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement;
pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle, );
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
} private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
if (axMapControl1.LayerCount > )
{
axMapControl2.Map = new MapClass();
for (int i = ; i <= axMapControl1.LayerCount - ; i++)
{
axMapControl2.Map.AddLayer(axMapControl1.Map.get_Layer(i));
}
axMapControl2.Extent = axMapControl1.Extent;
axMapControl2.Refresh();
}
//axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
//axMapControl2.Refresh();
//axMapControl2.Extent = axMapControl2.FullExtent;
} private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.button == )
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
} private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2.Map.LayerCount > )
{
if (e.button == )
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
else
{
IEnvelope pEnv = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnv;
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
} }
}