Sub chart_chartitemclicked(Message As String)
Dim sb As ABMSideBar = page.GetSideBar("SideBar")
Dim cn As ABMContainer = sb.Content.Component("cnt1")
Dim us As ABMCheckbox = cn.Component("btnshowus")
DateTime.TimeFormat = "HH:mm:ss"
ListFindOther.Initialize
Dim mark As List ' the list of points used to draw the GeoZone (polygon) - after determining extents...
mark.Initialize
Dim latlist As List ' the lists of points to process. These are used to extract the extents of the poly...
Dim lonlist As List
latlist.Initialize
lonlist.Initialize
Dim mes As String = Message
Log(" ECM File SIze: "&ListECM.Size)
Dim idx As Int = Message.IndexOf("row:")
mes = mes.Replace("row:","")
Dim idx As Int = mes.IndexOf(",")
Dim val As String =""
If idx > 0 Then
val = mes.SubString2(1, idx)
Log(" rec to get: "&val)
Else
Log(" no index > 0")
End If
If IsNumber(val) Then
Dim val0 As Int = val - 60 ' make sure we have at least 60 points both for and aft of selected point...
If val0 < 1 Then
val0 = 1
End If
Dim val1 As Int = val + 60
If val1 > ListECM.Size-1 Then
val1 = ListECM.Size
End If
gm1.RemoveMarkers
gm1.RemovePolygons
Log(" Number of select recs: "&(val1-val0) )
Log(" for vals - 0: "&val0&" 1: "&val1)
For i = val0 To val1 -1
Dim mpp As Map = ListECM.Get(i)
ListFindOther.Add(mpp) ' add all the details to a list
Dim lt As Double = mpp.Get("501")
Dim ln As Double = mpp.Get("502")
latlist.Add(lt) ' make 2 lists of lat / lon
lonlist.Add(ln)
Dim lat As String = mpp.Get("501") ' this is used to create an info box for the google map
Dim lon As String = mpp.Get("502")
Dim sp As String = mpp.GetDefault("2",0)
Dim tm As String = mpp.GetDefault("1",0)
Dim rp As String = mpp.GetDefault("4",0)
If us.State Then ' show US miles or Metric....
sp = NumberFormat2(sp * 0.62137 ,1,1,1,False)
End If
Dim dt As String = DateTime.Time(tm)
Dim legend As String = " {B} Time: "&" "&dt&" {BR}"
legend = legend&" Speed: "&" "&sp&" {BR}"
legend = legend&" RPM: "&" "&rp&" {/B} {BR}"
If i = val Then ' show the selected point in RED...
gm1.AddMarker( "mk"&i,lat,lon, ABM.COLOR_RED ,"Speed: "&sp&" Time: "&" "&dt&" ", legend)
Else
gm1.AddMarker( "mk"&i,lat,lon, ABM.COLOR_Blue ,"Speed: "&sp&" Time: "&" "&dt&" ",legend)
End If
Next
gm1.SetLocation( lat,lon) ' center the map on the selected point....
gm1.Refresh
End If
mark = GetCoords(latlist, lonlist) ' call the method to get the Geozone bounds!!!!
' show (and store later) the Geozone we need...
gm1.AddPolygon( "p1" , mark , ABM.COLOR_DEEPORANGE, ABM.INTENSITY_NORMAL, 1.0, 5, ABM.COLOR_CYAN, ABM.INTENSITY_NORMAL, 0.3)
End Sub
Sub GetCoords(Lat As List, Lon As List) As List
Dim MinLon As Double = Lon.Get(0)
Dim MaxLon As Double = Lon.Get(0)
Dim MinLat As Double = Lat.Get(0)
Dim MaxLat As Double = Lat.Get(0)
For I = 1 To Lat.Size - 1 'first point (array element 0) already done
If Lon.Get(I) < MinLon Then
MinLon = Lon.Get(I)
Else
If Lon.Get(I) > MaxLon Then MaxLon = Lon.Get(I)
End If
If Lat.Get(I) < MinLat Then
MinLat = Lat.Get(I)
Else
If Lat.Get(I) > MaxLat Then MaxLat = Lat.Get(I)
End If
Next
'allow a bit extra in each direction to handle GPS wander etc:
' Dim LatBuffer As Double = (50 / 40000000) * 360 '50 metres = 0.00045 degrees latitude (planet earth circumference is nominally 40,000 km = 40,000,000 m)
' Dim LonBuffer As Double = LatBuffer / Cos(68) '50 metres = 0.00120 degrees longitude (scale varies with latitude)
'probably better as: LonBuffer = LatBuffer / Cos((MinLat + MaxLat) / 2) for use at other latitudes
'bounding rectangle polygon is now the four points:
'(MinLon - LonBuffer, MinLat - LatBuffer) to
'(MinLon - LonBuffer, MaxLat + LatBuffer) to
'(MaxLon + LonBuffer, MaxLat + LatBuffer) to
'(MaxLon + LonBuffer, MinLat - LatBuffer) to
'(MinLon - LonBuffer, MinLat - LatBuffer) starting point again, if needed to close polygon
Log("MaxLat: "&MaxLat&" MaxLon: "&MaxLon&" MinLat: "&MaxLat&" MinLon: "&MinLon)
Dim coord As List
coord.Initialize
Dim buflat As Double = 0.0005 ' my buffers for simplicity....
Dim buflon As Double = 0.0009
coord.Addall(Array As Double(MinLat-buflat, MinLon-buflon, MaxLat+buflat, MinLon-buflon, MaxLat+buflat, MaxLon+buflon, MinLat-buflat, MaxLon+buflon ))
Return coord ' done here... simple eh?
End Sub