void DrawMap() { int rtcnt = 0; try { mapoverlay.Routes.Clear(); DateTime starttime = DateTime.MinValue; DateTime workingtime = starttime; DateTime lastdrawn = DateTime.MinValue; List<PointLatLng> routelist = new List<PointLatLng>(); List<int> samplelist = new List<int>(); //zg1.GraphPane.GraphObjList.Clear(); //check if GPS data are available if (!DFLog.logformat.ContainsKey("GPS")) return; int index = DFLog.FindMessageOffset("GPS", "Lat"); if (index == -1) { return; } int index2 = DFLog.FindMessageOffset("GPS", "Lng"); if (index2 == -1) { return; } int index3 = DFLog.FindMessageOffset("GPS", "Status"); if (index3 == -1) { return; } int i = 0; int firstpoint = 0; int b = 0; foreach (var item2 in logdata) { b++; var item = DFLog.GetDFItemFromLine(item2, b); if (item.msgtype == "GPS") { var ans = getPointLatLng(item); if (ans.HasValue) { routelist.Add(ans.Value); samplelist.Add(i); if (routelist.Count > 1000) { //split the route in several small parts (due to memory errors) GMapRoute route_part = new GMapRoute(routelist, "route_" + rtcnt); route_part.Stroke = new Pen(Color.FromArgb(127, Color.Blue), 2); LogRouteInfo lri = new LogRouteInfo(); lri.firstpoint = firstpoint; lri.lastpoint = i; lri.samples.AddRange(samplelist); route_part.Tag = lri; route_part.IsHitTestVisible = true; mapoverlay.Routes.Add(route_part); rtcnt++; //clear the list and set the last point as first point for the next route routelist.Clear(); samplelist.Clear(); firstpoint = i; samplelist.Add(firstpoint); routelist.Add(ans.Value); } } } i++; } GMapRoute route = new GMapRoute(routelist, "route_" + rtcnt); route.Stroke = new Pen(Color.FromArgb(127, Color.Blue), 2); LogRouteInfo lri2 = new LogRouteInfo(); lri2.firstpoint = firstpoint; lri2.lastpoint = i; lri2.samples.AddRange(samplelist); route.Tag = lri2; route.IsHitTestVisible = true; mapoverlay.Routes.Add(route); rtcnt++; myGMAP1.ZoomAndCenterRoute(route); } catch (Exception ex) { log.Error(ex); } if (rtcnt > 0) myGMAP1.RoutesEnabled = true; }
void DrawMap() { int rtcnt = 0; try { mapoverlay.Routes.Clear(); DateTime starttime = DateTime.MinValue; DateTime workingtime = starttime; DateTime lastdrawn = DateTime.MinValue; List<PointLatLng> routelist = new List<PointLatLng>(); List<int> samplelist = new List<int>(); List<PointLatLng> routelistgps2 = new List<PointLatLng>(); List<int> samplelistgps2 = new List<int>(); List<PointLatLng> routelistpos = new List<PointLatLng>(); List<int> samplelistpos = new List<int>(); int i = 0; int firstpoint = 0; int firstpointpos = 0; int firstpointgps2 = 0; foreach (var item in logdata.GetEnumeratorType(new string[] {"GPS", "POS", "GPS2"})) { i = item.lineno; if (item.msgtype == "GPS") { var ans = getPointLatLng(item); if (ans.HasValue) { routelist.Add(ans.Value); samplelist.Add(i); if (routelist.Count > 1000) { //split the route in several small parts (due to memory errors) GMapRoute route_part = new GMapRoute(routelist, "route_" + rtcnt); route_part.Stroke = new Pen(Color.FromArgb(127, Color.Blue), 2); LogRouteInfo lri = new LogRouteInfo(); lri.firstpoint = firstpoint; lri.lastpoint = i; lri.samples.AddRange(samplelist); route_part.Tag = lri; route_part.IsHitTestVisible = false; mapoverlay.Routes.Add(route_part); rtcnt++; //clear the list and set the last point as first point for the next route routelist.Clear(); samplelist.Clear(); firstpoint = i; samplelist.Add(firstpoint); routelist.Add(ans.Value); } } } if (item.msgtype == "GPS2") { var ans = getPointLatLng(item); if (ans.HasValue) { routelistgps2.Add(ans.Value); samplelistgps2.Add(i); if (routelistgps2.Count > 1000) { //split the route in several small parts (due to memory errors) GMapRoute route_part = new GMapRoute(routelistgps2, "routegps2_" + rtcnt); route_part.Stroke = new Pen(Color.FromArgb(127, Color.Green), 2); LogRouteInfo lri = new LogRouteInfo(); lri.firstpoint = firstpointgps2; lri.lastpoint = i; lri.samples.AddRange(samplelistgps2); route_part.Tag = lri; route_part.IsHitTestVisible = false; mapoverlay.Routes.Add(route_part); rtcnt++; //clear the list and set the last point as first point for the next route routelistgps2.Clear(); samplelistgps2.Clear(); firstpointgps2 = i; samplelistgps2.Add(firstpointgps2); routelistgps2.Add(ans.Value); } } } if (item.msgtype == "POS") { var ans = getPointLatLng(item); if (ans.HasValue) { routelistpos.Add(ans.Value); samplelistpos.Add(i); if (routelistpos.Count > 1000) { //split the route in several small parts (due to memory errors) GMapRoute route_part = new GMapRoute(routelistpos, "routepos_" + rtcnt); route_part.Stroke = new Pen(Color.FromArgb(127, Color.Red), 2); LogRouteInfo lri = new LogRouteInfo(); lri.firstpoint = firstpointpos; lri.lastpoint = i; lri.samples.AddRange(samplelistpos); route_part.Tag = lri; route_part.IsHitTestVisible = false; mapoverlay.Routes.Add(route_part); rtcnt++; //clear the list and set the last point as first point for the next route routelistpos.Clear(); samplelistpos.Clear(); firstpointpos = i; samplelistpos.Add(firstpointpos); routelistpos.Add(ans.Value); } } } i++; } // add last part of each // gps1 GMapRoute route = new GMapRoute(routelist, "route_" + rtcnt); route.Stroke = new Pen(Color.FromArgb(127, Color.Blue), 2); route.IsHitTestVisible = false; LogRouteInfo lri2 = new LogRouteInfo(); lri2.firstpoint = firstpoint; lri2.lastpoint = i; lri2.samples.AddRange(samplelist); route.Tag = lri2; route.IsHitTestVisible = false; mapoverlay.Routes.Add(route); // gps2 GMapRoute route2 = new GMapRoute(routelistgps2, "routegps2_" + rtcnt); route2.Stroke = new Pen(Color.FromArgb(127, Color.Green), 2); route2.IsHitTestVisible = false; LogRouteInfo lri3 = new LogRouteInfo(); lri3.firstpoint = firstpointgps2; lri3.lastpoint = i; lri3.samples.AddRange(samplelistgps2); route2.Tag = lri3; route2.IsHitTestVisible = false; mapoverlay.Routes.Add(route2); // pos GMapRoute route3 = new GMapRoute(routelistpos, "route2_" + rtcnt); route3.Stroke = new Pen(Color.FromArgb(127, Color.Red), 2); route3.IsHitTestVisible = false; LogRouteInfo lri4 = new LogRouteInfo(); lri4.firstpoint = firstpointpos; lri4.lastpoint = i; lri4.samples.AddRange(samplelistpos); route3.Tag = lri4; route3.IsHitTestVisible = false; mapoverlay.Routes.Add(route3); rtcnt++; myGMAP1.ZoomAndCenterRoutes(mapoverlay.Id); } catch (Exception ex) { log.Error(ex); } if (rtcnt > 0) myGMAP1.RoutesEnabled = true; }