ArcGIS Engine开发-TOCControl中实现图层的拖放

  TOCControl非常好,不用写一行代码就可以将整个地图的图层信息况显示出来;
  TOCControl也非常坏,提供的接口非常少,我认为有用的只有三个:HitTest,SetBuddyControl,Update,而且Update方法一执行,整个TocControl就会重新装载一次,闪烁很厉害,实在是让人烦。要想在TOCControl中拖动图层,也并不容易,得动一动脑筋才行。
  下面是我写的一个类,用于实现拖动图层,有需要的朋友,可以复制过去了,看一看。
  需要说明的是,该类需要传入一个System.Windows.Forms.Control作为移动图层时显示要移到的位置,所以,在TOCControl上最好上一个Panel,然后传入到TocHelper中。另外,在计算同m_MovingLine显示的位置时,偶没找到什么好办法,只好设置了一个行高的参数。在正常字体时,据我的经验,行高是16,在Windows大字体显示时,行高是18,可以精确的显示。但这毕竟不是一个好办法。哪位高人要是看到了这个帖子,也请指点小弟一二,感激不尽!


None.gif public   class  TocHelper
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
private ESRI.ArcGIS.TOCControl.AxTOCControl m_toc;
InBlock.gif        
private ILayer m_layer = null;
InBlock.gif        
private object m_other,m_index;
InBlock.gif
InBlock.gif        
private LayerPopmenu m_LyMenu ;
InBlock.gif        
private DataFramePopmenu m_FrameMenu = new DataFramePopmenu();
InBlock.gif
InBlock.gif        
public event CurrentLayerChangedHandler CurrentLayerChanged;
InBlock.gif
InBlock.gif        
private bool m_Dragging = false;
InBlock.gif        
private System.Windows.Forms.Control m_MovingLine;// = new System.Windows.Forms.Panel();
InBlock.gif

InBlock.gif        
public TocHelper(ESRI.ArcGIS.TOCControl.AxTOCControl toc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            m_toc 
= toc;
InBlock.gif            m_LyMenu 
= new LayerPopmenu(this);
InBlock.gif            m_LyMenu.TOCControl 
= m_toc;
InBlock.gif            m_FrameMenu.TOCControl 
= m_toc;
InBlock.gif
InBlock.gif            m_toc.LabelEdit 
= esriTOCControlEdit.esriTOCControlManual;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////处理事件
InBlock.gif            m_toc.OnMouseDown += new ITOCControlEvents_OnMouseDownEventHandler(m_toc_OnMouseDown);
InBlock.gif            m_toc.OnMouseMove 
+= new ITOCControlEvents_OnMouseMoveEventHandler(m_toc_OnMouseMove);
InBlock.gif            m_toc.OnMouseUp 
+= new ITOCControlEvents_OnMouseUpEventHandler(m_toc_OnMouseUp);
InBlock.gif            m_toc.OnBeginLabelEdit 
+= new ITOCControlEvents_OnBeginLabelEditEventHandler(m_toc_OnBeginLabelEdit);
InBlock.gif            m_toc.OnEndLabelEdit 
+= new ITOCControlEvents_OnEndLabelEditEventHandler(m_toc_OnEndLabelEdit);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void SetMoveLine(System.Windows.Forms.Control line)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            m_MovingLine 
= line;
InBlock.gif            m_MovingLine.Size 
= new System.Drawing.Size(100,2);
InBlock.gif            m_MovingLine.BackColor 
= System.Drawing.Color.Black;
InBlock.gif            m_MovingLine.Visible 
= false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private DevExpress.XtraBars.BarManager m_pBarManager;
InBlock.gif        
public void SetBarManager(DevExpress.XtraBars.BarManager barMan)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            m_pBarManager 
= barMan;
InBlock.gif            m_LyMenu.SetBarManager(barMan);
InBlock.gif            m_FrameMenu.SetBarManager(barMan);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 获取当前图层
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public ESRI.ArcGIS.Carto.ILayer CurrentLayer
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return m_layer;
ExpandedSubBlockEnd.gif            }
            
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 刷新视图
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="layer"></param>

InBlock.gif        private void RefreshView(ILayer layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (m_toc == null)
InBlock.gif                
return;
InBlock.gif            
if (m_toc.Buddy == null)
InBlock.gif                
return;
InBlock.gif
InBlock.gif            IActiveView pView 
= null;
InBlock.gif            
if (m_toc.Buddy is  ESRI.ArcGIS.MapControl.IMapControl2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                pView 
= (m_toc.Buddy as ESRI.ArcGIS.MapControl.IMapControl2).ActiveView;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else if (m_toc.Buddy is ESRI.ArcGIS.SceneControl.ISceneControl)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                IScene scene 
= (m_toc.Buddy as ESRI.ArcGIS.SceneControl.ISceneControl).Scene;
InBlock.gif                
if (scene is IActiveView)
InBlock.gif                    pView 
= scene as IActiveView;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (pView != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (layer != null)
InBlock.gif                    pView.PartialRefresh(esriViewDrawPhase.esriViewGeography,layer,pView.Extent);
InBlock.gif                
else
InBlock.gif                    pView.Refresh();
InBlock.gif            
ExpandedSubBlockEnd.gif            }
                
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int m_DragStartY;
InBlock.gif        
public int MouseX,MouseY;
InBlock.gif        
private int m_TextHeight = 18;
InBlock.gif        
private void m_toc_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////选中对象            
InBlock.gif            ITOCControl m_TOCControl = (ITOCControl) m_toc.Object;
InBlock.gif            esriTOCControlItem item 
=esriTOCControlItem.esriTOCControlItemNone;
InBlock.gif            ILayer layer 
= null;
InBlock.gif            IBasicMap map 
= null;            
InBlock.gif            m_TOCControl.HitTest(e.x,e.y,
ref item,ref map,ref layer,ref m_other,ref m_index);
InBlock.gif            MouseX 
= e.x;MouseY =e.y;
InBlock.gif            m_DragStartY 
= e.y;
InBlock.gif
InBlock.gif            
//设置当前图层
InBlock.gif
//            if (item == esriTOCControlItem.esriTOCControlItemLayer)
InBlock.gif
//            {
InBlock.gif
                if (m_layer != layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_layer 
= layer;
InBlock.gif                    
if (CurrentLayerChanged != null)
InBlock.gif                        CurrentLayerChanged();
ExpandedSubBlockEnd.gif                }

InBlock.gif
//            }
InBlock.gif
//            else
InBlock.gif
//            {
InBlock.gif
//                if (m_layer != null)
InBlock.gif
//                {
InBlock.gif
//                    m_layer = null;
InBlock.gif
//                    if (CurrentLayerChanged != null)
InBlock.gif
//                        CurrentLayerChanged();
InBlock.gif
//                }
InBlock.gif
//            }
InBlock.gif
            m_LyMenu.CurrentLayer = m_layer;
InBlock.gif            m_FrameMenu.CurrentLayer 
= m_layer;
InBlock.gif
InBlock.gif            
//如果点中的图例,则弹出符号设置窗口
InBlock.gif
            if ((e.button == 1&& (item == esriTOCControlItem.esriTOCControlItemLegendClass)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ILegendGroup legendGroup;
InBlock.gif                ILegendClass legendClass;
InBlock.gif                legendGroup 
= m_other as ILegendGroup;
InBlock.gif                Debug.Assert(legendGroup 
!= null);
InBlock.gif                legendClass 
= legendGroup.get_Class(Convert.ToInt32(m_index.ToString()));
InBlock.gif                Debug.Assert(legendClass 
!= null);
InBlock.gif                ISymbol pSymbol 
= legendClass.Symbol;
InBlock.gif
InBlock.gif                //选择符号窗口代码去掉了。

InBlock.gif                
return;
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//如果是鼠标右键,则弹出右键菜单
InBlock.gif
            if (e.button == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                System.Diagnostics.Debug.Assert(m_pBarManager 
!= null);
InBlock.gif                
if ((item == esriTOCControlItem.esriTOCControlItemLayer) && (layer != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_pBarManager.SetPopupContextMenu(m_toc,m_LyMenu.PopMenu);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if (item == esriTOCControlItem.esriTOCControlItemMap)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_pBarManager.SetPopupContextMenu(m_toc,m_FrameMenu.PopMenu);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_pBarManager.SetPopupContextMenu(m_toc,
null);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
InBlock.gif            
//如果鼠标左键选中了一个图层,则设为拖动状态
InBlock.gif
            if ((e.button == 1&& (layer != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                m_Dragging 
= true;
InBlock.gif                m_DestLayer 
= null;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
InBlock.gif            m_TextHeight 
= m_toc.Parent.Font.Height+2
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int GetLayerIndex(IBasicMap map,ILayer layer,bool DragUp)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ILayer tmpLayer;
InBlock.gif            
for (int i=0;i<=map.LayerCount-1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tmpLayer 
= map.get_Layer(i);
InBlock.gif                
if (tmpLayer == layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{    
InBlock.gif                    
if (DragUp == true)
InBlock.gif                        
return i-1;
InBlock.gif                    
else
InBlock.gif                        
return i;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return 0;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int GetLayerIndex(ICompositeLayer groupLayer,ILayer layer,bool DragUp)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i=0;i<=groupLayer.Count-1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (groupLayer.get_Layer(i) == layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (i == groupLayer.Count-1)
InBlock.gif                        
return i;
InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if (DragUp == true)
InBlock.gif                            
return i;
InBlock.gif                        
else
InBlock.gif                            
return i+1;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return 0;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private ILayer m_DestLayer;
InBlock.gif        
private bool m_DestIsMap = false;
InBlock.gif        
private bool m_DragToCorrectPos = false;
InBlock.gif        
private void m_toc_OnMouseMove(object sender, ITOCControlEvents_OnMouseMoveEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////如果正在拖动图层
InBlock.gif            if (m_Dragging == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                m_DragToCorrectPos 
= false;
InBlock.gif
InBlock.gif                ITOCControl m_TOCControl 
= (ITOCControl) m_toc.Object;
InBlock.gif                esriTOCControlItem item 
=esriTOCControlItem.esriTOCControlItemNone;
InBlock.gif                ILayer layer 
= null;
InBlock.gif                IBasicMap map 
= null;
InBlock.gif                
object other = null;
InBlock.gif                
object index = null;
InBlock.gif                m_TOCControl.HitTest(e.x,e.y,
ref item,ref map,ref layer,ref other,ref index);
InBlock.gif                
InBlock.gif                m_DestIsMap 
= false;
InBlock.gif                m_DestLayer 
= layer;
InBlock.gif                
if (item == esriTOCControlItem.esriTOCControlItemMap)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_DestIsMap 
= true;
InBlock.gif
InBlock.gif                    
int yy;                    
InBlock.gif                    yy 
= Convert.ToInt32(Math.Floor(e.y/m_TextHeight) * m_TextHeight)+m_TextHeight;
InBlock.gif
InBlock.gif                    m_MovingLine.Location 
= new System.Drawing.Point(30,yy);
InBlock.gif                    m_MovingLine.Width 
= m_toc.Width - 35;
InBlock.gif                    m_MovingLine.Visible 
= true;
InBlock.gif                    m_toc.MousePointer 
= ESRI.ArcGIS.SystemUI.esriControlsMousePointer.esriPointerDefault;                    
InBlock.gif                    m_DragToCorrectPos 
= true;
InBlock.gif                                
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if ((item == esriTOCControlItem.esriTOCControlItemLayer) && (layer != m_layer) && (layer != null))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
if (m_DestLayer is IGroupLayer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        m_MovingLine.Visible 
= false;
InBlock.gif                        m_toc.MousePointer 
= ESRI.ArcGIS.SystemUI.esriControlsMousePointer.esriPointerLabel;
InBlock.gif                        m_DragToCorrectPos 
= true;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
int yy;                    
InBlock.gif                        
if (e.y > m_DragStartY)  //向下拖放
ExpandedSubBlockStart.gifContractedSubBlock.gif
                        dot.gif{
InBlock.gif                            yy 
= Convert.ToInt32(Math.Floor(e.y/m_TextHeight) * m_TextHeight)+m_TextHeight;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else  //向上拖放
ExpandedSubBlockStart.gifContractedSubBlock.gif
                        dot.gif{
InBlock.gif                            yy 
= Convert.ToInt32(Math.Floor(e.y/m_TextHeight) * m_TextHeight);                        
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        m_MovingLine.Location 
= new System.Drawing.Point(30,yy);
InBlock.gif                        m_MovingLine.Width 
= m_toc.Width - 35;
InBlock.gif                        m_MovingLine.Visible 
= true;
InBlock.gif                        m_toc.MousePointer 
= ESRI.ArcGIS.SystemUI.esriControlsMousePointer.esriPointerDefault;                    
InBlock.gif                        m_DragToCorrectPos 
= true;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_MovingLine.Visible 
= false;
InBlock.gif                    m_toc.MousePointer 
= ESRI.ArcGIS.SystemUI.esriControlsMousePointer.esriPointerDefault;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 取得图层的上一级对象,可能是igrouplayer,或ibasicmap
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="map"></param>
InBlock.gif        
/// <param name="layer"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        private object GetLayerParent(IBasicMap map,ILayer layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ILayer tmpLayer;
InBlock.gif            
for (int i=0;i<= map.LayerCount-1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tmpLayer 
= map.get_Layer(i);
InBlock.gif                
if (tmpLayer == layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return map;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if (tmpLayer is IGroupLayer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    IGroupLayer ly 
= FindParentGroupLayer(tmpLayer as IGroupLayer,layer);
InBlock.gif                    
if (ly != null)
InBlock.gif                        
return ly;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return map;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private IGroupLayer FindParentGroupLayer(IGroupLayer groupLayer,ILayer layer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (!(groupLayer is ICompositeLayer))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return groupLayer;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            ICompositeLayer comLayer 
= groupLayer as ICompositeLayer;
InBlock.gif            ILayer tmpLayer;
InBlock.gif            
for (int i=0;i<=comLayer.Count-1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tmpLayer 
= comLayer.get_Layer(i);
InBlock.gif                
if (tmpLayer == layer)
InBlock.gif                    
return groupLayer;
InBlock.gif                
else if (tmpLayer is IGroupLayer)
InBlock.gif                    
return FindParentGroupLayer(tmpLayer as IGroupLayer,layer);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 在grouplayer中移动图层
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="pGroupLayer"></param>
InBlock.gif        
/// <param name="pLayer"></param>
ExpandedSubBlockEnd.gif        
/// <param name="nIndex"></param>

InBlock.gif        private void MoveLayerTo(IGroupLayer pGroupLayer, ILayer pLayer, int nIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            ICompositeLayer pCompositeLayer 
= pGroupLayer as ICompositeLayer;
InBlock.gif
//            if(pCompositeLayer.Count < 2)
InBlock.gif
//                return ;
InBlock.gif

InBlock.gif            
if(pCompositeLayer.Count-1 == nIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                pGroupLayer.Delete(pLayer);
InBlock.gif                pGroupLayer.Add(pLayer);
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            IArray pArray 
= new ArrayClass();
InBlock.gif
InBlock.gif            
for(int i = 0; i < pCompositeLayer.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                pArray.Add(pCompositeLayer.get_Layer(i));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            pGroupLayer.Clear();
InBlock.gif            ILayer pLayer1;
InBlock.gif            
for(int i = 0; i < pArray.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(pCompositeLayer.Count  == nIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    pGroupLayer.Add(pLayer);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                pLayer1  
= pArray.get_Element(i) as ILayer;
InBlock.gif                
if(pLayer1 == pLayer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                pGroupLayer.Add(pLayer1);
InBlock.gif
ExpandedSubBlockEnd.gif            }
            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void m_toc_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (m_Dragging == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif                
check dragging conditions#region check dragging conditions
InBlock.gif                m_Dragging 
= false;
InBlock.gif                m_toc.MousePointer 
= ESRI.ArcGIS.SystemUI.esriControlsMousePointer.esriPointerDefault;
InBlock.gif                
if (m_toc == null)
InBlock.gif                    
return ;
InBlock.gif                
if (m_toc.Buddy == null)
InBlock.gif                    
return ;
InBlock.gif                
if (m_DragToCorrectPos == false)
InBlock.gif                    
return;
InBlock.gif                m_DragToCorrectPos 
= false;
InBlock.gif                m_MovingLine.Visible 
= false;
InBlock.gif
InBlock.gif                IMap map
=null;
InBlock.gif                IScene scene
=null;
InBlock.gif                
if (m_toc.Buddy is IMapControl2)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    map 
= (m_toc.Buddy as IMapControl2).Map;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if (m_toc.Buddy is ESRI.ArcGIS.SceneControl.ISceneControl)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    scene 
= (m_toc.Buddy as ESRI.ArcGIS.SceneControl.ISceneControl).Scene;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                IBasicMap bmap;
InBlock.gif                
if (map != null)
InBlock.gif                    bmap 
= map as IBasicMap;
InBlock.gif                
else 
InBlock.gif                    bmap 
= scene as IBasicMap;
InBlock.gif                
if (bmap.LayerCount ==0)
InBlock.gif                    
return;
InBlock.gif
ExpandedSubBlockEnd.gif                
#endregion

InBlock.gif
InBlock.gif                
bool destIgnoreGroupLayer = false;
InBlock.gif                
if (m_DestIsMap == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_DestLayer 
= bmap.get_Layer(0);
InBlock.gif                    destIgnoreGroupLayer 
= true;
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if (m_DestLayer == null)
InBlock.gif                    
return;
InBlock.gif                
if (m_layer == m_DestLayer)
InBlock.gif                    
return;
InBlock.gif
InBlock.gif                
bool DragUp;  //是否正向上拖放
InBlock.gif
                DragUp = (e.y < m_DragStartY);
InBlock.gif                
int destIndex;
InBlock.gif
InBlock.gif                
object buddy = m_toc.Buddy;
InBlock.gif                m_toc.SetBuddyControl(
null);
InBlock.gif
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
object srcGroupLayer = GetLayerParent(bmap,m_layer);
InBlock.gif                    
object destGroupLayer = GetLayerParent(bmap,m_DestLayer);                
InBlock.gif                
InBlock.gif                    
//先删除源图层
InBlock.gif
                    if (srcGroupLayer is GroupLayer)
InBlock.gif                        (srcGroupLayer 
as IGroupLayer).Delete(m_layer);
InBlock.gif                    
else
InBlock.gif                        bmap.DeleteLayer(m_layer);
InBlock.gif
InBlock.gif                    
//再加入,并移到合适位置
InBlock.gif
                    if ((m_DestLayer is IGroupLayer) && (destIgnoreGroupLayer == false))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        (m_DestLayer 
as IGroupLayer).Add(m_layer);
InBlock.gif                        destIndex 
= GetLayerIndex(m_DestLayer as ICompositeLayer,m_layer,DragUp);                    
InBlock.gif                    
InBlock.gif                        MoveLayerTo(m_DestLayer 
as IGroupLayer,m_layer,destIndex);
InBlock.gif                        RefreshView(m_DestLayer);                                        
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else if (destGroupLayer is IGroupLayer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{                    
InBlock.gif                        (destGroupLayer 
as IGroupLayer).Add(m_layer);
InBlock.gif                        destIndex 
= GetLayerIndex(destGroupLayer as ICompositeLayer,m_DestLayer,DragUp);                    
InBlock.gif                                        
InBlock.gif                        MoveLayerTo(destGroupLayer 
as IGroupLayer,m_layer,destIndex);    
InBlock.gif                        RefreshView(destGroupLayer 
as ILayer);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        bmap.AddLayer(m_layer);
InBlock.gif                        destIndex 
= GetLayerIndex(bmap,m_DestLayer,DragUp);
InBlock.gif                                            
InBlock.gif                        
if (bmap is IMap)
InBlock.gif                            (bmap 
as IMap).MoveLayer(m_layer,destIndex);
InBlock.gif                        
else if (bmap is IScene)
InBlock.gif                            (bmap 
as IScene).MoveLayer(m_layer,destIndex);                    
ExpandedSubBlockEnd.gif                    }
    
InBlock.gif    
ExpandedSubBlockEnd.gif                }

InBlock.gif                
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    m_toc.SetBuddyControl(buddy);  
//重新绑定,并刷新toc
ExpandedSubBlockEnd.gif
                }

InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void m_toc_OnBeginLabelEdit(object sender, ITOCControlEvents_OnBeginLabelEditEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            e.canEdit 
= false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void m_toc_OnEndLabelEdit(object sender, ITOCControlEvents_OnEndLabelEditEvent e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值