AE+C#实现鹰眼功能——(二)(带鼠标拖动)

vs2005+AE9.2实现,主要功能:鹰眼视图里面鼠标左键画红框,右键拖动
代码中主视图为Mapcontrol1,鹰眼视图为MapControl2。
主要利用了Envelope进行视图范围传递,从而控制视图同步等。
代码如下:
几个变量声明 :
         // 变量
        IMapDocument pMapDocument  =   new  MapDocumentClass();
        IEnvelope pEn 
=   new  EnvelopeClass();
        
object  oFillobject  =   new   object ();
        
private   void  CreateOverviewSymbol()
        
{
            IRgbColor iRgb 
= new RgbColorClass();
            iRgb.RGB 
= 255;
            ILineSymbol pOutline 
= new SimpleLineSymbolClass();
            pOutline.Color 
= iRgb;
            pOutline.Width 
= 2.3;
            ISimpleFillSymbol pSimpleFillSymbol 
= new SimpleFillSymbolClass();
            pSimpleFillSymbol.Outline 
= pOutline;
            pSimpleFillSymbol.Style 
= esriSimpleFillStyle.esriSFSHollow;
            oFillobject 
= pSimpleFillSymbol;
        }

控制拖动变量:
         private  IMoveEnvelopeFeedback pSmallViewerEnvelope; // 鹰眼小地图的红框,IMoveEnvelopeFeedback,用来移动Envelope的接口
         private  IPoint pSmallViewerMouseDownPt; // 拖动时鼠标落点
         private   bool  isTrackingSmallViewer  =   false // 标识是否在拖动
         static   int  moveCount  =   0 ; // 记录移动的个数,为移动过程中显示红框用。

axMapControl1_OnMapReplaced
事件:
 axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
两个视图加载数据可能存在鹰眼视图数据显示不完全(不知道是不是我电脑的毛病。。。),这样加载可以控制数据的同步更新

axMapControl1_OnExtentUpdated事件:
            pEn  =  e.newEnvelope  as  IEnvelope;
            axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, 
null null );

axMapControl1_OnAfterDraw
            esriViewDrawPhase viewDrawPhase  =  (esriViewDrawPhase)e.viewDrawPhase;
            
if  (viewDrawPhase  ==  esriViewDrawPhase.esriViewForeground)
            
{
                axMapControl2.DrawShape(pEn, 
ref oFillobject);
            }

axMapControl2_OnMouseDown
             if (e.button == 1 ) // 左键画红框
             {
            pEn 
= axMapControl2.TrackRectangle();
            axMapControl1.Extent 
= pEn;
            axMapControl2.DrawShape(pEn, 
ref oFillobject);

            
if (e.button == 2)//右键拖动红框
            {
                pSmallViewerMouseDownPt 
= new PointClass();
                pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
                axMapControl1.CenterAt(pSmallViewerMouseDownPt);

                isTrackingSmallViewer 
= true;
                
if (pSmallViewerEnvelope == null)
                
{
                    pSmallViewerEnvelope 
= new MoveEnvelopeFeedbackClass();
                    pSmallViewerEnvelope.Display 
= axMapControl2.ActiveView.ScreenDisplay;
                    pSmallViewerEnvelope.Symbol 
= (ISymbol)oFillobject;
                }

                pSmallViewerEnvelope.Start(pEn, pSmallViewerMouseDownPt);

 axMapControl2_OnMouseMove
             if  (isTrackingSmallViewer)
            
{
                moveCount
++;
                
if (moveCount % 4 == 0)//因为一刷新,红框就没了。所以每移动4次就刷新一下,保持红框的连续性。
                    axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, nullnull);
                pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
                pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);
            }
       

axMapControl2_OnMouseUp
             if  (pSmallViewerEnvelope  !=   null )
            
{
                pEn 
= pSmallViewerEnvelope.Stop();
                axMapControl1.Extent 
= pEn;
                isTrackingSmallViewer 
= false;
            }

Form初始化:
            axMapControl1.LoadMxFile( @" load data " );
            pEn 
=  axMapControl1.Extent; // 鹰眼红框初始化
            CreateOverviewSymbol();

经过测试可以实现鹰眼中画红框和拖动功能。
现在存在问题是,拖动功能还不太完善,抓紧研究,有了结果在贴上来。
其中,拖动部分思路即代码来自ESRI中国社区AE版。

你可能感兴趣的:(C#)