zoukankan      html  css  js  c++  java
  • C#+AE 调整TOCControl控件中图层的显示顺序

    基本思路如下:利用鼠标左键将需要调整顺序的图层移动至目标位置。

    ①需要涉及到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();
                        }
                    }
                }
            }

  • 相关阅读:
    我自己开发的工具,打印出百度贴吧某用户发表过的所有帖子
    The Smart Field Service Prototype powered by SAP FSM and Wechat
    如何阻止SAP CRM订单创建好之后,自动被置为传输状态这一行为
    C++ Primer读书笔记(3)
    C++ Primer读书笔记(2)
    Coursera台大机器学习技法课程笔记08-Adaptive Boosting
    计算机视觉目标检测的框架与过程(转)
    目标检测的图像特征提取之(一)HOG特征(转)
    Coursera台大机器学习技法课程笔记07-Blending and Bagging
    前景检测(1):VIBE
  • 原文地址:https://www.cnblogs.com/yanhan/p/2720113.html
Copyright © 2011-2022 走看看