예제 #1
0
        public MapData LocateWaypointWithLineOfSight(WaypointDetectionMethod method, List <GPSLocation> history, int waypointIndex = 0, int viewArc = 0, double distance = 1.0)
        {
            MapData waypoint = null;

            var location = history.Last();

            var sortedMAPPoints = GLOSAHelper.SortMAPDataByDistanceFromCurrentLocation(_mapDataCache, location.Latitude, location.Longitude);

            if (sortedMAPPoints != null && sortedMAPPoints.Count > 0)
            {
                switch (method)
                {
                case WaypointDetectionMethod.ShortestDistance:
                    waypoint = sortedMAPPoints.First();
                    break;

                case WaypointDetectionMethod.GPSHistoryDirection:
                    GPSLocation to             = history[history.Count - 1];
                    double?     vehicleHeading = LocationHelper.HeadingFromGPSTrail(history);

                    List <IntersectionNode> listOfMAPDataWaypoints = IntersectionNode.IntersectionNodesFromMAPData(_mapDataCache).ToList();
                    var filtered = IntersectionNode.Filter(listOfMAPDataWaypoints, vehicleHeading, history);
                    var sortedByBearingAndDistance = IntersectionNode.SortIntersectionNodes(filtered, to, vehicleHeading, viewArc, distance).ToList();

                    if (sortedByBearingAndDistance.Count() > waypointIndex)
                    {
                        var tn = sortedByBearingAndDistance.ToList()[waypointIndex];
                        waypoint = tn.MapData;
                    }

                    break;

                default:
                    throw new Exception("Waypoint Detection Method not implemented.");
                    break;
                }
            }
            return(waypoint);
        }