鹰眼功能的实现

key

  • 实现鹰眼,需要两个MapControl,一个是主视图,一个是鹰眼视图;
  • 主视图和鹰眼视图内的地图数据要一致;
  • 在主视图中当前显示的地图范围,用一个红框在鹰眼视图中框起来,主视图的地图范围发生变化时,红框位置也相应变化;
  • 用鼠标在鹰眼视图中点击或移动红框时,主视图的地图范围也会发生变化。

关键代码

private void axMapControl1_OnMapReplaced ( object sender, IMapControlEvents2_OnMapReplacedEvent e )
        {
            IMap pMap;
            pMap = axMapControl1.Map;
            for (int i = 0 ; i < pMap.LayerCount ; i++)
            {
                axMapControl2.Map.AddLayer(pMap.get_Layer(i));
            }
            //设置鹰眼的显示范围:FullExtent完整显示
            axMapControl2.Extent = axMapControl2.FullExtent;
            //每次加载或删除图层后都要刷新一次MapControl
            axMapControl2.ActiveView.Refresh();
        }
//这段代码使两个
MapControl的数据保持一致
private void axMapControl2_OnMouseDown ( object sender, IMapControlEvents2_OnMouseDownEvent e )
        {
            if (e.button == 1)
            {
                IPoint pPt = new PointClass();
                pPt.X = e.mapX;
                pPt.Y = e.mapY;
                IEnvelope pEnvelop = axMapControl1.Extent as IEnvelope;
                pEnvelop.CenterAt(pPt);
                axMapControl1.Extent = pEnvelop;
                axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,null,null);
            }
else if (e.button == 2) { IEnvelope pEnvelop = axMapControl2.TrackRectangle(); axMapControl1.Extent = pEnvelop; axMapControl1.ActiveView.PartialRefresh( esriViewDrawPhase.esriViewGeography, null, null ); } }
//这段代码实现在鹰眼视图中移动红色框,主视图的地图也变化
private void axMapControl2_OnMouseMove ( object sender, IMapControlEvents2_OnMouseMoveEvent e )
        {
            if (e.button != 1)
            {
                return;
            }
            IPoint pPt = new PointClass();
            pPt.X = e.mapX;
            pPt.Y = e.mapY;
            axMapControl1.CenterAt( pPt );
            axMapControl2.ActiveView.PartialRefresh( esriViewDrawPhase.esriViewGeography, null, null );
        }
private void axMapControl2_OnExtentUpdated ( object sender, IMapControlEvents2_OnExtentUpdatedEvent e )
        {//绘制红色框
            IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
            IActiveView pAv = pGraphicsContainer as IActiveView;
            pGraphicsContainer.DeleteAllElements();
            IRectangleElement pRecElement = new RectangleElementClass();
            IElement pEle = pRecElement as IElement;
            IEnvelope pEnv;
            pEnv = e.newEnvelope as IEnvelope;
            pEle.Geometry = pEnv;
       //设置颜色
            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 200;
            pColor.Green = 0;
            pColor.Blue = 0;
            pColor.Transparency = 255;
       //产生一个线符号对象
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
            pLineSymbol.Width = 2;
            pLineSymbol.Color = pColor;
       //设置填充符号的属性
            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
       //设置透明颜色
            pColor.Transparency = 0;
            pFillSymbol.Color = pColor;
            pFillSymbol.Outline = pLineSymbol;
            IFillShapeElement pFillShapeElement = pRecElement as IFillShapeElement;
            pFillShapeElement.Symbol = pFillSymbol;
            pGraphicsContainer.AddElement(pEle,0);
            axMapControl2.ActiveView.PartialRefresh( esriViewDrawPhase.esriViewGeography, null, null );
        }

猜你喜欢

转载自www.cnblogs.com/liuliang1999/p/10746723.html