1. 程式人生 > >ArcGlobe移動圖層順序

ArcGlobe移動圖層順序

要在TOC控制元件中移動順序,其實就是這二個操作,選擇要移動的圖層;拖動要放置的位置,但是這兩個操作牽扯到三個函式,分別是mousedown,mounsemove,mounseup。而在這三個操作裡面牽扯一個重要的方法HitTest這裡只做了對圖層的移動,其它的沒有考慮,現在直接上程式碼:

//儲存選擇的圖層
public ILayer pSeletLayer = null;
public IBasicMap pBasicMap = null;
System.Object pOther = new object();
System.Object pIndex = new object();

private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
ILayer pLayer = null;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//滑鼠左擊操作,對層的選擇
if (e.button == 1)
{
this.axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref pOther, ref pIndex);
if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
{
pSeletLayer = pLayer;
this.axTOCControl1.SelectItem(pLayer, null);
}

//重新整理SelectLayer控制元件

}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//滑鼠右擊操作
if (e.button == 2)
{
this.axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref pOther, ref pIndex);
/////////////////////////////////////////////////////////////////////////////
//顯示右擊事件視窗
if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
{
pSeletLayer = pLayer;
this.axTOCControl1.SelectItem(pLayer, null);

if (pLayer is IFeatureLayer)
{

this.pContextMenuStrip.Show(this.axTOCControl1, new System.Drawing.Point(e.x, e.y));
}
}
else if (pItem == esriTOCControlItem.esriTOCControlItemMap)
{
this.pMapMenu.Show(this.axTOCControl1, new System.Drawing.Point(e.x, e.y));
}


}
}
private void axTOCControl1_OnMouseMove(object sender, ITOCControlEvents_OnMouseMoveEvent e)
{
IBasicMap pTemBasicMap = null;
System.Object pTemOther = new object();
System.Object pTemIndex = new object();


esriTOCControlItem pTemItem = new esriTOCControlItem(); //選擇的TOC的專案名

ILayer pLayer = null;

if (e.button == 1)
{
this.axTOCControl1.HitTest(e.x, e.y, ref pTemItem, ref pTemBasicMap, ref pLayer, ref pTemOther, ref pTemIndex);

if (pTemItem != esriTOCControlItem.esriTOCControlItemNone)
{

axTOCControl1.MousePointer = esriControlsMousePointer.esriPointerCustom;
}
//重新整理SelectLayer控制元件

}
}

private void axTOCControl1_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e)
{

IBasicMap pTemBasicMap = null;
System.Object pTemOther = new object();
System.Object pTemIndex = new object();


esriTOCControlItem pTemItem = new esriTOCControlItem(); //選擇的TOC的專案名

ILayer pLayer = null;

//滑鼠左擊操作,對層的選擇
if (e.button == 1)
{
this.axTOCControl1.HitTest(e.x, e.y, ref pTemItem, ref pTemBasicMap, ref pLayer, ref pTemOther, ref pTemIndex);
if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
{
if (pSeletLayer != pLayer && pLayer!=null)
{
this.axTOCControl1.SelectItem(pLayer, null);

this.globe.Globe.GlobeDisplay.Scene.MoveLayer(pSeletLayer, CommonHelper.GetIndexByLayer(this.globe.Globe, pLayer));

this.globe.Globe.GlobeDisplay.RefreshViewers();
this.axTOCControl1.Refresh();

this.axTOCControl1.SelectItem(pSeletLayer, null);
}

}


}

}

其中GetIndexByLayer 方法是用來獲取圖層物件的索引值,程式碼如下:

public static int GetIndexByLayer(IGlobe _pGlobe,ILayer _pLayer)
{
IScene pScene = _pGlobe.GlobeDisplay.Scene;
int pIndex = 0;

for (int i = 0; i < pScene.LayerCount; i++)
{
if (pScene.get_Layer(i).Name == _pLayer.Name)
{
pIndex = i;
return pIndex;
}

}

return pIndex;
}

原文地址:http://www.gisall.com/html/63/151663-6305.html