📄 监听.txt
字号:
Dim WithEvents g_Map As map
Private Sub UIButtonControl1_Click()
Dim mxDoc As IMxDocument '地图文档
Dim lyr As IFeatureLayer '要素层
Dim sel As IFeatureSelection '选择集
Dim filter As IQueryFilter '查询过滤器
Dim selEvents As ISelectionEvents '???
Set g_Map = mxDoc.FocusMap '获取当前地图
Set mxDoc = Application.Document '获取当前地图文档
Set lyr = FindLayer(mxDoc.FocusMap, "BUILDING") '调用FindLayer函数查找图层
Set sel = lyr '将找到的图层设为选择集
Set filter = New QueryFilter '创建查询过滤器
filter.WhereClause = "BDNAME ='实验楼A'" '设置where子句
sel.SelectFeatures filter, esriSelectionResultNew, False '选中满足条件的要素
mxDoc.activeView.PartialRefresh esriViewGeoSelection, Nothing, Nothing '绘出选中的要素
Set selEvents = mxDoc.FocusMap '???
selEvents.SelectionChanged '通知系统选择已经改变了
End Sub
'查找图层
Function FindLayer(map As IMap, name As String) As ILayer
Dim i As Integer
For i = 0 To map.LayerCount - 1 '第一层的索引为1
If map.Layer(i).name = name Then '如果第i层的名称为name
Set FindLayer = map.Layer(i) '获取并返回该层
Exit Function
End If
Next
End Function
Private Sub g_Map_SelectionChanged()
Dim activeView As IActiveView '活动地图
Dim featureEnum As IEnumFeature '列举的要素?
Dim feat As IFeature '要素
Dim index As Long
Dim Msg As String
Set activeView = g_Map '获取当前地图
Set featureEnum = activeView.Selection '列举所选的要素
featureEnum.Reset '还原至初始顺序
Set feat = featureEnum.Next '获取选择集中第一个要素
Do While Not feat Is Nothing '如果要素存在
index = feat.Fields.FindField(“Name”) '获取Name字段的索引值
If index <> -1 Then MsgBox Msg & chr(13) & chr(10) & feat.Value(index) '显示该要素的Name
Set feat = featureEnum.Next '移至选择集中的下一个要素
Loop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -