📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3120
ClientLeft = 165
ClientTop = 825
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3120
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin RichTextLib.RichTextBox RichTextBox1
Height = 975
Left = 360
TabIndex = 13
Top = 6480
Width = 1575
_ExtentX = 2778
_ExtentY = 1720
_Version = 393217
Enabled = -1 'True
TextRTF = $"Form1.frx":0000
End
Begin VB.CommandButton Command8
Caption = "图层不可见"
Height = 495
Left = 6960
TabIndex = 12
Top = 5760
Width = 1215
End
Begin VB.CommandButton Command7
Caption = "图层可见"
Height = 495
Left = 5760
TabIndex = 11
Top = 5760
Width = 1095
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 1215
Left = 0
TabIndex = 10
Top = 1905
Width = 4680
_ExtentX = 8255
_ExtentY = 2143
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 3
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
EndProperty
End
Begin MapObjects2.Map Map1
Height = 5055
Left = 120
TabIndex = 9
Top = 600
Width = 4935
_Version = 131072
_ExtentX = 8705
_ExtentY = 8916
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Form1.frx":008F
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 2400
Top = 1920
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command5
Caption = "删除"
Height = 495
Left = 4560
TabIndex = 8
Top = 5760
Width = 975
End
Begin VB.CommandButton Command4
Caption = "置底"
Height = 495
Left = 3360
TabIndex = 7
Top = 5760
Width = 975
End
Begin VB.CommandButton Command3
Caption = "置顶"
Height = 495
Left = 2280
TabIndex = 6
Top = 5760
Width = 855
End
Begin VB.CommandButton Command2
Caption = "下"
Height = 495
Left = 1200
TabIndex = 5
Top = 5760
Width = 735
End
Begin VB.CommandButton Command1
Caption = "上"
Height = 375
Left = 240
TabIndex = 4
Top = 5880
Width = 735
End
Begin MSComctlLib.ListView ListView1
Height = 4935
Left = 8160
TabIndex = 3
Top = 720
Width = 2655
_ExtentX = 4683
_ExtentY = 8705
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 2
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "field"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Text = "value"
Object.Width = 2540
EndProperty
End
Begin VB.ListBox List1
Height = 2400
Left = 5400
TabIndex = 2
Top = 720
Width = 2415
End
Begin MapObjects2.Map Map2
Height = 2175
Left = 5400
TabIndex = 1
Top = 3480
Width = 2415
_Version = 131072
_ExtentX = 4260
_ExtentY = 3836
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Form1.frx":00A9
End
Begin MSComctlLib.ImageList ImageList1
Left = 960
Top = 1920
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 16
ImageHeight = 16
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 5
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":00C3
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":01D5
Key = ""
EndProperty
BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":02E7
Key = ""
EndProperty
BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":03F9
Key = ""
EndProperty
BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Form1.frx":050B
Key = ""
EndProperty
EndProperty
End
Begin MSComctlLib.Toolbar Toolbar1
Align = 1 'Align Top
Height = 420
Left = 0
TabIndex = 0
Top = 0
Width = 4680
_ExtentX = 8255
_ExtentY = 741
ButtonWidth = 609
ButtonHeight = 582
Appearance = 1
ImageList = "ImageList1"
_Version = 393216
BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
NumButtons = 5
BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
ImageIndex = 1
EndProperty
BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
ImageIndex = 2
EndProperty
BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
ImageIndex = 3
EndProperty
BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
ImageIndex = 4
EndProperty
BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628}
ImageIndex = 5
EndProperty
EndProperty
End
Begin VB.Menu file
Caption = "文件"
Begin VB.Menu open
Caption = "打开"
End
Begin VB.Menu save
Caption = "保存"
End
Begin VB.Menu exit
Caption = "退出"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim c As Integer
Sub addlyrname()
Dim i As Integer
Dim lyr As MapLayer
List1.Clear
For i = 0 To Map1.Layers.Count - 1
Set lyr = Map1.Layers(i)
List1.AddItem lyr.name
Next i
End Sub
Private Sub Command1_Click()
If List1.ListIndex > 0 Then
Map1.Layers.MoveTo List1.ListIndex, List1.ListIndex - 1
Map1.Refresh
Call addlyrname
End If
End Sub
Private Sub Command2_Click()
If List1.ListIndex >= 0 And List1.ListIndex < Map1.Layers.Count - 1 Then
Map1.Layers.MoveTo List1.ListIndex, List1.ListIndex + 1
Map1.Refresh
Call addlyrname
End If
End Sub
Private Sub Command3_Click()
If List1.ListIndex > 0 Then
Map1.Layers.MoveToTop List1.ListIndex
Map1.Refresh
Call addlyrname
End If
End Sub
Private Sub Command4_Click()
If List1.ListIndex >= 0 And List1.ListIndex < Map1.Layers.Count - 1 Then
Map1.Layers.MoveToBottom List1.ListIndex
Map1.Refresh
Call addlyrname
End If
End Sub
Private Sub Command5_Click()
If List1.ListIndex > 0 Then
Map1.Layers.Remove List1.ListIndex
Map1.Refresh
Call addlyrname
End If
End Sub
Private Sub Form_Load()
Map1.Refresh
Call addlyrname
End Sub
Private Sub Command6_Click()
CommonDialog1.Filter = "shapfile.|*.shp"
CommonDialog1.ShowOpen
Dim dc As New DataConnection
Dim name As String
name = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)
dc.Database = CurDir
Dim layer As New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset(name)
Map2.Layers.Add layer
Map1.Layers.Add layer
Map1.Refresh
Map2.Refresh
End Sub
Private Sub Command7_Click()
Map1.Visible = True
Map2.Visible = True
End Sub
Private Sub Command8_Click()
Map1.Visible = False
Map2.Visible = False
End Sub
Private Sub Map2_AfterTrackingLayerDraw(ByVal hDC As stdole.OLE_HANDLE)
Dim object As MapObjects2.Rectangle
Dim objsym As New MapObjects2.Symbol
Set object = Map1.Extent
With objsym
.Outline = True
.OutlineColor = vbBlue
.Style = moTransparentFill
.Style = moTransparentFill
End With
Map2.DrawShape object, objsym
Set object = Nothing
Set objsym = Nothing
End Sub
Private Sub Map2_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim object As MapObjects2.Rectangle
Set object = Map2.TrackRectangle
If object.Width > 1 And object.Height > 1 Then
Set Map1.Extent = object
Map1.Refresh
Else: Map1.CenterAt object.Center.x, object.Center.y
End If
Set object = Nothing
End Sub
Private Sub Map1_AfterTrackingLayerDraw(ByVal hDC As stdole.OLE_HANDLE)
Map2.Refresh
End Sub
Private Sub open_Click()
Dim dc As New DataConnection
Dim strp As Integer
Dim p As Integer
Dim j As Integer, i As Integer
Dim FileName As String
Dim FileNames() As String
CommonDialog1.Filter = "shapfile1.|*.shp"
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) > 0 Then
dc.Database = CurDir
strp = 1
p = InStr(strp, CommonDialog1.FileName, Chr(0))
If p = 0 Then '导入一个文件
Set layer = New MapLayer
Dim name As String
name = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)
Set layer.GeoDataset = dc.FindGeoDataset(name)
Map1.Layers.Add layer
Map2.Layers.Add layer
Else '导入多个文件
CommonDialog1.FileName = CommonDialog1.FileName & Chr(0)
strp = 1
j = 0
For i = 1 To Len(CommonDialog1.FileName)
i = InStr(strp, CommonDialog1.FileName, Chr(0))
If i = 0 Then Exit For
ReDim Preserve FileNames(i)
FileNames(j) = Mid(CommonDialog1.FileName, strp, i - strp)
strp = i + 1
j = j + 1
Next
For i = 1 To j - 1
FileName = FileNames(i)
Set layer = New MapLayer
name = Left(FileName, Len(FileName) - 4)
Set layer.GeoDataset = dc.FindGeoDataset(name)
Map1.Layers.Add layer
Map2.Layers.Add layer
Next i
End If
End If
Call addlyrname
End Sub
Private Sub save_Click()
CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.FileName
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub Map1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pt As New MapObjects2.Point
Set pt = Map1.ToMapPoint(x, y)
StatusBar1.Panels(2).Text = "x=" & pt.x
StatusBar1.Panels(3).Text = "y=" & pt.y
End Sub
Private Sub Map2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim pt As New MapObjects2.Point
Set pt = Map1.ToMapPoint(x, y)
StatusBar1.Panels(2).Text = "x=" & pt.x
StatusBar1.Panels(3).Text = "y=" & pt.y
End Sub
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim r As MapObjects2.Rectangle
If c = 5 Then
Set r = Map1.TrackRectangle
If r.Width > 1 And r.Top > 1 Then
Map1.Extent = r
Else
Set r = Map1.Extent
r.ScaleRectangle 0.5
Map1.Extent = r
End If
ElseIf c = 1 Then
Set r = Map1.Extent
r.ScaleRectangle 1.5
Map1.Extent = r
ElseIf c = 3 Then
Map1.Pan
ElseIf c = 2 Then
Call showarr(x, y)
ElseIf c = 4 Then
Map1.Extent = Map1.FullExtent
Map2.Extent = Map1.FullExtent
End If
End Sub
Private Sub showarr(x As Single, y As Single)
Dim objpnt As MapObjects2.Point
Dim i As Integer
Dim objmors As MapObjects2.Recordset
Dim objlyr As MapObjects2.MapLayer
Dim obj As Object
Dim objtds As MapObjects2.TableDesc
Dim objitem As ListItem
Dim strkey As String
Set objpnt = Map1.ToMapPoint(x, y)
Set objlyr = Map1.Layers(0)
Set objmors = objlyr.SearchShape(objpnt, moAreaIntersect, "")
Set obj = objmors.Fields("shape").Value
Map1.FlashShape obj, 2
ListView1.ListItems.Clear
Set objtds = objmors.TableDesc
For i = 0 To objtds.FieldCount - 1
strkey = objtds.FieldName(i)
Set objitem = ListView1.ListItems.Add(, strkey, strkey)
objitem.SubItems(1) = objmors.Fields(strkey).ValueAsString
Next i
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = 1 Then
Map1.MousePointer = moZoomOut
c = 1
ElseIf Button.Index = 5 Then
Map1.MousePointer = moZoomIn
c = 5
ElseIf Button.Index = 3 Then
Map1.MousePointer = moPan
c = 3
ElseIf Button.Index = 2 Then
Map1.MousePointer = moCross
c = 2
ElseIf Button.Index = 4 Then
c = 4
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -