⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form08.frm

📁 给出了详细的vb环境下mo基本功能的代码 如图层的加载
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form08 
   Caption         =   "世界地图"
   ClientHeight    =   5790
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7950
   LinkTopic       =   "Form1"
   ScaleHeight     =   5790
   ScaleWidth      =   7950
   StartUpPosition =   2  '屏幕中心
   Begin VB.OptionButton Option2 
      Caption         =   "Option2"
      Height          =   495
      Left            =   3000
      TabIndex        =   4
      Top             =   5160
      Width           =   1215
   End
   Begin VB.OptionButton Option1 
      Caption         =   "Option1"
      Height          =   495
      Left            =   1320
      TabIndex        =   3
      Top             =   5160
      Value           =   -1  'True
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   5400
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   5280
      Width           =   1335
   End
   Begin MapObjects2.Map Map1 
      Height          =   4575
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7695
      _Version        =   131072
      _ExtentX        =   13573
      _ExtentY        =   8070
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form08.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Left            =   1920
      TabIndex        =   1
      Top             =   4800
      Width           =   3855
   End
End
Attribute VB_Name = "Form08"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xue Wei,2003/6/13
'对于选择点和给定距离,转换单位。

Option Explicit
Dim Dx As Single
Dim sym1 As New MapObjects2.Symbol
Dim Sym2 As New MapObjects2.Symbol
Dim Eli As MapObjects2.Ellipse
Dim Pt1 As MapObjects2.Point

Private Sub Form_Load()
  Dx = 40075.7 / 360
  Label1.Caption = "点击地图显示经纬度和查找半径。"
  Option1.Caption = "度"
  Option2.Caption = "公里"
  Text1.Text = 10
  DrawLayer     '加载世界地图;
    
  With sym1
    .Color = moRed
    .Size = 3
  End With
  
  With Sym2
    .Color = moYellow
    .SymbolType = moFillSymbol
    .Style = 7
  End With
End Sub

Private Sub DrawEli(Dist As Double, Pt As MapObjects2.Point)
  Set Eli = New MapObjects2.Ellipse
  Eli.Right = Pt.X + Dist
  Eli.Left = Pt.X - Dist
  Eli.Top = Pt.Y + Dist
  Eli.Bottom = Pt.Y - Dist
  Map1.Refresh
End Sub

Private Sub Map1_AfterLayerDraw(ByVal index As Integer, ByVal canceled As Boolean, ByVal hDC As stdole.OLE_HANDLE)
  If Not Pt1 Is Nothing Then
    Map1.DrawShape Pt1, sym1
  End If
  
  If Not Eli Is Nothing Then
    Map1.DrawShape Eli, Sym2
  End If
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim Str1 As String
  Dim Dy As Single
    
  Set Pt1 = Map1.ToMapPoint(X, Y)
  If Option1 Then
    DrawEli Text1.Text, Pt1
    Str1 = "x=" & Format(Pt1.X, "0.000") & ",y=" & Format(Pt1.Y, "0.000") & _
    ",半径=" & Text1.Text & "度"
  Else
    DrawEli Text1.Text / Dx, Pt1
    Str1 = "x=" & Format(Pt1.X, "0.000") & ",y=" & Format(Pt1.Y, "0.000") & _
    ",半径=" & Text1.Text & "公里"
  End If
  
  Label1.Caption = Str1
End Sub

Sub DrawLayer()
  Dim dc As New DataConnection
  Dim layer As MapLayer
  
  dc.Database = App.Path + "\..\" + "world"
  If Not dc.Connect Then
    MsgBox "在指定的文件夹下没找到图层数据文件!"
    End
  End If
  
  Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("country")
  layer.Symbol.Color = moLimeGreen
  Map1.Layers.Add layer
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -