Ejemplo n.º 1
0
        static string GetAirportCode(string value, List <Airport> airports, HashSet <string> missing)
        {
            Airport airport;

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            // First, try looking up the airport by (any) airport code.
            if ((airport = Airports.GetAirport(value, AirportCode.Any)) != null)
            {
                airports.Add(airport);
                return(airport.FAA);
            }

            // Next, try matching the common name of the airport.
            if ((airport = Airports.GetAirportByName(value)) != null)
            {
                airports.Add(airport);
                return(airport.FAA);
            }

            // Unknown airport... just return the provided string.
            missing.Add(value);

            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the main entry point of the application.
        /// </summary>
        static void Main(string[] args)
        {
            Airports.Init();
            LogBook.Init();

            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main(args, null, "AppDelegate");
        }
Ejemplo n.º 3
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Default to the region for North America
            double minLatitude  = 37.37 - (28.49 / 2);
            double maxLatitude  = 37.37 + (28.49 / 2);
            double minLongitide = -96.24 - (31.025 / 2);
            double maxLongitude = -96.24 + (31.025 / 2);
            bool   initialized  = false;

            foreach (var code in LogBook.GetVisitedAirports())
            {
                Airport airport = Airports.GetAirport(code, AirportCode.FAA);
                if (airport == null)
                {
                    continue;
                }

                if (!initialized)
                {
                    minLongitide = maxLongitude = airport.Longitude;
                    minLatitude  = maxLatitude = airport.Latitude;
                    initialized  = true;
                }
                else
                {
                    minLongitide = Math.Min(minLongitide, airport.Longitude);
                    maxLongitude = Math.Max(maxLongitude, airport.Longitude);
                    minLatitude  = Math.Min(minLatitude, airport.Latitude);
                    maxLatitude  = Math.Max(maxLatitude, airport.Latitude);
                }
            }

            coordinates = new CLLocationCoordinate2D((minLatitude + maxLatitude) / 2, (minLongitide + maxLongitude) / 2);
            double spanLongitude = Math.Abs(maxLongitude - minLongitide);
            double spanLatitude  = Math.Abs(maxLatitude - minLatitude);

            if (initialized)
            {
                spanLongitude = Math.Max(spanLongitude, 1.0) * 1.25;
                spanLatitude  = Math.Max(spanLatitude, 1.0) * 1.25;
            }

            // Get the region for North America
            var region = new MKCoordinateRegion(
                coordinates, new MKCoordinateSpan(spanLatitude, spanLongitude)
                );

            mapView.SetRegion(region, animated);
        }
Ejemplo n.º 4
0
        void MapRegionChanged(object sender, MKMapViewChangeEventArgs e)
        {
            Dictionary <string, AirportAnnotation> current = new Dictionary <string, AirportAnnotation> ();
            List <AirportAnnotation> added = new List <AirportAnnotation> ();

            // Query for the list of airports in the new region
            foreach (var airport in Airports.GetAirports(mapView.Region))
            {
                AirportAnnotation aa;

                if (annotations.ContainsKey(airport.FAA))
                {
                    // This airport is already in view...
                    aa = annotations[airport.FAA];
                    annotations.Remove(airport.FAA);
                }
                else
                {
                    // This is a new annotation, keep track of it in 'added'
                    aa = new AirportAnnotation(airport);
                    added.Add(aa);
                }

                current.Add(aa.Airport.FAA, aa);
            }

            if (annotations.Count > 0)
            {
                // Remove annotations that are no longer in view
                mapView.RemoveAnnotations(annotations.Values.ToArray());
                annotations.Clear();
            }

            if (added.Count > 0)
            {
                mapView.AddAnnotation(added.ToArray());
                added.Clear();
            }

            annotations = current;
        }
Ejemplo n.º 5
0
        IEnumerable <Airport> GetAirports(MKCoordinateRegion region)
        {
            if (visited)
            {
                foreach (var code in LogBook.GetVisitedAirports())
                {
                    Airport airport = Airports.GetAirport(code, AirportCode.FAA);
                    if (airport != null)
                    {
                        yield return(airport);
                    }
                }
            }
            else
            {
                foreach (var airport in Airports.GetAirports(region))
                {
                    yield return(airport);
                }
            }

            yield break;
        }
Ejemplo n.º 6
0
        static bool IsCrossCountry(List <Airport> airports, double minimum)
        {
            if (airports.Count < 2)
            {
                return(false);
            }

            Airport origin = airports[0];

            for (int i = 1; i < airports.Count; i++)
            {
                double distance = Airports.GetDistanceBetween(origin, airports[i]);

                // The FAA only classifies flights where the pilot touches down
                // at one or more airports that are greater than 50 nautical miles
                // from the point of origin.
                if (distance > minimum)
                {
                    return(true);
                }
            }

            return(false);
        }