博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
arcengine动态显示所需字段值
阅读量:6832 次
发布时间:2019-06-26

本文共 6433 字,大约阅读时间需要 21 分钟。

需求:实现和GIS桌面端中Identify的类似功能,鼠标滑动的时候可以显示鼠标所在位置的要素的指定字段的值.。

 

主要操作流程:

①先打开一个对话框,用于选择需要显示的图层和字段名

②点击确定之后,在mapControl上鼠标滑动的时候利用axMapControl的showTips功能实现实时显示,相对于Identify,取消的点击查看属性,和只能查看所有属性的弊端。

主窗体代码

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.Controls;namespace MapChuanzhi{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        public int s_flag = 0;        private void button2_Click(object sender, EventArgs e)        {            IMap pMap = this.axMapControl1.Map;            Form2 frm2 = new Form2(pMap);            frm2.formDelegate += new FormDelegate(Display);            frm2.StartPosition = FormStartPosition.CenterScreen;            frm2.ShowDialog();            s_flag = 1;        }        string LayerName = "";        List
FieldList = new List
(); public void Display(List
lc) { LayerName = lc[0].ToString(); FieldList.Clear(); for (int j = 1; j < lc.Count; j++) { FieldList.Add(lc[j].ToString()); } } private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) { switch (s_flag) { case 1: showtips(FieldList, e); break; default: break; } } private void showtips(List
index, IMapControlEvents2_OnMouseMoveEvent e) { StringBuilder sb = new StringBuilder(); string headd = string.Format("{0}:{1}", "图层", LayerName); sb.AppendLine(headd); sb.AppendLine( "————————"); for (int i = 0; i < this.axMapControl1.Map.LayerCount; i++) { if (axMapControl1.get_Layer(i).Name.ToString().Equals(LayerName)) { for (int j = 0; j < index.Count; j++) { IFeatureLayer pFLayer = axMapControl1.Map.get_Layer(i) as IFeatureLayer; pFLayer.DisplayField = index[j].ToString(); pFLayer.ShowTips = true; string Text = pFLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 1000); if (string.IsNullOrWhiteSpace(Text)) { break; } sb.AppendLine(string.Format("{0}:{1}",index[j].ToString(),Text)); } if (sb.Length == headd.Length + "————————".Length + 4) sb.Clear(); toolTip1.SetToolTip(axMapControl1, sb.ToString()); } } } }}

属性窗口代码

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.Geodatabase;using ESRI.ArcGIS.Carto;namespace MapChuanzhi{    public delegate void FormDelegate(List
FormMessage); public partial class Form2 : Form { private ESRI.ArcGIS.Carto.IMap pMap; public Form2( ESRI.ArcGIS.Carto.IMap pMap) { InitializeComponent(); // TODO: Complete member initialization this.pMap = pMap; } private void Form2_Load(object sender, EventArgs e) { for (int i = 0; i < pMap.LayerCount; i++) { this.comboBox1.Items.Add(pMap.get_Layer(i).Name.ToString()); } } string selectItems; private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { selectItems=comboBox1.SelectedItem.ToString(); for (int i = 0; i < pMap.LayerCount; i++) { if (pMap.get_Layer(i).Name.ToString() == selectItems) { IFeatureLayer pFLayer = pMap.get_Layer(i) as IFeatureLayer; IFeatureClass pFClass = pFLayer.FeatureClass; this.checkedListBox1.Items.Clear(); for (int j = 0; j < pFClass.Fields.FieldCount; j++) { this.checkedListBox1.Items.Add(pFClass.Fields.get_Field(j).Name); } try { checkedListBox1.Items.Remove("Shape"); } catch (Exception) { throw; } } } } /***************窗体委托传值*********************/ public FormDelegate formDelegate; private void button1_Click(object sender, EventArgs e) { if (this.checkedListBox1.CheckedItems == null || this.comboBox1.SelectedItem== null) return; List
cz = new List
(); cz.Add(comboBox1.SelectedItem.ToString()); for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++) { cz.Add(checkedListBox1.CheckedItems[i].ToString()); } try { cz.Remove("Shape"); } catch { } formDelegate(cz); this.Dispose(); } private void button2_Click(object sender, EventArgs e) { if (this.button2.Text == "全选") { for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { this.checkedListBox1.SetItemChecked(i, true); this.button2.Text = "取消全选"; } } else { for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { this.checkedListBox1.SetItemChecked(i, false); this.button2.Text = "全选"; } } } }}

 

转载于:https://www.cnblogs.com/clgis/p/9958516.html

你可能感兴趣的文章
珍爱生命,拒绝session。
查看>>
使用JDK原生api进行网络请求并比较
查看>>
网站安全问题的出现及解决方法
查看>>
java io FilterInputStream BufferedInputStream
查看>>
[转]shell脚本中echo显示内容带颜色
查看>>
循环队列的实现
查看>>
Hibernate的unsaved-value
查看>>
DNS故障处理一例(转)
查看>>
12月14日中国域名商解析量17强:易名增幅最大
查看>>
常见的WebPack文件、什么是WebPack
查看>>
DVD刻录机的使用与维护
查看>>
构建Postfix邮件系统(二) -- SMTP认证发信+SquirrelMail
查看>>
Oracle 使用concat函数需要注意的地方
查看>>
条件测试
查看>>
linux磁盘管理
查看>>
线上部署链路聚合bonding
查看>>
学LIUNX的常用英语补习
查看>>
单点登录CAS解决方案<一>:纯净CAS-Server
查看>>
Mysql 数据库表区分大小写问题
查看>>
什么是openstack的metadata
查看>>