void MapRegionChanged(object sender, MKMapViewChangeEventArgs e) { var current = new Dictionary <string, AirportAnnotation> (); var added = new List <AirportAnnotation> (); // Query for the list of airports in the new region foreach (var airport in GetAirports(mapView.Region)) { AirportAnnotation annotation; if (annotations.ContainsKey(airport.FAA)) { // This airport is already in view... annotation = annotations[airport.FAA]; annotation.UserCoordinates = coordinates; annotations.Remove(airport.FAA); } else { // This is a new annotation, keep track of it in 'added' annotation = new AirportAnnotation(airport, coordinates); added.Add(annotation); } current.Add(annotation.Airport.FAA, annotation); } if (annotations.Count > 0) { // Remove annotations that are no longer in view mapView.RemoveAnnotations(annotations.Values.ToArray()); foreach (var annotation in annotations.Values) { annotation.Dispose(); } annotations.Clear(); } if (added.Count > 0) { mapView.AddAnnotations(added.ToArray()); foreach (var annotation in added) { annotation.Dispose(); } } annotations = current; }
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; }
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; }
void MapRegionChanged(object sender, MKMapViewChangeEventArgs e) { var current = new Dictionary<string, AirportAnnotation> (); var added = new List<AirportAnnotation> (); // Query for the list of airports in the new region foreach (var airport in GetAirports (mapView.Region)) { AirportAnnotation annotation; if (annotations.ContainsKey (airport.FAA)) { // This airport is already in view... annotation = annotations[airport.FAA]; annotation.UserCoordinates = coordinates; annotations.Remove (airport.FAA); } else { // This is a new annotation, keep track of it in 'added' annotation = new AirportAnnotation (airport, coordinates); added.Add (annotation); } current.Add (annotation.Airport.FAA, annotation); } if (annotations.Count > 0) { // Remove annotations that are no longer in view mapView.RemoveAnnotations (annotations.Values.ToArray ()); foreach (var annotation in annotations.Values) annotation.Dispose (); annotations.Clear (); } if (added.Count > 0) { mapView.AddAnnotations (added.ToArray ()); foreach (var annotation in added) annotation.Dispose (); } annotations = current; }