arcgis for js 天地图_ArcGIS程序设计(4)

  1. 设计属性信息显示对话框

    b0f5e7a42519a52226358dbe234c5cdc.png

  2. 显示该窗体

     try            {                //执行属性查询操作                SelectFeaturesByAttribute();                //新创建属性查询窗体                FormSelection formSelection = new FormSelection(currentMap);                //将当前主窗体中MapControl控件中的Map对象赋值给FormQueryByAttribute窗体的CurrentMap属性             //   formSelection.CurrentMap = currentMap;                //显示属性查询窗体                formSelection.Show();            }            catch            { }            
  3. 显示左侧的树节点

       IFeatureLayer featureLayer; /设置临时变量存储当前矢量图层            string layerName;   //设置临时变量存储当前图层的名称            TreeNode treeNode;  //设置临时变量存储当前树节点的信息            //对Map中的每个图层进行判断并加载图层名称            for (int i = 0; i < currentMap.LayerCount; i++)            {                //如果该图层为图层组类型,则分别对所包含的每个图层进行操作                if (currentMap.get_Layer(i) is GroupLayer)                {                    //使用ICompositeLayer接口进行遍历操作                    ICompositeLayer compositeLayer = currentMap.get_Layer(i) as ICompositeLayer;                    for (int j = 0; j < compositeLayer.Count; j++)                    {                        //得到图层的名称                        layerName = compositeLayer.get_Layer(j).Name;                        //得到矢量图层对象的IFeatureLayer接口                        featureLayer = (IFeatureLayer)compositeLayer.get_Layer(j);                        //如果该图层选择集中的要素不为空,则在TreeView控件中添加一个树节点                        if (((IFeatureSelection)featureLayer).SelectionSet.Count > 0)                        {                            //新建一个树节点,将图层名称作为树节点的名称                            treeNode = new TreeNode(layerName);                            //利用树节点的Tag属性,存储当前图层的IFeatureLayer接口信息                            treeNode.Tag = featureLayer;                            //将新建的树节点添加到TreeView控件中的根节点下                            treeViewLayers.TopNode.Nodes.Add(treeNode);                        }                    }                }                //如果图层不是图层组类型,则同样在TreeView控件中的根节点下添加节点                else                {                    if (currentMap.get_Layer(i) is FeatureLayer)                    {                        layerName = currentMap.get_Layer(i).Name;                        featureLayer = (IFeatureLayer)currentMap.get_Layer(i);                        if (((IFeatureSelection)featureLayer).SelectionSet.Count > 0)                        {                            treeNode = new TreeNode(layerName);                            treeNode.Tag = featureLayer;                            treeViewLayers.TopNode.Nodes.Add(treeNode);                        }                    }                }            }            //添加完节点后将根节点展开以显示所有的图层            treeViewLayers.TopNode.Expand();            //通过IMap接口的SelectionCount属性可以获取被选择要素的数量            labelMapSelectionCount.Text = "当前地图共选择了 " + curre            ntMap.SelectionCount + " 个要素。";
  4. 点击左侧图层节点,在右侧显示查询结果

      try            {                //首先清空DataGridView中的行和列                dataGridView.Columns.Clear();                dataGridView.Rows.Clear();                //设置label显示选择的要素                //通过树节点的Tag属性获取以该节点名称命名的矢量图层                currentFeatureLayer = e.Node.Tag as IFeatureLayer;                //通过接口转换,使用IFeatureSelection接口获取图层的选择集                IFeatureSelection featureSelection = currentFeatureLayer as IFeatureSelection;                //通过ISelectionSet接口获取被选择的要素集合                ISelectionSet selectionSet = featureSelection.SelectionSet;                //通过ISelectionSet接口的Count属性可以获取被选择要素的数量                labelLayerSelectionCount.Text = "当前图层选择了 " + selectionSet.Count + " 个要素。";                //添加datagrid列名                //对当前图层要素的属性字段进行遍历,从而建立DataGridView中的列                //获取所有的属性字段                IFields fields = currentFeatureLayer.FeatureClass.Fields;                for (int i = 0; i < fields.FieldCount; i++)                {                    //通过遍历添加列,使用字段的AliasName作为DataGridView中显示的列名                    dataGridView.Columns.Add(fields.get_Field(i).Name, fields.get_Field(i).AliasName);                }                //                //对选择集进行遍历,从而建立DataGridView中的行                //定义ICursor接口的游标以遍历整个选择集                ICursor cursor;                //使用ISelectionSet接口的Search方法,使用null作为查询过滤器,cursor作为返回值获取整个选择集                selectionSet.Search(null, false, out cursor);                //进行接口转换,使用IFeatureCursor接口来获取选择集中的每个要素                IFeatureCursor featureCursor = cursor as IFeatureCursor;                //获取IFeature接口的游标中的第一个元素                IFeature feature = featureCursor.NextFeature();                //定义string类型的数组,以添加DataGridView中每一行的数据                string[] strs;                //当游标不为空时                while (feature != null)                {                    //string数组的大小为字段的个数                    strs = new string[fields.FieldCount];                    //对字段进行遍历                    for (int i = 0; i < fields.FieldCount; i++)                    {                        //将当前要素的每个字段值放在数组的相应位置                        strs[i] = feature.get_Value(i).ToString();                    }                    //在DataGridView中添加一行的数据                    dataGridView.Rows.Add(strs);                    //移动游标到下一个要素                    feature = featureCursor.NextFeature();                }            }            catch { }
  5. 选择一条记录在当前地图窗口进行定位

    //获取当前所点击的行            DataGridViewRow row = dataGridView.Rows[e.RowIndex];            //每行的第一列是要素的ObjectID,获取该信息            int objectID = Convert.ToInt32(row.Cells[0].Value);            //使用IFeatureClass接口的GetFeature方法根据ObjectID获取该要素            IFeature feature = currentFeatureLayer.FeatureClass.GetFeature(objectID);            //定义新的IEnvelope接口对象获取该要素的空间范围            ESRI.ArcGIS.Geometry.IEnvelope outEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();            //通过IGeometry接口的QueryEnvelope方法获取要素的空间范围            feature.Shape.QueryEnvelope(outEnvelope);            //将主窗体地图的当前可视范围定义为要素的空间范围,并刷新地图            IActiveView activeView = currentMap as IActiveView;                        activeView.Extent = outEnvelope;            activeView.Refresh();            
  6. 点选查询,在地图上选择查询对象,然后弹出查询对象的属性信息并在地图上高亮显示

    传递点选查询参数

     axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;            pMouseOperate = "PointSel";            
  7. 在mapcontrol控件的onmousedown中设置显示属性的代码

     case "PointSel":                     ESRI.ArcGIS.Geometry.Point pt = new ESRI.ArcGIS.Geometry.Point();                      pt.X = e.mapX;                      pt.Y = e.mapY;                      geometry = pt as IGeometry;                    axMapControl1.Map.SelectByShape(geometry, null, false);                     axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);                                       //将当前主窗体中MapControl控件中的Map对象赋值给FormQueryByAttribute窗体的CurrentMap属性                        formSelection.CurrentMap = axMapControl1.Map;                //显示属性查询窗体                formSelection.Show();                    break;                    
  8. 框选

      axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;            pMouseOperate = "RecSel";            
  9.   #region 框选                    case "RecSel":                    geometry = axMapControl1.TrackRectangle();                      axMapControl1.Map.SelectByShape(geometry, null, false);                     axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);                                      //将当前主窗体中MapControl控件中的Map对象赋值给FormQueryByAttribute窗体的CurrentMap属性                        formSelection.CurrentMap = axMapControl1.Map;                //显示属性查询窗体                formSelection.Show();                    break;                    #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值