思路:axMapControl1加载主图时,触发其OnMapReplaced事件,将加载的图层同样加载到鹰眼控件即axMapControl2中,当主图的extent变化例如放大缩小事件,会触发主图的OnExtentUpdated事件,此时设置矩形边框的颜色等参数。另外需要在点击鹰眼图层时(OnMouseDown事件)使得主图范围随之变化。
#region 鹰眼实现代码
private void axMapControl1_OnMapReplaced_1(object sender,IMapControlEvents2_OnMapReplacedEvent e)
//这个函数不会刷新,但是只对地图文档有用,shp无效
{
for (int i = axMapControl1.Map.LayerCount - 1; i >= 0; i--)
// if (axMapControl1.Map.get_Layer(i).Visible==true)
axMapControl2.Map.AddLayer(axMapControl1.Map.get_Layer(i));
axMapControl2.Extent = axMapControl2.FullExtent;
axMapControl2.Refresh();
}
//互动
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);