三、使用选择集
MapX的一个基本功能是在地图上选择图元,用户可以单击选择一个或多个图元(点、区域等)。MapX高亮显示所有选中的图元。
要检查所选图元列表,请使用Selection集合,它是Feature对象的集合。Selection集合提供了不同的方法(例如SelectByRadius)使用户得以完成不同类型的选择。例如,选择以某城市为圆心的一定半径范围内的所有图元,所选图元将在地图上高亮显示出来。利用Layer.Selection方法可以获取每个图层所选图元对象的集合。
Selection集合具有在集合中添加和删除图元的方法。同时,如果已经具有Selection集合
或Features集合,那么可以追加、删除、复制或查找两个集合的交集。
表6-16列出了一些Selection集合方法。
表6-16 Selection集合方法
1.搜索类型常数
使用选择集的搜索类型常数及其功能描述见表6-17。
表6-17 搜索类型常数
以下代码在指定点创建新的选择。
Private Sub Command1_Click()
Map1.Layers(5).Selection.SelectByPoint-98,31.56,miSelectionNew
End Sub
2.SelectionChanged事件
当地图中的图层选择集发生改变时,将触发SelectionChanged事件,该事件使建立在地图上的选择操作发生作用。使用选择工具或使用Layer对象的某一Selection方法可以将选择更改为用户结果。以下示例为用户当前选择的记录刷新列表内容。
Private Sub Map1_SelectionChanged()
'Any time the selection changes,update the listbox with the currently selected records
Dim ftr As Feature'Create a feature object
Dim lyr As Layer'Create a layer object
'Within the current layer the user is selecting from,print out a message
For Each lyr In Map1.Layers
For Each ftr in lyr.Selection
MsgBox("found:")ftr.name
Next
Next
End Sub
以下程序演示了怎样从Features集合中选取对象。
'how to select the objects from a features collection
Dim fs as Features
Dim pt as new Point
pt.SetXY-96.731,39.728
'assumes map unit is miles
Set fs=map1.Layers(1).SelectWithinDistance(pt,50,_miSearchTypePartiallyWithin)
map1.Layers(1).Selection.Replace(fs)
免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。