arcengine动态显示所需字段值

摘要:
主要操作流程:①打开对话框,选择要显示的图层和字段名称;②单击“确定”,然后使用axMapControl的showTips功能在单击mapControl时实现实时显示。与“标识”相比,单击“取消”可查看属性,并且只查看所有属性。

需求:实现和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<string> FieldList = new List<string>();
        public void Display(List<string> 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<string> 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<string> 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<string> cz = new List<string>();
            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 = "全选";
                }
            }
        }
        


    }
}

免责声明:文章转载自《arcengine动态显示所需字段值》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇OpenGL ES3使用MSAA(多重采样抗锯齿)的方法Oracle数据库优化器的优化方式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

利用ARCGIS和LocaSpace Viewer无限制免费下载高清的谷歌卫星影像

卫星影像可以当做我们内业成图时的工作参考。目前市面上出现的几款好用的卫星图片下载工具,比如91卫图助手、bigemap等软件,都可以自定义导出坐标系及参数,但存在使用限制,比如限制了单次下载大小或者每日下载大小等。 也有无限制下载卫星地图的软件,比如LocaSpace Viewer,但是该软件最终导出只能是WGS84坐标系下的卫星影像,无法直接导出北京5...

ArcMap 0 (ArcGIS10.2安装(完善版--能解决常见问题))

一入GIS深似海,从此相逢是故人(这句话适合初步接触GIS的,我算是初窥门径。还是道行太浅,只是多了感慨) 一、前言: 1. 本人GIS专业,对于ArcGIS较为熟悉。由于专业和其它经历需要,接触过不少各种类型的软件如ENVI、Visual Studio 各版本(10、12、15、17)、matlab、CAD、CASS、VC6.0、python、spss、...

Arcgis镶嵌数据集java代码操作

转自:http://www.cdtarena.com/javapx/201307/9105.html 镶嵌数据集结合了之前arcgis管理影像的栅格目录和栅格数据集,为解决海量影像管理提供了很好的方案!为什么要使用镶嵌数据集?•可伸缩性海量影像管理 •重叠影像管理•管理离散数据集大量的空值区域•多种传感器数据支持•流畅的影像更新•所有比例尺下无缝显示•保留...

arcgis api的三种查询实现

1. 引言 FindTask:Search a map service exposed by the ArcGIS Server REST API based on a string value. The search can be conducted on a single field of a single layer, on many fields...

ArcPad 10 的安装部署

ArcPad是安装在手持设备或者移动终端的一个外业ArcGIS产品,也就是说ArcPad是Esri的一款软件产品,而不是硬件设备哦。尽管不比ArcGIS Desktop功能复杂缤纷,可是对于野外作业、数据採集等工作来说,算是功能十分丰富了。 说到安装,首先要了解系统要求,http://resources.arcgis.com/zh-cn/con...

《ArcGIS Runtime SDK for Android开发笔记》

开发笔记之基础教程 ArcGIS Runtime SDK for Android 各版本下载地址 《ArcGIS Runtime SDK for Android开发笔记》——(1)、Android Studio下载与安装 《ArcGIS Runtime SDK for Android开发笔记》——(2)、Android Studio基本配置与使用 《Arc...