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

📄 form07a.frm

📁 给出了详细的vb环境下mo基本功能的代码 如图层的加载
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form07a 
   Caption         =   "墨西哥地图"
   ClientHeight    =   7020
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9315
   LinkTopic       =   "Form1"
   ScaleHeight     =   7020
   ScaleWidth      =   9315
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "显示"
      Height          =   495
      Left            =   7200
      TabIndex        =   6
      Top             =   6120
      Width           =   1215
   End
   Begin VB.PictureBox Picture1 
      Height          =   375
      Index           =   0
      Left            =   1320
      ScaleHeight     =   315
      ScaleWidth      =   555
      TabIndex        =   4
      Top             =   240
      Width           =   615
   End
   Begin VB.ListBox List1 
      Height          =   960
      Left            =   2760
      MultiSelect     =   2  'Extended
      Sorted          =   -1  'True
      TabIndex        =   3
      Top             =   5880
      Width           =   1695
   End
   Begin VB.OptionButton Option2 
      Caption         =   "Option2"
      Height          =   495
      Left            =   5160
      TabIndex        =   2
      Top             =   6360
      Width           =   1215
   End
   Begin VB.OptionButton Option1 
      Caption         =   "Option1"
      Height          =   495
      Left            =   5160
      TabIndex        =   1
      Top             =   5880
      Width           =   1215
   End
   Begin MapObjects2.Map Map1 
      Height          =   5535
      Left            =   2040
      TabIndex        =   0
      Top             =   120
      Width           =   7215
      _Version        =   131072
      _ExtentX        =   12726
      _ExtentY        =   9763
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form07a.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   5
      Top             =   360
      Width           =   1095
   End
End
Attribute VB_Name = "Form07a"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xuewei,2003/6/8
'ChartRenderer复杂示例;
'

Option Explicit
Dim Cr As New MapObjects2.ChartRenderer
Const Lh = 400

Private Sub Command1_Click()
  Map1.Refresh
End Sub

Private Sub Form_Load()
  Dim recset As New MapObjects2.Recordset
  Dim fld As MapObjects2.Field
  
  DrawLayer   '添加一个States图层
  Option1.Caption = "Pie Chart"
  Option2.Caption = "Bar Chart"
  
  Set Map1.Layers.Item("states").Renderer = Cr
  Set recset = Map1.Layers.Item("states").Records
  For Each fld In recset.Fields
    If fld.Type > 0 And fld.Type < 8 Then
      List1.AddItem fld.Name
    End If
  Next fld
End Sub

Private Sub ShowLegend(mi As Integer, Li As String, ci As Integer)
  If mi = 0 Then
    Label1(0).Caption = Li
    Picture1(0).BackColor = QBColor(ci)
  Else
    If Label1.Count < mi + 1 Then Load Label1(mi)
    With Label1(mi)
      .Top = Label1(mi - 1).Top + Lh
      .Caption = Li
      .Visible = True
    End With
    
    If Picture1.Count < mi + 1 Then Load Picture1(mi)
    With Picture1(mi)
      .Top = Picture1(mi - 1).Top + Lh
      .Visible = True
      .BackColor = QBColor(mi + ci)
    End With
  End If
End Sub

Private Sub Map1_BeforeLayerDraw(ByVal index As Integer, ByVal hDC As Stdole.OLE_HANDLE)
  Dim i As Integer, ctr As Integer
  If Option1.Value = True Or Option2.Value = True Then
    Select Case Cr.ChartType 'heights, widths, and sizes are somewhat arbitrary
      Case moBar
        Cr.BarHeight = Map1.Height * 0.005
        Cr.BarWidth = Map1.Width * 0.003
      Case moPie
        Cr.MinPieSize = Map1.Height * 0.001
        Cr.MaxPieSize = Map1.Height * 0.004
    End Select
    If List1.ListIndex > 0 Then
      For i = 0 To List1.ListCount - 1
        If List1.Selected(i) = True Then
          ctr = ctr + 1
          Call ShowLegend(ctr - 1, List1.List(i), 8)
          With Cr
            .FieldCount = ctr
            .Field(ctr - 1) = List1.List(i)
            .Color(ctr - 1) = QBColor(ctr + 7)
          End With
        End If
      Next i
    End If
  End If
End Sub

Private Sub Option1_Click()
  If Option1.Value = True Then
    Cr.ChartType = moPie
  End If
End Sub

Private Sub Option2_Click()
  If Option2.Value = True Then
    Cr.ChartType = moBar
  End If
End Sub

Private 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 = moPaleYellow
  layer.Symbol.Size = 1
  layer.Symbol.OutlineColor = moBrown
  Map1.Layers.Add layer
  
  Map1.Refresh
End Sub




⌨️ 快捷键说明

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