form03.frm
来自「给出了详细的vb环境下mo基本功能的代码 如图层的加载」· FRM 代码 · 共 115 行
FRM
115 行
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form03
Caption = "美国地图"
ClientHeight = 6270
ClientLeft = 60
ClientTop = 345
ClientWidth = 8730
LinkTopic = "Form1"
ScaleHeight = 6270
ScaleWidth = 8730
StartUpPosition = 3 '窗口缺省
Begin MapObjects2.Map Map1
Height = 5655
Left = 120
TabIndex = 0
Top = 120
Width = 8535
_Version = 131072
_ExtentX = 15055
_ExtentY = 9975
_StockProps = 225
BackColor = 16777215
BorderStyle = 1
Contents = "Form03.frx":0000
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Left = 2640
TabIndex = 1
Top = 5880
Width = 3495
End
End
Attribute VB_Name = "Form03"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xuewei,2003/6/11
'放大4倍显示较小地图;
Option Explicit
Private Sub Map1_BeforeLayerDraw(ByVal index As Integer, ByVal hDC As stdole.OLE_HANDLE)
Dim layer As MapObjects2.MapLayer
Set layer = Map1.Layers(index)
If index = 1 Then 'counties
If Map1.Extent.Width > (Map1.FullExtent.Width / 4) Then
Label1.Caption = "没有放大4倍以上,不显示县地图。"
layer.Visible = False
Else
Label1.Caption = "已经放大4倍以上,显示县地图!"
layer.Visible = True
End If
End If
End Sub
Private Sub Form_Load()
DrawLayer '加载美国地图;
Label1.Caption = "左键放大,右键移动,双击缩小。"
End Sub
Sub DrawLayer()
Dim dc As New DataConnection
Dim layer As MapLayer
dc.Database = App.Path + "\..\" + "USA"
If Not dc.Connect Then
MsgBox "在指定的文件夹下没找到图层数据文件!"
End
End If
Set layer = New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("Counties")
layer.Symbol.Color = moYellow
layer.Symbol.SymbolType = moFillSymbol
layer.Symbol.Size = 1
layer.Symbol.Style = 7
layer.Symbol.OutlineColor = moGreen
Map1.Layers.Add layer
Set layer = New MapLayer
Set layer.GeoDataset = dc.FindGeoDataset("states")
layer.Symbol.Color = moPaleYellow
layer.Symbol.SymbolType = moFillSymbol
layer.Symbol.Style = 1
layer.Symbol.Size = 2
layer.Symbol.OutlineColor = moBrown
'标注
Set layer.Renderer = New LabelRenderer
layer.Renderer.Field = "STATE_NAME" '指定要显示的字段
layer.Renderer.Symbol(0).Color = moBlack
layer.Renderer.Symbol(0).Height = 0.5
layer.Renderer.AllowDuplicates = True
Map1.Layers.Add layer
End Sub
Private Sub Map1_DblClick()
Dim r As MapObjects2.Rectangle
Set r = Map1.Extent
r.ScaleRectangle 2
Map1.Extent = r
End Sub
Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Rect As MapObjects2.Rectangle
If Button = 1 Then
Set Rect = Map1.TrackRectangle
Map1.Extent = Rect
Else
Map1.Pan
End If
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?