ArcGlobe移动图层顺序

原文地址: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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值