ASPX Code:
Code Behind:
Private Shared result As String = String.Empty
Private vehicles As New Collection(Of JsonVehicle)()
Private Shared iRecordPos As Integer = 0
Private Shared iRecordCount As Integer = 0
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
'+--------------------------------------------------------------+
'| This sub contains call back code executed from the client |
'| side when the javascript timer fires. |
'+--------------------------------------------------------------+
'**
'** If we're executing a data archive report, don't execute code here.
'**
If Session("ReportType") = "DATA" Then
Exit Sub
End If
'**
'** The following construct allows for the display of different GPS positions
'** from the dataset stored in memory for the selected unit. This is accomplished
'** via a combination of client-side script, server-side data handling, and session
'** variables to store everything.
'**
Dim OriginalLon As Double = 0
Dim OriginalLat As Double = 0
Dim spd As Double = 0
Dim DT As DateTime
Dim Direction As Integer
Dim projectedLat As Double = 0
Dim projectedLon As Double = 0
Dim Address As String = ""
Dim Opr8r As String = ""
vehicles.Clear()
iRecordPos = Session("iRecordPos")
If Session("dv").Table.Rows.Count > 0 Then
lon = Session("dv").item(iRecordPos).item("Lon")
lat = Session("dv").item(iRecordPos).item("Lat")
OriginalLon = lon
OriginalLat = lat
If hidPlaybackMode.Value = "Stopped" Then
iRecordPos = 0
Session("iRecordPos") = 0
lon = Session("dv").item(iRecordPos).item("Lon")
lat = Session("dv").item(iRecordPos).item("Lat")
spd = Session("dv").item(iRecordPos).item("Knots") '* sngSpeedMultiplier
Direction = Session("dv").item(iRecordPos).item("Direction")
DT = Format(Session("dv").item(iRecordPos).item("Date_Time"), "dd-MM-yyyy hh:mm:ss")
Address = Session("dv").item(iRecordPos).item("Address")
Opr8r = Session("dv").item(iRecordPos).item("Unit_Operator")
ProjectVehicles2(lon, lat)
Dim vehicle As New JsonVehicle(cboUnitSelection.Text, "marker_blue.gif", spd, Direction, DT, Address, lon, lat, Opr8r)
vehicles.Add(vehicle)
End If
If hidPlaybackMode.Value = "Playing" Or hidPlaybackMode.Value = "Paused" Then
'** User is playing
If Not iRecordPos = Session("dv").count - 1 Then
iRecordPos = Session("iRecordPos")
lon = Session("dv").item(iRecordPos).item("Lon")
lat = Session("dv").item(iRecordPos).item("Lat")
spd = Session("dv").item(iRecordPos).item("Knots") '* sngSpeedMultiplier
Direction = Session("dv").item(iRecordPos).item("Direction")
DT = Format(Session("dv").item(iRecordPos).item("Date_Time"), "dd-MM-yyyy hh:mm:ss")
Address = Session("dv").item(iRecordPos).item("Address")
Opr8r = Session("dv").item(iRecordPos).item("Unit_Operator")
Select Case rbtnlstSpeedUnits.SelectedValue
Case "Slow"
Session("TimerInterval") = 2000
Case "Medium"
Session("TimerInterval") = 1000
Case "Fast"
Session("TimerInterval") = 500
End Select
ProjectVehicles2(lon, lat)
Dim vehicle As New JsonVehicle(cboUnitSelection.Text, "marker_blue.gif", spd, Direction, DT, Address, lon, lat, Opr8r)
vehicles.Add(vehicle)
If hidPlaybackMode.Value = "Playing" Then
iRecordPos += 1
Session("iRecordPos") += 1
End If
End If
Session("cb_RecordPos") = iRecordPos & " of " & Session("dv").Count - 1
If iRecordPos = Session("dv").Count - 1 Then
hidPlaybackMode.Value = "Stopped"
iRecordPos = 0
Session("iRecordPos") = 0
lon = Session("dv").item(iRecordPos).item("Lon")
lat = Session("dv").item(iRecordPos).item("Lat")
spd = Session("dv").item(iRecordPos).item("Knots") ' * sngSpeedMultiplier
Direction = Session("dv").item(iRecordPos).item("Direction")
DT = Format(Session("dv").item(iRecordPos).item("Date_Time"), "dd-MM-yyyy hh:mm:ss")
Address = Session("dv").item(iRecordPos).item("Address")
Opr8r = Session("dv").item(iRecordPos).item("Unit_Operator")
ProjectVehicles2(lon, lat)
Dim vehicle As New JsonVehicle(cboUnitSelection.Text, "marker_blue.gif", spd, Direction, DT, Address, lon, lat, Opr8r)
vehicles.Add(vehicle)
End If
End If
If hidPlaybackMode.Value = "Previous" Or hidPlaybackMode.Value = "Next" Then
'** User is playing
If Not iRecordPos = Session("dv").count - 1 Then
iRecordPos = Session("iRecordPos")
lon = Session("dv").item(iRecordPos).item("Lon")
lat = Session("dv").item(iRecordPos).item("Lat")
spd = Session("dv").item(iRecordPos).item("Knots") '* sngSpeedMultiplier
Direction = Session("dv").item(iRecordPos).item("Direction")
DT = Format(Session("dv").item(iRecordPos).item("Date_Time"), "dd-MM-yyyy hh:mm:ss")
Address = Session("dv").item(iRecordPos).item("Address")
Opr8r = Session("dv").item(iRecordPos).item("Unit_Operator")
ProjectVehicles2(lon, lat)
Dim vehicle As New JsonVehicle(cboUnitSelection.Text, "marker_blue.gif", spd, Direction, DT, Address, lon, lat, Opr8r)
vehicles.Add(vehicle)
If hidPlaybackMode.Value = "Next" Then
iRecordPos += 2
Session("iRecordPos") += 2
hidPlaybackMode.Value = "Paused"
End If
If hidPlaybackMode.Value = "Previous" Then
iRecordPos -= 2
Session("iRecordPos") -= 2
hidPlaybackMode.Value = "Paused"
End If
End If
End If
'For i As Integer = 0 To startPositions.GetLength(0) - 1
' Dim lon As Double = startPositions(i, 0) + New Random().[Next](-12, 20) / 5000.0R
' Dim lat As Double = startPositions(i, 1) + New Random().[Next](-11, 26) / 5000.0R
' If DirectCast(Session("MapTypeObj"), MapType).MapProvider <> MapProvider.WorldMapKit Then
' projectedLat = lat
' projectedLon = lon
' ProjectVehicles2(projectedLon, projectedLat)
' Else
' projectedLat = lat
' projectedLon = lon
' End If
' startPositions(i, 0) = lon
' startPositions(i, 1) = lat
' 'Dim vehicle As New JsonVehicle("vehicle" & (i + 1), "vehicle_van_" & (i + 1) & ".png", projectedLon, projectedLat)
' 'vehicles.Add(vehicle)
'Next
result = JsonSerializeHelper.Serialize(Of Collection(Of JsonVehicle))(vehicles)
End If
End Sub
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
'Return the vehicle data to client using callback
Return result
End Function
'''
''' This sub allows us to project vehicles using decimal degrees into other units such as meters
''' which is used by all of the online web mapping services.
'''
'''
'''
'''
Private Sub ProjectVehicles2(ByRef Lon As Double, ByRef Lat As Double)
If DirectCast(Session("MapTypeObj"), MapType).MapProvider <> MapProvider.WorldMapKit Then
'**
'** Keep remmed out code for when a switch for multiple vehicle display is implemented.
'**
Dim proj4 As New Proj4Projection(Proj4Projection.GetEpsgParametersString(4326), Proj4Projection.GetGoogleMapParametersString())
proj4.Open()
'For Each item As KeyValuePair(Of String, Vehicle) In vehicles
Dim vertex As Vertex = proj4.ConvertToExternalProjection(Lon, Lat)
'item.Value.X = vertex.X
'item.Value.Y = vertex.Y
'Next
Lon = vertex.X
Lat = vertex.Y
proj4.Close()
End If
End Sub