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

📄 form2.frm

📁 给出了详细的vb环境下mo基本功能的代码 如图层的加载
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form2 
   Caption         =   "沿线状移动"
   ClientHeight    =   5595
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6060
   LinkTopic       =   "Form1"
   ScaleHeight     =   5595
   ScaleWidth      =   6060
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Left            =   5520
      Top             =   5040
   End
   Begin MapObjects2.Map Map1 
      Height          =   4935
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5775
      _Version        =   131072
      _ExtentX        =   10186
      _ExtentY        =   8705
      _StockProps     =   225
      BackColor       =   16777215
      BorderStyle     =   1
      Contents        =   "Form2.frx":0000
   End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim m_ptsDemo As MapObjects2.Points
Dim m_nNum As Integer
Dim m_Evt As GeoEvent
Dim m_bIsMove As Boolean

Private Sub Form_Load()
  Dim Layer As MapLayer
  Dim dc As New DataConnection
  dc.Database = App.Path
  If Not dc.Connect Then
    MsgBox "在指定的文件夹下没找到图层数据文件,退出GIS!"
    Unload Me
    Exit Sub
  End If
  Set Layer = New MapLayer
  Set Layer.GeoDataset = dc.FindGeoDataset("图层 1_l")
  Layer.Name = "图层 1"
  Layer.Symbol.Color = moRed
  Layer.Symbol.Size = 2
  Map1.Layers.Add Layer
  
  Map1.Refresh
  
  Map1.TrackingLayer.SymbolCount = 2
  With Map1.TrackingLayer.Symbol(0)
    .SymbolType = moPointSymbol
    .Color = moBlue
    .Style = 0
    .Size = 8
  End With
  
  With Map1.TrackingLayer.Symbol(1)
    .SymbolType = moLineSymbol
    .Color = moBlue
    .Style = 0
    .Size = 5
  End With
  
  m_bIsMove = True
  Num = 0
End Sub

Private Sub Map1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  Dim p1 As MapObjects2.Point
  Dim theTol
  Dim line
  
  theTol = Map1.ToMapDistance(300)
  Set Layer1 = Map1.Layers(0)
  Set p1 = Map1.ToMapPoint(x, y)
  Set recs1 = Layer1.SearchByDistance(p1, theTol, "")
  Timer1.Interval = 0
      
  If Button = 2 Then
    Timer1.Interval = 0
    Map1.TrackingLayer.ClearEvents
    Exit Sub
  Else
    Map1.TrackingLayer.ClearEvents
    m_nNum = 0
  End If
  
  If Not recs1.EOF And Map1.Layers(0).Visible = True Then
    Set line = recs1("Shape").Value
    Set m_ptsDemo = New MapObjects2.Points
    
    For Each pt In line.Parts(0)
        m_ptsDemo.Add pt
    Next pt
    
    p1.x = m_ptsDemo.Item(0).x
    p1.y = m_ptsDemo.Item(0).y
    Set m_Evnt = Map1.TrackingLayer.AddEvent(p1, 0)
    m_bIsMove = True
    Timer1.Interval = 500
  End If
End Sub

Private Sub Timer1_Timer()
  Dim count As Integer
  Dim x, y
  
  If m_bIsMove And Map1.TrackingLayer.EventCount > 0 Then
    count = m_nNum
    If count > m_ptsDemo.count Then
        Timer1.Interval = 0
    End If
    
    Set m_Evnt = Map1.TrackingLayer.Event(0)
    m_nNum = m_nNum + 1
    x = m_ptsDemo.Item(count).x
    y = m_ptsDemo.Item(count).y
    m_Evnt.MoveTo x, y
  End If
End Sub

⌨️ 快捷键说明

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