ArcGlobe移动图层顺序

长平狐 发布于 2012/11/28 15:40
阅读 535
收藏 0

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

要在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


原文链接:http://blog.csdn.net/arcgis_all/article/details/8193935
加载中
返回顶部
顶部