SuperMap-点选查询

点选查询,根据鼠标所点击的位置得到查询对象,然后把查询对象的属性信息返回给用户

1)设置鼠标状态参数optionofmouse

   private string OptionofMouse="";

2)设置当前的鼠标状态为十字叉丝

  OptionofMouse = "PTSel"; mapControl1.Cursor = MapControl.Cursors.Cross;

3)得到查询位置的坐标

4)根据鼠标位置进行查询

5)将查询结果在地图上高亮显示

                    System.Drawing.Point pt = new System.Drawing.Point();                    pt.X = e.X;                    pt.Y = e.Y;                    //屏幕坐标转成地理坐标                    Point2D pt2d = mapControl1.Map.PixelToMap(pt);                    GeoPoint geopt = new GeoPoint();                    //GeoPoint geopt = new GeoPoint(new Point2D(e.X, e.Y));                    geopt.X = pt2d.X;                    geopt.Y = pt2d.Y;                                        DatasetVector datasetqy = workspaceControl1.Workspace.Datasources[0].Datasets["China_ProCenCity_pt"] as DatasetVector;                    QueryParameter qp = new QueryParameter();                    qp.SpatialQueryObject = geopt ;                    qp.SpatialQueryMode = SpatialQueryMode.Cross;                    Layer layer = mapControl1.Map.Layers["China_ProCenCity_pt@ChinaClimate"];                   //设置查询条件                    Recordset rl = datasetqy.Query(geopt, 10000,CursorType.Static);                    if (rl.RecordCount>0)                    {                        int id = Convert.ToInt32(rl.GetFieldValue("SmID"));                        layer.Selection.Add(id);
                    }

6)根据ID返回对象的属性信息

    //访问数据集中属性表                        DataTable dt = new DataTable();                        SuperMap.Data.Datasets objDts = workspaceControl1.Workspace.Datasources["ChinaClimate"].Datasets;                        SuperMap.Data.Dataset objDt = objDts["China_ProCenCity_pt"];                        SuperMap.Data.DatasetVector objDtv = (SuperMap.Data.DatasetVector)objDt;                        SuperMap.Data.Recordset recordset = objDtv.GetRecordset(false, CursorType.Dynamic);                                               recordset.MoveFirst();                        dt.Columns.Add("字段名");                        dt.Columns.Add("字段值");
                        if (Convert.ToInt32(recordset.GetFieldValue("SmID")) == id)                        {                            for (int i=0;i< objDtv.FieldInfos.Count;i++)                            {                                dt.Rows.Add();                                dt.Rows[i][0] = objDtv.FieldInfos[i].Name;                                dt.Rows[i][1] = recordset.GetFieldValue(objDtv.FieldInfos[i].Name);
                            }                        }                      else                        {                         while (recordset.MoveNext() == true)                        {                                if (Convert.ToInt32(recordset.GetFieldValue("SmID")) == id)                                {                                    for (int i = 0; i < objDtv.FieldInfos.Count; i++)                                    {                                        dt.Rows.Add();                                        dt.Rows[i][0] = objDtv.FieldInfos[i].Name;                                        dt.Rows[i][1] = recordset.GetFieldValue(objDtv.FieldInfos[i].Name);
                                    }                                    break;                                }                        }                        }                        frmPtSelproperty myfrm = new frmPtSelproperty(dt);                        myfrm.Show();

7)显示属性列表

  uiDataGridView1.DataSource = _dt;

8)效果

图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值