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

📄 form02.frm

📁 这是一个计算面积的程序
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form02 
   Caption         =   "墨西哥地图"
   ClientHeight    =   6360
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8400
   LinkTopic       =   "Form1"
   ScaleHeight     =   6360
   ScaleWidth      =   8400
   StartUpPosition =   3  '窗口缺省
   Begin MapObjects2.Map Map1 
      Height          =   5655
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   8415
      _Version        =   131072
      _ExtentX        =   14843
      _ExtentY        =   9975
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "form02.frx":0000
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   375
      Left            =   1200
      TabIndex        =   1
      Top             =   5880
      Width           =   5775
   End
End
Attribute VB_Name = "Form02"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Xuewei,2003/5/20
'计算矩形和州的交集;

Option Explicit
Dim resultShape As MapObjects2.Polygon
Dim recSelection As MapObjects2.Recordset
Dim intersectShape As MapObjects2.Polygon
Dim rect As MapObjects2.Rectangle

Private Sub Map1_AfterLayerDraw(ByVal index As Integer, ByVal canceled As Boolean, ByVal hDC As stdole.OLE_HANDLE)
  Dim sym1 As New MapObjects2.Symbol
  
  If Not rect Is Nothing Then
    sym1.Color = moYellow
    Map1.DrawShape rect, sym1
  End If
  
  If Not recSelection Is Nothing Then
    sym1.Color = moOrange
    Map1.DrawShape recSelection, sym1
  End If
  
  If Not resultShape Is Nothing Then
    sym1.Color = moRed
    Map1.DrawShape resultShape, sym1
  End If
End Sub

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 = moLimeGreen
  Map1.Layers.Add layer
  
  Set layer = New MapLayer
  Set layer.GeoDataset = dc.FindGeoDataset("Rivers")
  layer.Symbol.Color = moRed
  Map1.Layers.Add layer
End Sub

Private Sub Form_Load()
  DrawLayer
  Label1.Caption = "在地图上画矩形。"
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  Dim strExpression As String
  Dim Ai As Single
  Const Ak = 1000
  
  Set rect = Map1.TrackRectangle
  strExpression = "STATE_ID = 25"   '查找编码为25的州;
  Set recSelection = Map1.Layers("States").SearchExpression(strExpression)
  Set intersectShape = recSelection.Fields("Shape").Value
  Set resultShape = rect.Intersect(intersectShape)
  
  If resultShape Is Nothing Then
    Label1.Caption = "没有相交。"
  Else
    Ai = Format(resultShape.Area * Ak, "0.00")
    Label1.Caption = "相交面积=" & Ai & "平方公里。"
  End If
  Map1.Refresh
End Sub

⌨️ 快捷键说明

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