}
privatevoid toolStripZoomIn_Click(object sender, EventArgs e) { //地图放大
mapControl1.Action = SuperMap.UI.Action.ZoomIn;
}
privatevoid toolStripZoomOut_Click(object sender, EventArgs e) { //地图缩小
mapControl1.Action = SuperMap.UI.Action.ZoomOut; }
privatevoid toolStripFree_Click(object sender, EventArgs e) { //地图自由缩放
mapControl1.Action = SuperMap.UI.Action.ZoomFree; }
privatevoid toolStripEntire_Click(object sender, EventArgs e) { //地图全幅显示
mapControl1.Map.ViewEntire(); }
(6)地图属性浏览 {
//选择对象(此处支持选择多个对象)
mapControl1.Action = SuperMap.UI.Action.Select2; }
//*****图查属性*****
privatevoid toolStripQueryproperty_Click(object sender, EventArgs e) { //获取选择集
Selection[] selection = mapControl1.Map.FindSelection(true); //判断选择集
if (selection == null || selection.Length == 0) {
MessageBox.Show(\请选择要查询的空间对象\); return; } //将选择集转换为记录
Recordset recordest = selection[0].ToRecordset();
4
this.dataGridView1.Columns.Clear(); this.dataGridView1.Rows.Clear();
for (int i = 0; i < recordest.FieldCount; i++) { //定义并获得字段名称
string fieldName = recordest.GetFieldInfos()[i].Name; //将字段名称添加到datagridView列中
this.dataGridView1.Columns.Add(fieldName,fieldName); } //初始化row
DataGridViewRow row = null;
//根据选中记录的个数,将选中对象的信息添加到DataGirdView中显示 while (!recordest.IsEOF) {
row = newDataGridViewRow(); for(int i=0;i object fieldValue = recordest.GetFieldValue(i); //将字段值添加DataGirdView中指定的位置 DataGridViewTextBoxCell cell = newDataGridViewTextBoxCell(); if (fieldValue != null) { cell.ValueType = fieldValue.GetType(); cell.Value = fieldValue; } row.Cells.Add(cell); } this.dataGridView1.Rows.Add(row); recordest.MoveNext(); } this.dataGridView1.Update(); recordest.Dispose(); } privatevoid toolStripSQLquery_Click(object sender, EventArgs e) { //属性查图 //判断toolStripTextBox1的输入内容是否为空 if (toolStripTextBox1.Text.Length == 0) { MessageBox.Show(\查询信息不能为空\); return; } //定义图层个数 5 Int32 layerCount = mapControl1.Map.Layers.Count; //判断当前地图窗口中是否有打开的图层 if (layerCount == 0) { MessageBox.Show(\请先打开一个矢量数据集!\); return; } //定义查询条件信息; QueryParameter queryParameter = newQueryParameter(); queryParameter.AttributeFilter = toolStripTextBox1.Text; queryParameter.CursorType = CursorType.Static; Boolean hasGeometry = false; //遍历每一个图层,实现多图层查询 foreach (Layer layer in mapControl1.Map.Layers) { //得到矢量数据集并强制转换为矢量数据集类型 DatasetVector dataset = layer.Dataset asDatasetVector; if (dataset == null) { continue; } //通过查询条件对矢量数据集进行查询,从数据集中查询出属性数据, Recordset recordset = dataset.Query(queryParameter); //判断是否有查询结果 if (recordset.RecordCount > 0) { hasGeometry = true; } //把查询得到的数据加入到选择集中(使其高亮显示) Selection selection = layer.Selection; selection.FromRecordset(recordset); recordset.Dispose(); } //没有查询结果,弹出提示 if (!hasGeometry) { MessageBox.Show(\没有符合查询条件的结果或查询条件有误,请重新确认后查询!\); } //当可创建对象使用完毕后,使用Dispose方法来释放所占用的内部资源。 queryParameter.Dispose(); //刷新地图窗口显示 mapControl1.Refresh(); hasGeometry = false; 6 } } } 全幅显示 放大缩小 选中查询和属性查询 7 五、总结 这次试验正如题目一样是入门的,所以是相对简单的,话虽如此,自己在做的过程中还是遇到了一些问题的,因为上机课被假期冲掉,自己在宿舍做的时候也没能及时问老师请教,这些实验代码有些地方自己并不理解,实现的途径和方式不太清楚。在地图浏览等一些操作比较简单,直接调用接口就可以实现。但是属性查询这些小块方面一旦有点难度我就解决不掉了,还有数据转换和多图层操作不好理解,对接不上,但最后还是把代码给粘上去了,先把要完成的作业完成了,之后再学习中在慢慢的深入去学习和探讨。希望自己在接下来的试验中能收获的更多,最后谢谢老师的辛苦指导和批改。 8

