Esempio n. 1
0
        private static void SimulateTrack(long trackId, Action<TrackPoint> action4TrackPoint = null, Action<WayPoint> action4WayPoint = null)
        {
            System.Console.WriteLine("Start to simulateTrack.");

            var track = TrackDao.GetTrack(trackId);
            DateTime? endDate = track.EndTime;
            track.EndTime = null;
            (new TrackDao()).Update(track);

            var trackPointDao = new TrackPointDao();
            var wayPointDao = new WayPointDao();

            var trackPoints = TrackPointDao.GetTrackPoints(track);
            foreach (var p in trackPoints)
            {
                p.IsActive = false;
                trackPointDao.Update(p);
            }
            var wayPoints = WayPointDao.GetWaypoints(track);
            foreach (var p in wayPoints)
            {
                p.IsActive = false;
                wayPointDao.Update(p);
            }
            int wayPointIdx = 0;

            TrackPoint lastp = null;
            foreach (var p in trackPoints)
            {
                //if (lastp != null && p.GpsTime == lastp.GpsTime)
                //    continue;
                p.IsActive = true;
                trackPointDao.Update(p);

                if (action4TrackPoint != null)
                {
                    action4TrackPoint(p);
                }
                if (wayPointIdx < wayPoints.Count
                    && p.MessageTime >= wayPoints[wayPointIdx].MessageTime)
                {
                    wayPoints[wayPointIdx].IsActive = true;
                    wayPointDao.Update(wayPoints[wayPointIdx]);

                    action4WayPoint(wayPoints[wayPointIdx]);
                    wayPointIdx++;
                }

                System.Console.Write("Press any Key.");
                System.Console.ReadLine();
                //System.Threading.Thread.Sleep(5000);
                System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime));

                lastp = p;
            }

            track.EndTime = endDate;
            (new TrackDao()).Update(track);
            System.Console.WriteLine("Finish.");
        }
Esempio n. 2
0
        private static void SimulateTrack(long trackId, Action <TrackPoint> action4TrackPoint = null, Action <WayPoint> action4WayPoint = null)
        {
            System.Console.WriteLine("Start to simulateTrack.");

            var      track   = TrackDao.GetTrack(trackId);
            DateTime?endDate = track.EndTime;

            track.EndTime = null;
            (new TrackDao()).Update(track);

            var trackPointDao = new TrackPointDao();
            var wayPointDao   = new WayPointDao();

            var trackPoints = TrackPointDao.GetTrackPoints(track);

            foreach (var p in trackPoints)
            {
                p.IsActive = false;
                trackPointDao.Update(p);
            }
            var wayPoints = WayPointDao.GetWaypoints(track);

            foreach (var p in wayPoints)
            {
                p.IsActive = false;
                wayPointDao.Update(p);
            }
            int wayPointIdx = 0;

            TrackPoint lastp = null;

            foreach (var p in trackPoints)
            {
                //if (lastp != null && p.GpsTime == lastp.GpsTime)
                //    continue;
                p.IsActive = true;
                trackPointDao.Update(p);

                if (action4TrackPoint != null)
                {
                    action4TrackPoint(p);
                }
                if (wayPointIdx < wayPoints.Count &&
                    p.MessageTime >= wayPoints[wayPointIdx].MessageTime)
                {
                    wayPoints[wayPointIdx].IsActive = true;
                    wayPointDao.Update(wayPoints[wayPointIdx]);

                    action4WayPoint(wayPoints[wayPointIdx]);
                    wayPointIdx++;
                }

                System.Console.Write("Press any Key.");
                System.Console.ReadLine();
                //System.Threading.Thread.Sleep(5000);
                System.Console.WriteLine(string.Format("write trackpoint at {0}", p.GpsTime));

                lastp = p;
            }

            track.EndTime = endDate;
            (new TrackDao()).Update(track);
            System.Console.WriteLine("Finish.");
        }
Esempio n. 3
0
        private void LoadTrackData(Track track, bool clearFirst = false)
        {
            Feng.Async.AsyncHelper.Start(() =>
            {
                IList <TrackPoint> trackPoints = TrackPointDao.GetTrackPoints(track);
                if (trackPoints.Count == 0)
                {
                    if (track.StartTime.HasValue)
                    {
                        if (!track.EndTime.HasValue)
                        {
                            track.EndTime = DateTime.MaxValue;
                        }

                        trackPoints = TrackPointDao.GetTrackPoints(track.VehicleName, track.StartTime.Value, track.EndTime.Value);
                    }
                }
                return(trackPoints);
            }, (result) =>
            {
                var trackPoints           = result as IList <TrackPoint>;
                List <PointLatLng> points = new List <GMap.NET.PointLatLng>();
                foreach (var p in trackPoints)
                {
                    points.Add(new PointLatLng(p.Latitude, p.Longitude));
                }
                if (clearFirst)
                {
                    ClearTrack();
                }

                DarwTrack(points);

                if (trackPoints.Count > 0)
                {
                    //DrawCircle();
                    var p  = trackPoints[trackPoints.Count - 1];
                    var p2 = new PointLatLng(p.Latitude, p.Longitude);
                    var m  = new GMap.NET.WindowsForms.Markers.GMapMarkerCircle(p2);
                    m_trackOverlay.Markers.Add(m);

                    m_MainMap.Position = p2;
                }

                if (tsm显示路线点地址.Checked)
                {
                    // Show Start, End
                    for (int i = 0; i < trackPoints.Count; i += trackPoints.Count - 1)
                    {
                        var p         = trackPoints[i];
                        var m         = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleRed(new PointLatLng(p.Latitude, p.Longitude));
                        m.ToolTipText = (i == 0 ? "Start" : "End") + ", " + p.GpsTime.ToLongTimeString();
                        m_trackOverlay.Markers.Add(m);
                    }

                    try
                    {
                        DrawTrackPointAddr(trackPoints);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (tsm显示路线点.Checked)
                {
                    IList <WayPoint> wayPoint = WayPointDao.GetWaypoints(track);

                    foreach (var p in wayPoint)
                    {
                        if (!string.IsNullOrEmpty(p.Action))
                        {
                            var m         = new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleRed(new PointLatLng(p.Latitude, p.Longitude));
                            m.ToolTipText = p.Action + "," + p.GpsTime.ToLongTimeString();
                            m_trackOverlay.Markers.Add(m);
                        }
                    }
                }

                if (!track.EndTime.HasValue)
                {
                    if (m_timer == null)
                    {
                        m_timer          = new System.Timers.Timer(30 * 1000);
                        m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
                    }

                    m_timer.AutoReset = true;
                    m_timer.Enabled   = true;
                }

                if (track.Route != null)
                {
                    LoadRoute(track.Route.Name);
                }
            });
        }