ArcEngine9.3的鹰眼实现

主地图控件的ExtentUpdated事件激发时,要随之改变鹰眼地图窗口中的框的位置和大小。函数为:

//鹰眼程序,根据主地图窗口的Extent,在鹰眼地图中绘制Element private void CreateElementForEagleMap(IEnvelope pEnv)//将主窗体的Extent传入 { IGraphicsContainer pGraphicsContainer; IActiveView pActiveView; pGraphicsContainer = this.axMapControl2.Map as IGraphicsContainer; pActiveView = pGraphicsContainer as IActiveView; pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle; pRectangleEle = new RectangleElementClass(); IElement pEle; pEle = pRectangleEle as IElement; pEle.Geometry = pEnv; IRgbColor pColor; pColor = new RgbColorClass(); pColor.RGB = 255; pColor.Transparency = 255;//不透明 ILineSymbol pOutline; pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1.2; pOutline.Color = pColor; pColor = new RgbColorClass(); pColor.RGB = 255; pColor.Transparency = 0;//透明 IFillSymbol pFillSymbol; pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle; pFillShapeEle = pEle as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pEle = pFillShapeEle as IElement; pGraphicsContainer.AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }

上面的函数在主窗体的load事件函数和主地图的ExtentUpdated事件函数中都要执行,前者保证初始化后,鹰眼地图存在红框。

private void MainForm_Load(object sender, EventArgs e) { //get the MapControl m_mapControl = (IMapControl3)axMapControl1.Object; //disable the Save menu (since there is no document yet) //menuSaveDoc.Enabled = false; axToolbarControl1.AddItem(new SearchData(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //axToolbarControl1.AddItem(new ClearFeatureSelection(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //axToolbarControl1.AddItem(new CreateNewDocument(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //构造鹰眼地图的红框 this.CreateElementForEagleMap(this.axMapControl1.Extent as IEnvelope); }

private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { //鹰眼程序 this.CreateElementForEagleMap(e.newEnvelope as IEnvelope); }

鹰眼地图的MouseDown事件函数如下,要求在鹰眼地图划框时,改变主地图的Extent,并在鹰眼地图中加入新的红框:

只需要根据新划的框更新主地图的Extent,由于更新了主地图的Extent,激发了其ExtentUpdated事件,因此鹰眼地图的红框也会自动更新:

private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { IEnvelope pEnvelope; pEnvelope = this.axMapControl2.TrackRectangle(); this.axMapControl1.Extent = pEnvelope; this.axMapControl1.ActiveView.Refresh(); }

效果:ArcEngine9.3的鹰眼实现