C#+AE 調整TOCControl控制項中圖層的顯示順序

來源:互聯網
上載者:User

基本思路如下:利用滑鼠左鍵將需要調整順序的圖層移動至目標位置。

①需要涉及到TOCControl的OnMouseDown事件來擷取要調整的圖層,

②OnMouseUp事件獲得靶心圖表層和索引號,

③再利用IMap提供的MoveLayer方法,將相應調整axMapControl中的圖層的顯示順序。

④最後使用TOCControl的Update方法來更新TOCControl控制項中的顯示順序;

 

具體實現代碼如下:

//全域變數
        public ITOCControl mTOCControl;
        public ILayer pMoveLayer;//需要被調整的圖層;
        public int toIndex;//將要調整到的靶心圖表層的索引;

//表單載入

private void Form1_Load(object sender, EventArgs e)
        {
         
            this.axTOCControl1.SetBuddyControl(this.axMapControl1);
           mTOCControl=this.axTOCControl1.Object as ITOCControl;
        }

 

//TOCControl控制項的OnMouseDown事件,獲得需要被調整的圖層

 private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            esriTOCControlItem item=esriTOCControlItem.esriTOCControlItemNone;
            if (e.button == 1)
            {
                IBasicMap map = null;
                ILayer layer = null;
                object other = null;
                object index = null;

                mTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
                if (item == esriTOCControlItem.esriTOCControlItemLayer)
                {
                    if(layer is IAnnotationSublayer)
                    {
                        return;
                    }
                    else
                    {
                        pMoveLayer = layer;
                    }
                }
               
            }
        }

//TOCControl控制項的OnMouseUp事件,獲得靶心圖表層及索引

//並實現axMapControl中視圖顯示的索引的變化,並更新TOCControl控制項中的顯示順序

private void axTOCControl1_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e)
        {
            if (e.button == 1)
            {
                esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap map = null;
                ILayer layer = null;
                object other = null;
                object index = null;

                mTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
                IMap pMap = this.axMapControl1.ActiveView.FocusMap;
                if(item==esriTOCControlItem.esriTOCControlItemLayer||layer!=null)
                {
                    if (pMoveLayer != null)
                    {
                        ILayer pTempLayer;
                        for (int i = 0; i < pMap.LayerCount; i++)
                        {
                            pTempLayer = pMap.get_Layer(i);
                            if (pTempLayer == layer)
                            {
                                toIndex = i;
                            }
                        }
                        pMap.MoveLayer(pMoveLayer,toIndex);
                        axMapControl1.ActiveView.Refresh();
                        mTOCControl.Update();
                    }
                }
            }
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.