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

📄 form07.frm

📁 给出了详细的vb环境下mo基本功能的代码 如图层的加载
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form07 
   Caption         =   "世界地图"
   ClientHeight    =   4530
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7215
   LinkTopic       =   "Form1"
   ScaleHeight     =   4530
   ScaleWidth      =   7215
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   495
      Left            =   5760
      TabIndex        =   3
      Top             =   3840
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   4080
      TabIndex        =   2
      Top             =   3840
      Width           =   1335
   End
   Begin MapObjects2.Map Map1 
      Height          =   3615
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6975
      _Version        =   131072
      _ExtentX        =   12303
      _ExtentY        =   6376
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form07.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   3960
      Width           =   3375
   End
End
Attribute VB_Name = "Form07"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xue Wei,2003/6/10
'ToMapDistance练习;
'在世界地图上查找中国,并计算面积;

Option Explicit
Dim Dx As Single
Dim sym As MapObjects2.Symbol
Dim sym1 As MapObjects2.Symbol
Dim Shp As MapObjects2.Polygon
Dim Shp1 As MapObjects2.Line

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

Private Sub Command1_Click()
  Dim strExpression As String
  Dim recSelection As MapObjects2.Recordset
  Dim Dy As Single
    
  '设置面积系数;
  Dy = Dx * Dx / 10000
  Set Shp1 = Nothing
  
  '查找特征;
  strExpression = "NAME = 'China'"
  Set recSelection = Map1.Layers("country").SearchExpression(strExpression)
  If Not recSelection.EOF Then
    Set Shp = recSelection.Fields("Shape").Value
    '设置显示模式;
    Set sym = New MapObjects2.Symbol
    sym.SymbolType = moFillSymbol
    sym.Color = moRed
    Label1.Caption = "面积为:" & Format(Shp.Area * Dy, "0.00") & "万平方公里。"
    Map1.Refresh
  End If
End Sub

Private Sub Command2_Click()
  Dim strExpression As String
  Dim recSelection As MapObjects2.Recordset
  'Dim Dy As Single
  
  '查找特征;
  strExpression = "NAME = 'Yangtze'"
  Set recSelection = Map1.Layers("rivers").SearchExpression(strExpression)
  If Not recSelection.EOF Then
    Set Shp1 = recSelection.Fields("Shape").Value
    '设置显示模式;
    Set sym1 = New MapObjects2.Symbol
    sym1.SymbolType = moLineSymbol
    sym1.Color = moYellow
    sym1.Size = 3
    Label1.Caption = "长度为:" & Format(Shp1.Length * Dx, "0.00") & "公里。"
    Map1.Refresh
  End If
End Sub

Private Sub Form_Load()
  Dx = 40075.7 / 360
  Label1.Caption = "点击按钮进行查找。"
  DrawLayer     '添加世界地图的Country和Rivers图层;
  Command1.Caption = "查找地区"
  Command2.Caption = "查找河流"
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim Str1 As String
  Dim P1 As MapObjects2.Point
      
  If Not Option1 Then
    Set P1 = Map1.ToMapPoint(X, Y)
    Str1 = "x=" & Format(P1.X * Dx, "0.000") & ",y=" & Format(P1.Y * Dx, "0.000")
  Else
    Str1 = "x=" & Format(Map1.ToMapDistance(X) * Dx, "0.000") & ",y=" & Format(Map1.ToMapDistance(Y) * Dx, "0.000")
  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
  
   Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("rivers")
  layer.Symbol.Color = moBlue
  Map1.Layers.Add layer
End Sub

⌨️ 快捷键说明

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