C#製作鷹眼的詳細全過程(帶注釋)執行個體代碼_C#教程

來源:互聯網
上載者:User

axMapControl1是主控制項,axMapControl2是鷹眼控制項

要看清楚事件響應

 

1.鷹眼地圖資源載入

複製代碼 代碼如下:

privatevoid axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)

        {

            //當主地圖顯示控制項的地圖更換時,鷹眼中的地圖也跟隨更換

            axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);

            axMapControl2.Extent = axMapControl2.FullExtent;

        }


2.繪製鷹眼矩形框
複製代碼 代碼如下:

private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)

        {

 

            // 得到新範圍

            IEnvelope pEnv = (IEnvelope)e.newEnvelope;

 

            IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;

            IActiveView pAv = pGra as IActiveView;

            //在繪製前,清除axMapControl2中的任何圖形元素

            pGra.DeleteAllElements();

 

            IRectangleElement pRectangleEle = new RectangleElementClass();

            IElement pEle = pRectangleEle as IElement;

            pEle.Geometry = pEnv;

 

            //設定鷹眼圖中的紅線框

            IRgbColor pColor = new RgbColorClass();

            pColor.Red = 255;

            pColor.Green = 0;

            pColor.Blue = 0;

            pColor.Transparency = 255;

            //產生一個線符號對象

            ILineSymbol pOutline = new SimpleLineSymbolClass();

            pOutline.Width = 2;

            pOutline.Color = pColor;

 

            //設定顏色屬性

            pColor = new RgbColorClass();

            pColor.Red = 255;

            pColor.Green = 0;

            pColor.Blue = 0;

            pColor.Transparency = 0;

            //設定填充符號的屬性

            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

            pFillSymbol.Color = pColor;

            pFillSymbol.Outline = pOutline;

 

            IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;

            pFillShapeEle.Symbol = pFillSymbol;

            pGra.AddElement((IElement)pFillShapeEle, 0);

            pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        }
 


3. 實現互動
複製代碼 代碼如下:

   private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)

        {

            IPoint pPt=new PointClass ();

            pPt.PutCoords (e.mapX ,e.mapY );

            //改變主控制項的視圖範圍

            axMapControl1 .CenterAt (pPt );

        }


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.