AE功能扩展一

1、添加栅格影像
基本思路:声明栅格工作空间→创建栅格数据集对象→创建金字塔→声明图层对象→刷新地图控件

private void AddBaseMap(string filepath){IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filepath), 0); IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace; IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(filepath)); // 创建金字塔IRasterPyramid pRasterPyramid = pRasterDataset as IRasterPyramid; if (!pRasterPyramid.Present){pRasterPyramid.Create(); } // 栅格图层IRasterLayer pRasterLayer = new RasterLayer(); pRasterLayer.CreateFromDataset(pRasterDataset); ILayer pLayer = pRasterLayer as ILayer; // 刷新地图axMapControl1.AddLayer(pLayer,axMapControl1.LayerCount); axMapControl1.Refresh(); }


2、图层顺序调整(记得绑定TOC的OnMouseUp事件)
基本思路:判断左键→声明参数→遍历得到该图层→改变图层顺序→刷新地图
private void axTOCControl1_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e){try{if (e.button == 1 && pMoveLayer != null && pMoveLayerPoint.Y != e.y){esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone; IBasicMap pBasicMap = null; object unk = null; object data = https://www.it610.com/article/null; ILayer pLayer = null; axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref unk, ref data); IMap pMap = axMapControl1.ActiveView.FocusMap; if (pItem == esriTOCControlItem.esriTOCControlItemLayer || pLayer != null){if (pMoveLayer != pLayer){ILayer pTempLayer; for (int i = 0; i < pMap.LayerCount; i++){pTempLayer = pMap.get_Layer(i); if (pTempLayer == pLayer){toIndex = i; }}}}else if (pItem == esriTOCControlItem.esriTOCControlItemMap){toIndex = 0; }else if (pItem == esriTOCControlItem.esriTOCControlItemNone){toIndex = pMap.LayerCount - 1; }pMap.MoveLayer(pMoveLayer, toIndex); axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); }}catch (Exception ex){MessageBox.Show(ex.Message); }}


3、图层上右键
基本思路:判断右键→判断图层→显示控件
这里需要用到一个控件contextMenuStrip。其实右键还有另外的方法,具体可百度,不赘述,有任何问题欢迎随时交流。
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e){ESRI.ArcGIS.Controls.esriTOCControlItem Item = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone; IBasicMap pBasicMap = null; ILayer pLayer = null; object other = null; object index = null; axTOCControl1.HitTest(e.x, e.y, ref Item, ref pBasicMap, ref pLayer, ref other, ref index); //实现赋值//图层右键if (e.button == 2){pTocFeatureLayer = pLayer as IFeatureLayer; m_Layer = pLayer; if (Item == esriTOCControlItem.esriTOCControlItemLayer)//点击的是图层的话,就显示右键菜单{contextMenuStrip1.Show(axTOCControl1, new System.Drawing.Point(e.x, e.y)); //显示右键菜单,并定义其相对控件的位置,正好在鼠标出显示}} }

AE功能扩展一
文章图片

也是想出一个系列吧,在自己刚开始学习AE开发的时候苦于查找书籍代码不可用或者各博客描述不够详尽到我一个小白可以读懂,然后踩了各种各样的坑(虽然踩过的坑忘记了很多),其间很多代码的产生都是始于Copy,然后结合自己的查询资料和思考所得,还是希望自己能帮助到各位正在学习或使用的各位同仁吧。
AE功能扩展一
文章图片

扫码关注公众号
【AE功能扩展一】

    推荐阅读