Esempio n. 1
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;
        }
Esempio n. 2
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;
        }