axMapControl1是主地图 axMapControl2是鹰眼地图
1 private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) 2 { 3 //获取地图当前的范围(包络线) 4 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; 5 //将鹰眼地图设置为地理容器,再设置为活动视图 6 IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; 7 IActiveView pActiveView = pGraphicsContainer as IActiveView; 8 //清除鹰眼地图中的任何图形元素 9 pGraphicsContainer.DeleteAllElements(); 10 //设置矩形范围 11 IRectangleElement pRectangeEle = new RectangleElementClass(); 12 IElement pElement = pRectangeEle as IElement; 13 pElement.Geometry = pEnvelope; 14 15 //创建鹰眼图中的红线框 16 IRgbColor pColor = new RgbColor(); 17 pColor.Red = 255; 18 pColor.Blue = 0; 19 pColor.Green = 0; 20 pColor.Transparency = 255; 21 22 //创建线符号对象 23 ILineSymbol pOutline = new SimpleLineSymbolClass(); 24 pOutline.Width = 3; 25 pOutline.Color = pColor; 26 27 //设置颜色属性 28 pColor = new RgbColorClass(); 29 pColor.Red = 255; 30 pColor.Blue = 0; 31 pColor.Green = 0; 32 pColor.Transparency = 0; 33 34 //设置填充符号 35 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); 36 pFillSymbol.Color = pColor; 37 pFillSymbol.Outline = pOutline; 38 39 IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; 40 pFillShapeEle.Symbol = pFillSymbol; 41 42 pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); 43 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); 44 } 45 46 private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e) 47 { 48 if (axMapControl1.LayerCount > 0) 49 { 50 axMapControl2.Map = new MapClass(); 51 for (int i = 0; i <= axMapControl1.LayerCount - 1; i++) 52 { 53 axMapControl2.Map.AddLayer(axMapControl1.Map.get_Layer(i)); 54 } 55 axMapControl2.Extent = axMapControl1.Extent; 56 axMapControl2.Refresh(); 57 } 58 //axMapControl2.LoadMxFile(axMapControl1.DocumentFilename); 59 //axMapControl2.Refresh(); 60 //axMapControl2.Extent = axMapControl2.FullExtent; 61 } 62 63 private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) 64 { 65 if (e.button == 1) 66 { 67 IPoint pPoint = new PointClass(); 68 pPoint.PutCoords(e.mapX, e.mapY); 69 axMapControl1.CenterAt(pPoint); 70 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 71 } 72 } 73 74 private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) 75 { 76 if (axMapControl2.Map.LayerCount > 0) 77 { 78 if (e.button == 1) 79 { 80 IPoint pPoint = new PointClass(); 81 pPoint.PutCoords(e.mapX, e.mapY); 82 axMapControl1.CenterAt(pPoint); 83 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 84 } 85 else 86 { 87 IEnvelope pEnv = axMapControl2.TrackRectangle(); 88 axMapControl1.Extent = pEnv; 89 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 90 } 91 92 } 93 }