点选查询,根据鼠标所点击的位置得到查询对象,然后把查询对象的属性信息返回给用户
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)效果