AE获得鼠标选择的图层信息

简介:

使用SelectionChanged事件

   private void axMapControl_OnSelectionChanged(object sender, EventArgs e)
    {
        if (iMapAction == 1)
        {
            //---------------------------------------Identify--------------------------------------------------//
            ITableSelection pTable;
            ILayer pLayer;
            string pointId = string.Empty;
            //获得选择的点
            for (int i = 0; i < axMapControl.LayerCount; i++)
            {
                pTable = (ITableSelection)axMapControl.get_Layer(i);
                pLayer = axMapControl.get_Layer(i);
                if (pLayer.Name == "newpoint")
                {
                    pointId = GetFieldValue(AddSelection(pTable.SelectionSet, pLayer.Name));
                    break;
                }
                pTable.Clear();
            }
            //判断点是不是为空
            if (!string.IsNullOrEmpty(pointId))
            {
                //查询是否存在于站点集合中
                if (hAreaIdList.IndexOf(pointId) != -1)
                {
                    if (_pfrmRealTimeData == null)
                    {
                        _pfrmRealTimeData = new frmRealTimeData(pointId);
                        _pfrmRealTimeData.ShowDialog();
                    }
                    else
                    {
                        //如果不是第一点击
                        if (pointIdList.Count > 1)
                        {
                            _pfrmRealTimeData = null;
                            _pfrmRealTimeData = new frmRealTimeData(pointId);
                            _pfrmRealTimeData.ShowDialog();
                        }
                    }
                    if (pointIdList.Count < 5)
                        pointIdList.Add(pointId);
                }
            }
        }
    }

 

 /// <summary>
    /// 获得选择的图层
    /// </summary>
    /// <param name="pSelection"></param>
    /// <param name="strLayer"></param>
    /// <returns></returns>
    private ArrayList AddSelection(ISelectionSet pSelection, string strLayer)
    {
        IQueryFilter pFilter = new QueryFilterClass();
        ICursor pCursor;
        pSelection.Search(pFilter, false, out pCursor);
        ESRI.ArcGIS.Geodatabase.IRow pRow;
        pRow = pCursor.NextRow();
        ArrayList Keys = new ArrayList();
        Keys.Add(strLayer);
        if (pRow != null)
        {
            IRowBuffer pBuffer;
            do
            {
                pBuffer = (IRowBuffer)pRow;
                Keys.Add(pBuffer.get_Value(0));
                pRow = pCursor.NextRow();
            } while (pRow != null);
        }
        return Keys;
    }

    /// <summary>
    /// 获得节点的值
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    private string GetFieldValue(ArrayList list)
    {
        string pointId = string.Empty;
        if (list.Count > 1)
        {
            string strLayer = string.Empty;
            strLayer = list[0].ToString();
            for (int j = 1; j < list.Count; j++)
            {
                IFeatureLayer pLayer;
                int i;
                for (i = 0; i < axMapControl.Map.LayerCount; i++)
                {
                    if (axMapControl.Map.get_Layer(i).Name == strLayer)
                        break;
                }
                pLayer = (IFeatureLayer)axMapControl.Map.get_Layer(i);
                IFeatureCursor pCursor;
                IQueryFilter pFilter = new QueryFilterClass();

                pFilter.WhereClause = " FID = " + list[i];
                pCursor = pLayer.Search(pFilter, false);
                IFeature pFeature;
                IRowBuffer pRow;
                pFeature = pCursor.NextFeature();
                if (pFeature != null)
                {
                    pRow = (IRowBuffer)pFeature;
                    for (int k = 0; k < pRow.Fields.FieldCount; k++)
                    {
                        if (pRow.Fields.get_Field(k).Name == "pointid")
                        {
                            pointId = pRow.get_Value(k).ToString();
                            break;
                        }
                    }
                }
            }
        }
        return pointId;
    }

版权说明

  如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。 
  作      者:温景良
  文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

0
0
« 上一篇: 多参数sp_executesql 
» 下一篇: 将Excel嵌入你的.Net程序-使用dsoFramer (转载)
posted @  2008-12-25 17:06  温景良(Jason) Views( 1513) Comments( 1Edit  收藏

  
#1楼   2011-03-25 20:36 |  kuaiGIS   
你的felx的文章很喜欢那里弄的啊

相关文章
UG02界面定制---左上角点击文件新建,选择做靠边栏倒数第三个Content是,选择它的基本功能,UG不想要工具栏,可以拖动删除它,最上方工具栏有定制,Ctrl + 1,文字在定制的文本,右键加命令
UG02界面定制---左上角点击文件新建,选择做靠边栏倒数第三个Content是,选择它的基本功能,UG不想要工具栏,可以拖动删除它,最上方工具栏有定制,Ctrl + 1,文字在定制的文本,右键加命令
UG01---NX10头部是标题栏 ,界面认识,进入全屏点击右下角,继续点击就退出了
UG01---NX10头部是标题栏 ,界面认识,进入全屏点击右下角,继续点击就退出了
|
6月前
Qt鼠标悬浮在图片上显示删除字样
Qt鼠标悬浮在图片上显示删除字样
VC下利用Picture控件实现png图片按钮(鼠标初始、按下、松开、获得焦点四种状态)
VC下利用Picture控件实现png图片按钮(鼠标初始、按下、松开、获得焦点四种状态)
129 0
PS实用技巧:用原始图片制作显示(正常状态)、鼠标悬浮(hover)、鼠标点击(pressed)的方法
PS实用技巧:用原始图片制作显示(正常状态)、鼠标悬浮(hover)、鼠标点击(pressed)的方法
PS实用技巧:用原始图片制作显示(正常状态)、鼠标悬浮(hover)、鼠标点击(pressed)的方法
C#鼠标拖拽,移动图片实例
最近工作需要做一个鼠标可以拖拽移动图片的功能。写了几个基本功能,勉强能用。
463 0
C#鼠标拖拽,移动图片实例