鹰眼的实现
分析:主图更新地图或改变显示范围,鸟瞰图随之发生变化;点击鸟瞰图,主图移动到相应的范围进行显示;鸟瞰图上面有一个红色的框。
实现思路:
1.要添加两个MapControl控件,其中axMapControl1为主图,而axMapControl2为鸟瞰图。
2.axMapControl1的MapControl控件,OnExtentUpdated,OnMapReplaced
3. axMapControl2的MapControl控件,OnMouseDown
private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { //先获取新的范围 IEnvelope pEnvelope = e.newEnvelope as IEnvelope; //clear map2's contents IGraphicsContainer pContainter = axMapControl2.ActiveView.GraphicsContainer; pContainter.DeleteAllElements(); //绘制一个矩形框 IRectangleElement rect = new RectangleElement() as IRectangleElement; IElement pElement = rect as IElement; pElement.Geometry = pEnvelope; // IRgbColor color = new RgbColor() as IRgbColor; color.Red = 255; color.Green = 0; color.Blue = 0; color.Transparency = 255; // ILineSymbol line = new SimpleLineSymbol() as ILineSymbol; line.Width = 2; line.Color = color; // color.Transparency = 0; // IFillSymbol fill = new SimpleFillSymbol(); fill.Color = color; fill.Outline = line; // IFillShapeElement shapeElement = pElement as IFillShapeElement; shapeElement.Symbol = fill; // pContainter.AddElement(shapeElement as IElement,0); axMapControl2.ActiveView.Refresh(); } private void Form1_Load(object sender, EventArgs e) { axMapControl1.ClearLayers(); axMapControl1.ActiveView.Refresh(); OpenFileDialog open = new OpenFileDialog(); string filename = string.Empty; if (open.ShowDialog() == DialogResult.OK) { filename = open.FileName; } axMapControl1.LoadMxFile(filename); //axMapControl2.LoadMxFile(filename); axMapControl1.ActiveView.Refresh(); // axMapControl2.ActiveView.Refresh(); } private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) { for (int i = 0; i < axMapControl1.Map.LayerCount - 1; i++) { axMapControl2.AddLayer(axMapControl1.get_Layer(i)); } axMapControl2.Extent = axMapControl1.Extent; axMapControl2.Refresh(); } private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { if (e.button == 1) { IPoint point = new ESRI.ArcGIS.Geometry.Point(); point.X = e.mapX; point.Y = e.mapY; axMapControl1.CenterAt(point); axMapControl1.ActiveView.Refresh(); } }