ArcEngine鼠标向上拖动调整图层顺序

        //1)获取目标图层及索引号 2)将源图层移到目标图层 3)使用TOCControl提供的update方法更新控件显示的内容

   int toIndex;
        ILayer pMoveLayer;
        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;
               axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref
index);
               IMap pMap = axMapControl1.ActiveView.FocusMap;
               if (item == esriTOCControlItem.esriTOCControlItemLayer || layer != null)
               {
                   if (pMoveLayer != layer)//如果是原图层则不用操作
                   {
                       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();
                       axTOCControl1.Update();
                   }
               }
           }
        }

 

posted @ 2018-08-27 22:48  ParanoiaApe  阅读(541)  评论(0)    收藏  举报