Tracking Vehicles


 

AspMap allows you to display locations of moving objects without reloading the page or the map image (AspMap uses AJAX to update the locations). The locations should be updated in a RefreshAnimationLayer event handler. After the RefreshAnimationLayer event handler is executed, further processing of the page will be stopped and the locations will be sent to the browser.

 

To track the location of a vehicle:

 

  1. Set the EnableAnimation property of a Map control to True. Use the AnimationInterval property to set an update interval.

  2. Add an event handler for the RefreshAnimationLayer event.

  3. Add the current location of a vehicle to the AnimationLayer object of the Map control.


Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Map1.EnableAnimation = True
        Map1.AnimationInterval = 2000 ' 2 seconds
End Sub

Private Sub Map1_RefreshAnimationLayer(ByVal sender As Object, ByVal e As RefreshAnimationLayerArgs) Handles Map1.RefreshAnimationLayer
        
        Dim vehicle As GeoEvent = New GeoEvent()

        ' set the current location of the vehicle
        vehicle.Location.X = -120.0 ' longitude
        vehicle.Location.Y = 45.0   ' latitude
        
        ' set the image of the vehicle
        vehicle.ImageUrl = "vehicle.gif"
        vehicle.ImageWidth = 20
        vehicle.ImageHeight = 20
        vehicle.Label = "Vehicle 1"
        vehicle.NavigateUrl = "javascript:alert('Vehicle 1')"

        ' add the location of the vehicle to the AnimationLayer
        Map1.AnimationLayer.Add(vehicle)

End Sub

4. You can display the previous movements of the vehicle as a line using the Path property of the GeoEvent class:


Private Sub Map1_RefreshAnimationLayer(ByVal sender As Object, ByVal e As RefreshAnimationLayerArgs) Handles Map1.RefreshAnimationLayer
        
        Dim vehicle As GeoEvent = New GeoEvent()

        ' set the current location of the vehicle
        vehicle.Location.X = -120.0 ' longitude
        vehicle.Location.Y = 45.0   ' latitude
        
        ' add previous and current locations of the vehicle
        vehicle.Path = new AspMap.Points()
        vehicle.Path.Add(-120.0, 45.0)
        vehicle.Path.Add(-119.0, 44.0)
        vehicle.Path.Add(-118.0, 43.0)  
        vehicle.Path.Add(-117.0, 42.0)  

        ' set the color of the path and the width of the path line in pixels
        vehicle.PathColor = Color.Green
        vehicle.PathWidth = 2
                
        ' set the image of the vehicle
        vehicle.ImageUrl = "vehicle.gif"
        vehicle.ImageWidth = 20
        vehicle.ImageHeight = 20
        vehicle.Label = "Vehicle 1"
        vehicle.NavigateUrl = "javascript:alert('Vehicle 1')"

        ' add the location of the vehicle to the AnimationLayer
        Map1.AnimationLayer.Add(vehicle)

End Sub


 

5. If the current location of the vehicle is outside the map, you can move the map to a new position using the CenterAt method. After that, set the NeedRefreshMap property of the RefreshAnimationLayerArgs class to True. This way, the map image will be refreshed without reloading the page.


Private Sub Map1_RefreshAnimationLayer(ByVal sender As Object, ByVal e As RefreshAnimationLayerArgs) Handles Map1.RefreshAnimationLayer
        
        Dim vehicle As GeoEvent = New GeoEvent()

        ' set the current location of the vehicle
        vehicle.Location.X = -120.0 ' longitude
        vehicle.Location.Y = 45.0   ' latitude
        
        ' add previous and current locations of the vehicle
        vehicle.Path = new AspMap.Points()
        vehicle.Path.Add(-120.0, 45.0)
        vehicle.Path.Add(-119.0, 44.0)
        vehicle.Path.Add(-118.0, 43.0)  
        vehicle.Path.Add(-117.0, 42.0)  

        ' set the color of the path and the width of the path line in pixels
        vehicle.PathColor = Color.Green
        vehicle.PathWidth = 2
                
        ' set the image of the vehicle
        vehicle.ImageUrl = "vehicle.gif"
        vehicle.ImageWidth = 20
        vehicle.ImageHeight = 20
        vehicle.Label = "Vehicle 1"
        vehicle.NavigateUrl = "javascript:alert('Vehicle 1')"

        ' add the location of the vehicle to the AnimationLayer
        Map1.AnimationLayer.Add(vehicle)
  ' move the map if the vehicle is outside the map
        If Not Map1.Extent.IsPointIn(geoEvent.Location) Then
                Map1.CenterAt(vehicle.Location)
                e.NeedRefreshMap = True
        End If
End Sub

 


© 2007 VDS Technologies. All rights reserved.

 

 

 

© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)