基于C#的AE二次开发之图层右键菜单打开属性表及图层相关操作

我的开发环境为ArcGIS Engine 10.2与Visual studio2010。主地图名称为axMapControl1,Toc目录名为axTOCControl1。(注意相关事件的添加与动态链接库的引入)!

  • 效果预览

  • 实现方法
  1. 引入contextMenuStrip工具,并添加菜单栏工具目录。我这里有打开属性表、图层可选、图层不可选、缩放至图层、移除图层这几个功能。

  2. 在解决方案中,创建属性表窗体OpenAtrributeForm.cs,添加工具箱数据栏中的DataGridView组件,命名为dataGridView1,调整好大小后,写入相关实现代码。(建议选择性地复制)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;namespace MyMapControlApplication01.Attribute
{public partial class OpenAtrributeForm : Form{public OpenAtrributeForm(){InitializeComponent();}//获取主窗体传入的图层private IFeatureLayer currentFeatureLayer;public IFeatureLayer CurrentFeatureLayer{get { return currentFeatureLayer; }set { currentFeatureLayer = value; }}//获取主窗体传入的地图private IMap currentMap;public IMap CurrentMap{get { return currentMap; }set { currentMap = value; }}//定义窗体显示方法,等待调用public void InitUI(){if (currentFeatureLayer == null) return;DataTable pTable = new DataTable();//查询所有的列标题for (int i = 0; i < currentFeatureLayer.FeatureClass.Fields.FieldCount; i++){pTable.Columns.Add(currentFeatureLayer.FeatureClass.Fields.get_Field(i).AliasName,Type.GetType("System.Object"));}//查询要素类中的所有的要素IFeatureCursor pCursor = currentFeatureLayer.Search(null, false);IFeature pFeature = pCursor.NextFeature();//遍历游标查询要素类中的所有要素的字段信息while (pFeature != null){DataRow pRow = pTable.NewRow();for (int k = 0; k < pFeature.Fields.FieldCount; k++){//将Shape列字段,改为对应的类型。默认显示的是代码类型if (pFeature.Fields.get_Field(k).Name == "Shape"){if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint){pRow[k] = "点要素";}else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline){pRow[k] = "线要素";}else if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon){pRow[k] = "面要素";}}else{pRow[k] = pFeature.get_Value(k).ToString();}                  }pTable.Rows.Add(pRow);pFeature = pCursor.NextFeature();}//将查询到的数据添加到窗体表格中dataGridView1.DataSource = pTable;}#region 高亮显示并缩放至要素private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e){if (e.RowIndex == -1) return;DataGridViewRow pRow = dataGridView1.Rows[e.RowIndex];int index = Convert.ToInt32(pRow.Cells[0].Value);IFeature pFeature = currentFeatureLayer.FeatureClass.GetFeature(index);IEnvelope pEnvelope = new Envelope() as IEnvelope;pFeature.Shape.QueryEnvelope(pEnvelope);IActiveView pView = currentMap as IActiveView;pView.FocusMap.ClearSelection();IFeatureSelection pSelection = currentFeatureLayer as IFeatureSelection;pSelection.Add(pFeature);pView.Extent = pEnvelope;pView.Refresh();}#endregion}
}
  1. 在地图所在的主窗体里,给添加Toc目录(axTOCControl1)添加OnMouseDown事件,写入如下代码。
  • 类库
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
  • 实现代码
#region TOCC右键菜单及其实现
private IFeatureLayer pToccFeatureLayer = null;//当前选择的要素类图层
private OpenAtrributeForm OpenAtrribute = null;//引入创建的属性表窗体
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{//鼠标点击右键,触发contextMenuStrip的显示if (e.button == 2){esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;IBasicMap pMap = null;ILayer pLayer = null;object unk = null;object data = null;axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pLayer != null){pToccFeatureLayer = pLayer as IFeatureLayer;//如果不写图层可选或不可选栏目,下面的两行代码不是必须的图层可选ToolStripMenuItem.Enabled = ! pToccFeatureLayer.Selectable;图层不可选ToolStripMenuItem.Enabled = pToccFeatureLayer.Selectable;//contextMenuStrip的显示,出现在鼠标点击位置contextMenuStrip1.Show(Control.MousePosition);}}
}//打开属性表窗体点击事件
private void 打开属性表ToolStripMenuItem_Click(object sender, EventArgs e)
{OpenAtrribute = new OpenAtrributeForm();OpenAtrribute.CurrentFeatureLayer = pToccFeatureLayer;OpenAtrribute.CurrentMap = axMapControl1.Map;OpenAtrribute.InitUI();OpenAtrribute.Show();
}//要素类图层允许被选择功能
private void 图层可选ToolStripMenuItem_Click(object sender, EventArgs e)
{pToccFeatureLayer.Selectable = true;图层可选ToolStripMenuItem.Enabled = !图层不可选ToolStripMenuItem.Enabled;
}//要素类图层不允许被选择功能
private void 图层不可选ToolStripMenuItem_Click(object sender, EventArgs e)
{pToccFeatureLayer.Selectable = false;图层可选ToolStripMenuItem.Enabled = !图层不可选ToolStripMenuItem.Enabled;
}//移除要素类图层功能
private void 移除图层ToolStripMenuItem_Click(object sender, EventArgs e)
{DialogResult result = MessageBox.Show("确定要移除[" + pToccFeatureLayer .Name+ "]图层吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);if (result == DialogResult.OK){axMapControl1.Map.DeleteLayer(pToccFeatureLayer);}
}//缩放至要素类图层功能
private void 缩放至图层ToolStripMenuItem_Click(object sender, EventArgs e)
{IEnvelope pEnvelope = pToccFeatureLayer.AreaOfInterest;axMapControl1.ActiveView.Extent = pEnvelope;axMapControl1.Refresh();
}#endregion

感兴趣的小伙伴们快去试试吧,对于不明白的地方可以留言提问,博主看到后会第一时间解答。

基于C#的AE二次开发之图层右键菜单打开属性表及图层相关操作相关推荐

  1. C#+AE开发TOCControl右键菜单打开属性表/图层目录右键功能

    文章转载自网易云博客,最初原创博客链接已失效,不再给出.仅给出转载链接: C# AE开发 TOCControl 右键打开图层属性表 致谢! 华丽丽的分割线/ 在ArcMap中,单击图层右键菜单中的&q ...

  2. 基于C#的AE二次开发导出地图为JPG、TIF、PDF图片

    基于C#的AE二次开发导出地图为JPG.TIF.PDF图片 我的开发环境为ArcGIS Engine 10.2与Visual studio2010.创建一个菜单或按钮,创建一个点击事件,粘贴代码即可实 ...

  3. 基于C#的AE二次开发之地图标注

    基于C#的AE二次开发之地图标注 我的开发环境为ArcGIS Engine 10.2与Visual studio2010.主地图名称为axMapControl1,创建一个菜单或按钮,创建一个点击事件, ...

  4. 基于C#的AE二次开发-地图渲染之分级设色符号化

    基于C#的AE二次开发-地图渲染之分级设色渲染符号化 我的开发环境为ArcGIS Engine 10.2与Visual studio2010.主地图名称为axMapControl1,Toc目录名为ax ...

  5. 基于C#的AE二次开发之主界面设计

    上篇文章介绍了AE的安装与配置,下面介绍在VS2012中AE的简单主界面设计方法. 一.项目创建 1.打开VS2012建立项目 在打开界面后,点击新建项目,在弹出的界面中选择Visual C#--Ar ...

  6. python在材料模拟中的应用_基于Python的ABAQUS二次开发及在板料快速冲压成形模拟中的应用...

    2009 doi :10 1 3969/ j 1 issn 1 1007 2 2012 1 2009 1 04 1 013 基于 Python 的 ABAQUS 二次开发及在板料快速 冲压成形模拟中的 ...

  7. sw二次开发 python_基于C#的SolidWorks二次开发.doc

    摘要: 气动电阻点焊钳已经被各大汽车制造厂商广泛运的用于汽车焊接工艺中.它以无污染.压力稳定.动作敏捷等优点逐步替代了国内常见的液压传动焊钳,改变了液压传动滞缓的现象,从而达到了焊接循环的要求.本次毕 ...

  8. 陈伯雄lisp_基于AutoLisp的AutoCAD二次开发自动生成系统图

    龙源期刊网 http://www.qikan.com.cn 基于 AutoLisp 的 AutoCAD 二次开发自动 生成系统图 作者:郎建山 金江 来源:<科技视界> 2013 年第 2 ...

  9. CAD自控lisp_基于AutoLisp的AutoCAD二次开发自动生成系统图

    基于 AutoLisp 的 AutoCAD 二次开发自动生成系统图 [摘 要]本文主要阐述了应用 autolisp 语言二次开发 autocad 自动生成系统图的实现方案. [关键词] autocad ...

最新文章

  1. C++和操作系统面试问题分类
  2. 怎么添加本地音乐_网易云音乐:60G免费云盘+隐藏彩蛋、技巧
  3. 为什么map对象不能使用stl中的sort函数
  4. Tomcat的web项目部署方式
  5. mysql gtid 主主_mysql GTID主从复制(主库在线,添加新丛库)
  6. monaco-editor 监听保存按钮
  7. bootstraptable 怎么在特定行添加数据_同等权限下多任职之间数据权限的实例
  8. 一文读懂 JavaScript 和 Python 九大语义区别
  9. JAVA指定范围生成随机数
  10. c语言宏定义数组_利用数组处理批量数据 C语言程序编写定义与利用数组技巧全归纳...
  11. php array函数 array_keys返回数组的键值
  12. MATLAB 2018a 安装
  13. 项目实施工程师的工作
  14. python中install语法错误_找不出python的语法错误该如何解决?
  15. 教你用Python实现经典游戏《小蜜蜂》
  16. H264码流的 ps封装
  17. 亚马逊邮件关联 关联原因?邮件
  18. NUCLEO-F767ZI以太网功能实现笔记本电脑不开盖开机
  19. Unity3D集成腾讯语音GVoice SDK
  20. twitter java_将twitter集成到你的Java程序中

热门文章

  1. python flask 微信小程序_python-flask微信小程序搭建
  2. iOS Swift 高仿微信
  3. Spring事务For循环中的代码单独为一个事务,循环一次提交一次事务
  4. 蓝桥杯单片机学习过程记录(二十七)超声波模块
  5. 使用建造者模式(Builder Pattern) 设计Excel导出场景,附源码
  6. 论文笔记:SIFT(Scale-invariant feature transform 尺度不变特征变换)
  7. android工程文件assts,Android初始化FaceSDK报错
  8. selenium使用PhantomJS浏览器报错module ‘selenium.webdriver‘ has no attribute ‘PhantomJS‘
  9. 复盘2020年全球科技行业:5G建设加速、半导体行业洗牌、云计算爆发 | TMT观察...
  10. MySQL单元选择题及答案(期末复习题)