It seems being the first owes more to the diff. time zones, so I take advantage while you guys sleep!
Here goes the first one.
Since we need to paint vehicles over the map and move them as data is received, there's a Public vehicle array to hold vehicle's data -besides being saved to a database.
Since speed of redraw is paramount I did not use de loadbitmap, letting inovagis do it's map thing and take care of bitmaps an other way.
1) First, have an picture control OVER the picture that'll show the maps, create copies of it like veh(1), veh(2) and so. Upper limit of vehicles is limited by this, but we'll change it in due time. This is a lot easier and faster to implement.
2) Then on another VB form with an image control holding a lot of 32x32 bitmaps (made with IconArt*, excellent freeware), like iclib(0), iclib(1), and so. Thus, at runtime you can do something like:
veh(i).picture = frmImages.iclib(1).picture
...or change it whenever is desirable to do so, like showing different vehicle states.
What is important is to make sure that the vehicles are shown on the correct geo. location, so we have that info on the vehicles array (pseudo-VB code):
lat=mts(numero).vLat ' updated when new data for vehicle number numero arrives lon=mts(numero).vLon ' same as above veh(numero).visible=false ' turn it off for a moment locate_mt(numero) ' this sub converts from lat&lon to y&x into screen coord. veh(numero).picture=frmImages.iclib(18).picture ' i.e. a "normal" state icon If (veh(numero).left>PosX1 and veh(numero).left<PosX2 and veh(numero).top>PosY1 and veh(numero).top<PosY2) then veh(numero).visible=true ' turn it on again Else ' do not turn it on if it is "outside" the shown area; we could zoom into it ' with a change of coordinates, or do nothing... End If
' ' This sub converts from Lat & Lon to Y & X (screen coord) ' Sub locate_mt(numero, lat, lon)
Dim PosGeoX, PosGeoY, angulo As Double 'remember option explicit! Dim X, Y As Double Dim Res As Double
PosGeoX = lon PosGeoY = lat
If GeoX1 <> Empty Then Res = (GeoX2 - GeoX1) / (PosX2 - PosX1) 'caution here when PosX1->PosX2
X = Screen.TwipsPerPixelX * (((PosGeoX - GeoX1) / Res) + PosX1) Y = Screen.TwipsPerPixelY * (((PosGeoY - GeoY2) / (-1 * Res)) + PosY1) veh(numero).Left = X veh(numero).Top = Y End If
End Sub
Note the -1 in the lon calcule; all maps have intrinsic lat & lon signs, so we have to take care of result's signs to avoid crashing poor VB. A screenshot of the result. veh(i)'s are the small trucks over the map and the one with red border is one that's no longer transmitting (caused by an error in the cellular number, not the app ;-)):
http://www.bcrux.com/docs/avl-gis.jpg
* Link: Icon Art |