MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; if (annotation.GetType() != typeof(CustomAnnotation)) { return(null); } var anno = (CustomAnnotation)annotation; var pin = anno.Pin; annotationView = mapView.DequeueReusableAnnotation(anno.Id); if (annotationView == null) { annotationView = new CustomMKAnnotationView(anno.Id, anno.Title, anno.Subtitle, pin.Position, anno.Type) { CalloutOffset = new CGPoint(10, 10), RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure) }; if (pin.Type == PinType.Generic) { annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("UserLocation.png")); annotationView.Image = UIImage.FromFile("UserLocation.png"); } else { annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("CitoPin.png")); annotationView.Image = UIImage.FromFile("CitoPin.png"); } } annotationView.CanShowCallout = false; return(annotationView); }
/// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation) { if(ThisIsTheCurrentLocation(mapView, annotation)) { return null; } // try and dequeue the annotation view MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) annotationView = new MKAnnotationView(annotation, annotationIdentifier); else // if we did dequeue one for reuse, assign the annotation to it annotationView.Annotation = annotation; // configure our annotation view properties annotationView.CanShowCallout = true; nfloat r; nfloat g; nfloat b; nfloat a; RandomColorHelper.GetRandomColor().GetRGBA(out r, out g, out b, out a); if (annotation.GetType () == typeof(HouseMapAnnotation)) { var rank = (annotation as HouseMapAnnotation).Rank; var fontSize = rank.Length >= 3 ? 9 : 15; annotationView.Image = LightMapPointStyleKit.ImageOfLightMapPoint ((float)r, (float)g, (float)b, (float)a, rank, fontSize); annotationView.Selected = true; // you can add an accessory view, in this case, we'll add a button on the right, and an image on the left detailButton = UIButton.FromType(UIButtonType.DetailDisclosure); detailButton.TintColor = UIColor.Black; detailButton.TouchUpInside += (s, e) => { Console.WriteLine ("Clicked"); var detailViewController = UIStoryboard.FromName ("MainStoryboard", null).InstantiateViewController("HouseDetailsViewController") as HouseDetailsViewController; detailViewController.Annotation = annotation as HouseMapAnnotation; mapView.DeselectAnnotation(annotation,true); this.parent.NavigationController.PushViewController(detailViewController,true); }; annotationView.RightCalloutAccessoryView = detailButton; FetchImageAsync(annotationView,(annotation as HouseMapAnnotation).House); } return annotationView; }