📄 form06.frm
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "Mo20.ocx"
Begin VB.Form Form06
Caption = "通过选择图形对象查找相邻图形对象"
ClientHeight = 6480
ClientLeft = 60
ClientTop = 345
ClientWidth = 7710
LinkTopic = "Form1"
ScaleHeight = 6480
ScaleWidth = 7710
StartUpPosition = 2 'CenterScreen
Begin MapObjects2.Map Map1
Height = 5415
Left = 120
TabIndex = 0
Top = 120
Width = 7455
_Version = 131072
_ExtentX = 13150
_ExtentY = 9551
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Form06.frx":0000
End
Begin VB.Label Label1
Caption = "Label1"
Height = 375
Left = 2280
TabIndex = 1
Top = 5880
Width = 2775
End
End
Attribute VB_Name = "Form06"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xue Wei,2003/5/17
'SearchShape练习;
'从MO的帮助中修改而来。
Option Explicit
Dim recset1 As MapObjects2.Recordset '点击的多边形;
Dim recset2 As MapObjects2.Recordset '邻近的多边形;
Private Sub Form_Load()
DrawLayer
Label1.Caption = "请点击地图"
End Sub
Private Sub Map1_AfterLayerDraw(ByVal index As Integer, ByVal canceled As Boolean, ByVal hDC As stdole.OLE_HANDLE)
Call DrawSelection(recset2, moDarkGreen)
Call DrawSelection(recset1, moMagenta)
Set recset1 = Nothing
Set recset2 = Nothing
End Sub
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pt As MapObjects2.Point
Set pt = Map1.ToMapPoint(X, Y)
Set recset1 = Map1.Layers(0).SearchShape(pt, moPointInPolygon, "")
Set recset2 = Map1.Layers(0).SearchShape(recset1, moCommonPoint, "")
If Not recset2 Is Nothing Then
Label1.Caption = "一共找到" & recset2.Count - 1 & "个对象。"
Else
Label1.Caption = "没有找到对象。"
End If
Map1.Refresh
End Sub
Sub DrawSelection(recs As MapObjects2.Recordset, color)
' draw the features of a RecordSet
Dim sym As New MapObjects2.Symbol
sym.SymbolType = moFillSymbol
sym.Style = moSolidFill
sym.color = color
If Not recs Is Nothing Then
Map1.DrawShape recs, sym
End If
End Sub
Sub DrawLayer()
Dim dc As New DataConnection
Dim layer As MapLayer
dc.Database = App.Path + "\..\" + "Mexico"
If Not dc.Connect Then
MsgBox "在指定的文件夹下没找到图层数据文件!"
End
End If
Set layer = New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("States")
layer.Symbol.color = moYellow
Map1.Layers.Add layer
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -