mapx+vb 实时读取数据库

1,实现图元根据数据库中X,Y字段的数据变化而改变位置

2,自己要另起一个线程,更改数据库的x,y的值

 

Private Sub Form_Load()

'1创建图层
Dim lyr As Layer
Set lyr = Map1.Layers.CreateLayer("Car")
Set Map1.Layers.AnimationLayer = lyr                '定义为动态图层

'2新建图元
Dim newobj As New MapXLib.Feature 'stand-alone object
Dim obj As MapXLib.Feature  'to hold feature added to layer
Dim NewStyle     As New MapXLib.Style
Dim str As String


newobj.Attach Map1

With NewStyle
        .SymbolType = miSymbolTypeBitmap
        .SymbolBitmapSize = 24
        .SymbolBitmapTransparent = True
        .SymbolBitmapName = "CAR1-32.BMP"
End With
newobj.Style = NewStyle                           '设置图元样式

newobj.Type = miFeatureTypeSymbol                 '设置图元类型

 

Set obj = Map1.Layers(1).AddFeature(newobj)

obj.Update

End Sub

 

 

 

Private Sub Timer1_Timer()

       timer1.Interval = 1000

       Dim lyr As MapXLib.Layer
       Set lyr = Map1.Layers("Car")
   
       Dim ftr As New MapXLib.Feature
       Dim ftrs As New MapXLib.Features
   
       Set ftr = lyr.AllFeatures.Item(1)
        ' **********************连接数据库        

        Set conn = New ADODB.Connection          
        Set rs = New ADODB.Recordset
      
        conn.ConnectionString = "Driver={sql server};server=127.0.0.1;uid=sa;pwd=password;database=databaseName"
        conn.ConnectionTimeout = 10
        conn.Open
        rs.Open "select x,y from X_Y", conn, adOpenStatic, adLockReadOnly, adCmdText  
          ' **********************连接数据库       
         ftr.Point.Set rs.Fields("x").Value, rs.Fields("y").Value         '设置图元位置
         ftr.Update

 

End Sub

你可能感兴趣的:(mapx+vb 实时读取数据库)