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

📄 form1.frm

📁 给出了详细的vb环境下mo基本功能的代码 如图层的加载
💻 FRM
字号:
VERSION 5.00
Object = "{9BD6A640-CE75-11D1-AF04-204C4F4F5020}#2.0#0"; "mo20.ocx"
Begin VB.Form Form1 
   Caption         =   "沿线状推进"
   ClientHeight    =   5310
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6060
   LinkTopic       =   "Form1"
   ScaleHeight     =   5310
   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        =   "Form1.frx":0000
   End
End
Attribute VB_Name = "Form1"
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

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
 
  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 As Double
  Dim line As MapObjects2.line
  
  If Button = 2 Then
    Timer1.Interval = 0
    Map1.TrackingLayer.ClearEvents
    Exit Sub
  End If
  
  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 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
    
    m_nNum = 0   '推进
    Timer1.Interval = 500
  End If
End Sub

Private Sub Timer1_Timer()
  Dim count As Integer
  Dim X, Y As Double
  
  Map1.TrackingLayer.ClearEvents
  If m_nNum >= m_ptsDemo.count Then
    m_nNum = 0
    If Map1.TrackingLayer.EventCount > 0 Then
        Map1.TrackingLayer.ClearEvents  '将已经有的event删除
    End If
    Timer1.Interval = 0
    Exit Sub
  End If
  If Map1.TrackingLayer.EventCount > 0 Then
      Map1.TrackingLayer.ClearEvents
  End If
  
  '新建一个line
  Dim line As New MapObjects2.line
  Dim pts As New MapObjects2.Points
  Dim h As Integer
  count = m_nNum
  For h = 0 To count
    pts.Add m_ptsDemo.Item(h)
  Next h
  line.Parts.Add pts
  Map1.TrackingLayer.AddEvent line, 1
  m_nNum = m_nNum + 1
End Sub

⌨️ 快捷键说明

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