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

📄 form04b.frm

📁 一个关于基于MO编程的参考资料希望对大家的交流和学习有帮助
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form04b 
   Caption         =   "世界地图"
   ClientHeight    =   8280
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7095
   LinkTopic       =   "Form1"
   ScaleHeight     =   8280
   ScaleWidth      =   7095
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   495
      Left            =   3600
      TabIndex        =   3
      Top             =   7680
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   1560
      TabIndex        =   2
      Top             =   7680
      Width           =   1335
   End
   Begin MapObjects2.Map Map1 
      Height          =   6855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6735
      _Version        =   131072
      _ExtentX        =   11880
      _ExtentY        =   12091
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form04b.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   255
      Left            =   840
      TabIndex        =   1
      Top             =   7200
      Width           =   5055
   End
End
Attribute VB_Name = "Form04b"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xue Wei,2003/6/10
'ToMapDistance和ToMapPoint练习;
'在北京地图上显示点击处经纬度,并计算面积;

Option Explicit
Dim Dx0 As Single, Dxk As Single
Dim Dy0 As Single, Dy1 As Single, Dyk As Single
Dim Ax As Single

Private Sub Command1_Click()
  Dim recs As New MapObjects2.Recordset
  Dim layer As MapObjects2.MapLayer
  Dim Ay As Single
  Dim Area1 As Single
  Dim Shp As MapObjects2.Polygon
  
  Set layer = Map1.Layers(1)
  Set recs = layer.Records
  Ay = Ax * Ax / (Dxk * Dyk)
  
  Area1 = 0
  Do While Not recs.EOF
    Set Shp = recs.Fields("Shape").Value
    Area1 = Shp.Area * Ay + Area1
    recs.MoveNext
  Loop
  Label1.Caption = "面积为" & Format(Area1, "0.00") & "平方公里。"
End Sub

Private Sub Command2_Click()
  Dim recs As New MapObjects2.Recordset
  Dim layer As MapObjects2.MapLayer
  Dim Ay As Single
  Dim Area1 As Single
  Dim Shp As MapObjects2.Polygon
  
  Set layer = Map1.Layers(1)
  Set recs = layer.SearchExpression("NAME = '密云县'")
  'Set recs = layer.SearchExpression("NAME = '怀柔县'")
  Set recs = layer.SearchExpression("NAME = '房山区'")
  'Set recs = layer.SearchExpression("NAME = '朝阳区'")
  Ay = Ax * Ax / (Dxk * Dyk)
  
  If recs.EOF Then
    Label1.Caption = "地区没有找到。"
  Else
    Set Shp = recs.Fields("Shape").Value
    Area1 = Shp.Area * Ay
    Label1.Caption = "面积为" & Format(Area1, "0.00") & "平方公里。"
  End If
End Sub

Private Sub Form_Load()
  Label1.Caption = "点击地图显示经纬度。"
  DrawLayer   '加载北京地图;
  Command1.Caption = "北京市面积"
  Command2.Caption = "区县面积"
  
  Dx0 = 115.4167
  Dxk = 84761.91
  'Dy0 = 39.4333
  Dy1 = 41.0667
  Dyk = 109587.4
  'Ax = 40075.7 / 360   '世界地图
  Ax = 97.577      '北京市地图
  'Ax = 98.86
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Dim Str1 As String
    
  Str1 = "x=" & Format(Dx0 + Map1.ToMapDistance(X) / Dxk, "0.000") & _
  ",y=" & Format(Dy1 - Map1.ToMapDistance(Y) / Dyk, "0.000")
  
  Label1.Caption = Str1
End Sub

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

⌨️ 快捷键说明

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