protected virtual MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView mapPin = null; // https://bugzilla.xamarin.com/show_bug.cgi?id=26416 var userLocationAnnotation = Runtime.GetNSObject(annotation.Handle) as MKUserLocation; if (userLocationAnnotation != null) { return(null); } const string defaultPinId = "defaultPin"; mapPin = mapView.DequeueReusableAnnotation(defaultPinId); if (mapPin == null) { #pragma warning disable CA1416 // TODO: MKPinAnnotationView type has [UnsupportedOSPlatform("macos12.0")], [UnsupportedOSPlatform("ios15.0")], [UnsupportedOSPlatform("tvos15.0")] mapPin = new MKPinAnnotationView(annotation, defaultPinId); #pragma warning restore CA1416 mapPin.CanShowCallout = true; } mapPin.Annotation = annotation; AttachGestureToPin(mapPin, annotation); return(mapPin); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // 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 MKPinAnnotationView(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; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; annotationView.Selected = true; Assembly ass = this.GetType ().Assembly; var annotationImage = UIImage.FromBundle((annotation as BasicPinAnnotation).ImageAdress); annotationView.LeftCalloutAccessoryView = new UIImageView( ResizeImage.MaxResizeImage(annotationImage,(float)40,(float)20)); return annotationView; }
public void InitWithFrame() { #if !MONOMAC if (!UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) // Crashes with EXC_BAD_ACCESS (SIGABRT) if < iOS 7.0 { Assert.Inconclusive("Crashes with EXC_BAD_ACCESS (SIGABRT) if < iOS 7.0"); } #endif RectangleF frame = new RectangleF(10, 10, 100, 100); using (var av = new MKPinAnnotationView(frame)) { Assert.That(av.Frame.ToString(), Is.EqualTo(frame.ToString()), "Frame"); // fp comparison fails Assert.Null(av.Annotation, "Annotation"); Assert.False(av.AnimatesDrop, "AnimatesDrop"); if (!TestRuntime.CheckXcodeVersion(7, 0)) { return; } Assert.That(av.PinColor, Is.EqualTo(MKPinAnnotationColor.Red), "PinColor"); #if MONOMAC Assert.That(av.PinTintColor.ToString(), Is.EqualTo("Developer/systemRedColor"), "PinTintColor"); #else if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { Assert.That(av.PinTintColor.ToString(), Is.EqualTo(UIColor.FromRGBA(255, 59, 48, 255).ToString()), "PinTintColor"); } else { Assert.Null(av.PinTintColor, "PinTintColor"); // differs from the other init call } #endif } }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude); var colorPin = ((ColorMap)Element).Pins.Where(x => x.Position == position).First() as ColorPin; //Las siguientes líneas son las encargadas de reemplazar el Pin actual por uno de nuestra clase nativa con soporte para el color var colorAnnotation = new ColorPointAnnotation(colorPin.PinColor.ToUIColor()) { Title = colorPin.Label, Subtitle = colorPin.Address, Coordinate = new CLLocationCoordinate2D(colorPin.Position.Latitude, colorPin.Position.Longitude) }; MKPinAnnotationView view = null; if (colorAnnotation != null) { var identifier = "colorAnnotation"; view = mapView.DequeueReusableAnnotation(identifier) as MKPinAnnotationView; if (view == null) { view = new MKPinAnnotationView(colorAnnotation, identifier); } view.Annotation = colorAnnotation; view.CanShowCallout = true; view.PinTintColor = colorAnnotation.Color; } return(view); }
/// <summary> /// Returns our custom MKAnnotationView /// </summary> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return(null); } var annotationView = mapView.DequeueReusableAnnotation(Identifier) as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, Identifier) { PinColor = MKPinAnnotationColor.Green, AnimatesDrop = true, CanShowCallout = true, RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure) } } ; else { annotationView.Annotation = annotation; } return(annotationView); }
public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { var pinView = mapView.DequeueReusableAnnotation("colorpin") as MKPinAnnotationView; if (pinView == null) { pinView = new MKPinAnnotationView(annotation, "colorpin") { CanShowCallout = true, }; } else { pinView.Annotation = annotation; } var color = MKPinAnnotationColor.Green; var place = viewModel.Places.First(p => p.Latitude == annotation.Coordinate.Latitude && p.Longitude == annotation.Coordinate.Longitude && p.Name == annotation.GetTitle()); if (place.Stars < 3.5) { color = MKPinAnnotationColor.Red; } else if (place.Stars < 4.3) { color = MKPinAnnotationColor.Purple; } pinView.PinColor = color; return(pinView); }
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (AnnotationIsUserLocation(mapView, annotation)) { return(null); } var annotationView = mapView.DequeueReusableAnnotation(_annotationViewIdentifier) as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, _annotationViewIdentifier); } else { annotationView.Annotation = annotation; } if (annotation is WayPointMkAnnotation wayPointMkAnnotation) { annotationView.PinTintColor = wayPointMkAnnotation.PinColor; annotationView.CanShowCallout = true; } return(annotationView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return(null); } MKAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, pId); } var annot = annotation as AnnotationForMap; if (annot.available == true) { ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Green; } else { ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Red; } pinView.CanShowCallout = true; return(pinView); }
UIButton detailButton; // need class-level ref to avoid GC /// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { // 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 MKPinAnnotationView(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; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; 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.TouchUpInside += (s, e) => { var c = (annotation as MKAnnotation).Coordinate; new UIAlertView("Annotation Clicked", "You clicked on " + c.Latitude.ToString() + ", " + c.Longitude.ToString() , null, "OK", null).Show(); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("Images/Icon/29_icon.png")); //annotationView.Image = UIImage.FromBundle("Images/Apress-29x29.png"); return annotationView; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { try { var ca = (ConferenceAnnotation)annotation; var aview = (MKPinAnnotationView)mapView.DequeueReusableAnnotation("pin"); if (aview == null) { aview = new MKPinAnnotationView(ca, "pin"); } else { aview.Annotation = ca; } aview.AnimatesDrop = true; aview.PinColor = MKPinAnnotationColor.Purple; aview.CanShowCallout = true; // UIButton rightCallout = UIButton.FromType(UIButtonType.DetailDisclosure); // rightCallout.Frame = new RectangleF(250,8f,25f,25f); // rightCallout.TouchDown += delegate // { // NSUrl url = new NSUrl("http://maps.google.com/maps?q=" + ca.Coordinate.ToLL() ); // UIApplication.SharedApplication.OpenUrl(url); // }; // aview.RightCalloutAccessoryView = rightCallout; return(aview); } catch (Exception) { return(null); } }
public override void ViewDidLoad() { mapView = new MKMapView(); RectangleF frame = new RectangleF(0,0,320,360); mapView.Frame = frame; mapView.ShowsUserLocation = true; var myAnnotation = new MyAnnotation(new CLLocationCoordinate2D(0,0), "Home", "is where the heart is"); mapView.AddAnnotationObject(myAnnotation); UIButton detailButton = UIButton.FromType(UIButtonType.DetailDisclosure); mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) { var anv = mapView.DequeueReusableAnnotation("thislocation"); if (anv == null) { anv = new MKPinAnnotationView(annotation, "thislocation"); detailButton.TouchUpInside += (s, e) => { Console.WriteLine ("Tapped"); }; anv.RightCalloutAccessoryView = detailButton; } else { anv.Annotation = annotation; } anv.CanShowCallout = true; return anv; }; View.AddSubview(mapView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) { return(null); } else { // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (anView == null) { anView = new MKPinAnnotationView(annotation, pId); } ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.CanShowCallout = true; } return(anView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) { return(null); } // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (anView == null) { anView = new MKPinAnnotationView(annotation, pId); } ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.CanShowCallout = true; ((MKPinAnnotationView)anView).AnimatesDrop = true; anView.Draggable = true; detailButton = UIButton.FromType(UIButtonType.DetailDisclosure); anView.RightCalloutAccessoryView = detailButton; return(anView); }
private void UpdatePinColor(MapPin pin, MKPinAnnotationView nativeView) { if (nativeView != null) { nativeView.PinTintColor = pin.Color.ToUIColor(); } }
public void Ctor_Annotation() { using (var a = new MKPolyline()) using (MKPinAnnotationView av = new MKPinAnnotationView(a, "reuse")) { Assert.AreSame(a, av.Annotation, "Annotation"); #if !MONOMAC if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0)) // Crashes with EXC_BAD_ACCESS (SIGABRT) if < iOS 7.0 { Assert.False(av.AnimatesDrop, "AnimatesDrop"); } if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0)) { return; } #endif Assert.That(av.PinColor, Is.EqualTo(MKPinAnnotationColor.Red), "PinColor"); if (TestRuntime.CheckXcodeVersion(7, 0)) { Assert.NotNull(av.PinTintColor, "PinTintColor"); } } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is BasicMapAnnotation) { MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); } else { annotationView.Annotation = annotation; } annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).PinTintColor = UIColor.Orange; if (parent.ViewModel.Item.ImageBytes != null) { var leftIconView = new UIImageView(new CGRect(0, 0, 53, 53)); var Image = BytesToImageConverter.Convert(parent.ViewModel.Item.ImageBytes); leftIconView.Image = Image; annotationView.LeftCalloutAccessoryView = leftIconView; } return(annotationView); } return(null); }
void AttachGestureToPin(MKPinAnnotationView mapPin, IMKAnnotation annotation) { UIGestureRecognizer[] recognizers = mapPin.GestureRecognizers; if (recognizers != null) { foreach (UIGestureRecognizer r in recognizers) { mapPin.RemoveGestureRecognizer(r); } } Action <UITapGestureRecognizer> action = g => OnClick(annotation, g); var recognizer = new UITapGestureRecognizer(action) { ShouldReceiveTouch = (gestureRecognizer, touch) => { _lastTouchedView = touch.View; return(true); } }; List.Add(action); List.Add(recognizer); mapPin.AddGestureRecognizer(recognizer); }
UIButton detailButton; // need class-level ref to avoid GC /// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // 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 MKPinAnnotationView(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; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; 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.TouchUpInside += (s, e) => { var c = (annotation as MKAnnotation).Coordinate; new UIAlertView("Annotation Clicked", "You clicked on " + c.Latitude.ToString() + ", " + c.Longitude.ToString(), null, "OK", null).Show(); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("Images/Icon/29_icon.png")); //annotationView.Image = UIImage.FromBundle("Images/Apress-29x29.png"); return(annotationView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { Console.WriteLine("attempt to get view for MKAnnotation " + annotation); try { var anv = mapView.DequeueReusableAnnotation("thislocation"); if (anv == null) { Console.WriteLine("creating new MKAnnotationView"); var pinanv = new MKPinAnnotationView(annotation, "thislocation"); pinanv.AnimatesDrop = true; pinanv.PinColor = MKPinAnnotationColor.Green; pinanv.CanShowCallout = true; anv = pinanv; } else { anv.Annotation = annotation; } return(anv); } catch (Exception ex) { Console.WriteLine("GetViewForAnnotation Exception " + ex); return(null); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // add the map view var map = new MKMapView(UIScreen.MainScreen.Bounds); View.Add(map); // change the map style map.MapType = MKMapType.Standard; // enable/disable interactions // map.ZoomEnabled = false; // map.ScrollEnabled = false; // show user location if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { locationManager.RequestAlwaysAuthorization (); } map.ShowsUserLocation = true; // TODO: Step 3d - specify a custom map delegate // var mapDelegate = new MyMapDelegate(); // map.Delegate = mapDelegate; // Add a point annotation map.AddAnnotation(new MKPointAnnotation() { Title = "MyAnnotation", Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824) }); // TODO: Step 3f - add a custom annotation // map.AddAnnotation(new CustomAnnotation("CustomSpot", new MonoTouch.CoreLocation.CLLocationCoordinate2D(38.364260, -68.120824))); // TODO: Step 3a - remove old GetViewForAnnotation delegate code to new delegate - we will recreate this next // Customize annotation view via GetViewForAnnotation delegate map.GetViewForAnnotation = delegate(MKMapView mapView, NSObject annotation) { if (annotation is MKUserLocation) return null; MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, pId); pinView.PinColor = MKPinAnnotationColor.Green; pinView.CanShowCallout = true; // Add accessory views to the pin pinView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); pinView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("Icon-29.png")); } return pinView; }; }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (IsUserLocationAnnotation(mapView, annotation)) { return(null); } MKPinAnnotationView pinView = NativeMapView.DequeueReusableAnnotation(DefaultPinId) as MKPinAnnotationView; if (pinView == null) { pinView = new MKPinAnnotationView(annotation, DefaultPinId); } pinView.CanShowCallout = true; pinView.AnimatesDrop = true; UIButton button = new UIButton(UIButtonType.ContactAdd); button.TouchUpInside += (object sender, EventArgs e) => { sourceMapItem = MKMapItem.MapItemForCurrentLocation(); destinationMapItem = new MKMapItem(new MKPlacemark(annotation.Coordinate)); CalculateRouteDetails(); }; pinView.RightCalloutAccessoryView = button; return(pinView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { // if it's the user location just return if (annotation is MKUserLocation) { return(null); } MKAnnotationView anView; // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); // if we didn't deque reuse if (anView == null) { anView = new MKPinAnnotationView(annotation, pId); } // set the accessory and pin ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); anView.CanShowCallout = true; // return the view return(anView); }
protected virtual MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView mapPin = null; // https://bugzilla.xamarin.com/show_bug.cgi?id=26416 var userLocationAnnotation = Runtime.GetNSObject(annotation.Handle) as MKUserLocation; if (userLocationAnnotation != null) { return(null); } const string defaultPinId = "defaultPin"; mapPin = mapView.DequeueReusableAnnotation(defaultPinId); if (mapPin == null) { mapPin = new MKPinAnnotationView(annotation, defaultPinId); mapPin.CanShowCallout = true; } mapPin.Annotation = annotation; AttachGestureToPin(mapPin, annotation); return(mapPin); }
/// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // 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 MKPinAnnotationView(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; (annotationView as MKPinAnnotationView).AnimatesDrop = true; if (color == 1) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; } else if (color == 2) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; } else { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Purple; } 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.TouchUpInside += (s, e) => { Console.WriteLine("Clicked"); //Create Alert var detailAlert = UIAlertController.Create("Binduraj Chandrasekaran", "415 516 1334", UIAlertControllerStyle.Alert); detailAlert.AddAction(UIAlertAction.Create("REQUEST HELP", UIAlertActionStyle.Default, (action) => { NexmoDataService nexmo = new NexmoDataService(); nexmo.VoiceCall("19256993334", "12016728509"); })); detailAlert.AddAction(UIAlertAction.Create("CALL", UIAlertActionStyle.Default, (action) => { NexmoDataService nexmo = new NexmoDataService(); nexmo.VoiceCall("19256993334", "12016728509"); })); detailAlert.AddAction(UIAlertAction.Create("SMS", UIAlertActionStyle.Default, (action) => { NexmoDataService nexmo = new NexmoDataService(); nexmo.SMS("19256993334", "12016728509"); })); detailAlert.AddAction(UIAlertAction.Create("CANCEL", UIAlertActionStyle.Cancel, null)); parent.PresentViewController(detailAlert, true, null); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("firstresponder.png")); return(annotationView); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // add the map view var map = new MKMapView(UIScreen.MainScreen.Bounds); View.Add(map); // change the map style map.MapType = MKMapType.Standard; // enable/disable interactions // map.ZoomEnabled = false; // map.ScrollEnabled = false; // show user location if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locationManager.RequestWhenInUseAuthorization(); } map.ShowsUserLocation = true; // TODO: Step 2a - Add a point annotation map.AddAnnotation(new MKPointAnnotation() { Title = "MyAnnotation", Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824) }); // TODO: Step 2b - Customize annotation view via GetViewForAnnotation delegate map.GetViewForAnnotation = delegate(MKMapView mapView, NSObject annotation) { if (annotation is MKUserLocation) { return(null); } MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, pId); // TODO: Step 2e - Move one-time setup to here pinView.PinColor = MKPinAnnotationColor.Green; pinView.CanShowCallout = true; // TODO: Step 2d - Add accessory views to the pin pinView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); pinView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("Icon-29.png")); } return(pinView); }; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; MKPinAnnotationView annotationPinView = null; if (annotation is MKUserLocation) { return(null); } var cAnnotation = annotation as CustomAnnotation; if (annotation is CustomAnnotation) { // show conference annotation annotationView = mapView.DequeueReusableAnnotation(annotationId); if (annotationView == null) { annotationView = new MKAnnotationView(annotation, annotationId); } if (annotationPinView == null) { annotationPinView = new MKPinAnnotationView(annotation, annotationId); } annotationView.CanShowCallout = true; UIImage image = (annotationPinView as MKPinAnnotationView).Image; if (!string.IsNullOrWhiteSpace(((CustomAnnotation)annotation).Icon)) { image = UIImage.FromBundle(((CustomAnnotation)annotation).Icon); annotationView.Image = image; annotationView.CenterOffset = new CGPoint(0, -image.Size.Height / 2); } else { annotationView.Image = image; annotationView.CenterOffset = new CGPoint(9, -image.Size.Height / 3); } var detailButton = UIButton.FromType(UIButtonType.InfoLight); //// detailButton.SetImage(UIImage.FromFile("ic_lesson_hotspot_start.png"), UIControlState.Normal); detailButton.TouchUpInside += (s, e) => { if (cAnnotation.Id != 0) { element.HandleClick(); } }; annotationView.RightCalloutAccessoryView = detailButton; } return(annotationView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { this.annotation = annotation; MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(pId); // Set current location and location of annotation CLLocationCoordinate2D currentLocation = mapView.UserLocation.Coordinate; CLLocationCoordinate2D annotationLocation = annotation.Coordinate; // We don't want a special annotation for the user location if (currentLocation.Latitude == annotationLocation.Latitude && currentLocation.Longitude == annotationLocation.Longitude) { return(null); } if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, pId); } else { annotationView.Annotation = annotation; } annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = false; var sss = annotation.GetTitle(); // Set to true if you want to animate the pin dropping if (annotation.GetTitle().Contains("HOSPITAL") || annotation.GetTitle().Contains("Coordinación")) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; } else if (opcion == 1) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Purple; } else if (opcion == 2) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; } 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); annotationView.RightCalloutAccessoryView = detailButton; // Annotation icon may be specified like this, in case you want it. // annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("example.png")); return(annotationView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is ProfileAnnotation) //profile image { MKAnnotationView imageView = mapView.DequeueReusableAnnotation(iId); if (imageView == null) { imageView = new MKAnnotationView(annotation, iId); } ImageCache im = new ImageCache(context); im.LoadImage(imageView, ((ProfileAnnotation)annotation).UserID.ToString(), ((ProfileAnnotation)annotation).image); //draws border inside, as opposed to Android where it is outside imageView.Layer.BorderColor = UIColor.FromName("PrimaryDark").CGColor; imageView.Layer.BorderWidth = 0.5f; imageView.Frame = new CoreGraphics.CGRect(0, 0, (double)Settings.MapIconSize, (double)Settings.MapIconSize); return(imageView); } else if (annotation is MKPointAnnotation) //list view circle center / profile view position marker { if (context is LocationActivity) { MKAnnotationView imageView = mapView.DequeueReusableAnnotation(iId); if (imageView == null) { imageView = new MKAnnotationView(annotation, iId); } imageView.Image = UIImage.FromBundle("IcMapmarker"); imageView.Frame = new CoreGraphics.CGRect(0, 0, 30, 30); return(imageView); } else { MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, pId); } pinView.PinColor = MKPinAnnotationColor.Red; pinView.CanShowCallout = false; return(pinView); } } else //user location. Class = MapKit.MKAnnotationWrapper, title = My Location { return(null); } }
private MKAnnotationView getAvaiableAnnotationView(string annotationId, MKPinAnnotationColor penColor, NSObject annotation) { var annotationView = mapView.DequeueReusableAnnotation(annotationId) as MKPinAnnotationView; if (annotationView == null) annotationView = new MKPinAnnotationView(annotation, annotationId); annotationView.PinColor = penColor; annotationView.CanShowCallout = true; annotationView.Draggable = true; return annotationView; }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // Set current location and location of annotation CLLocationCoordinate2D currentLocation = mapView.UserLocation.Coordinate; CLLocationCoordinate2D annotationLocation = annotation.Coordinate; // We don't want a special annotation for the user location if (currentLocation.Latitude == annotationLocation.Latitude && currentLocation.Longitude == annotationLocation.Longitude) { return(null); } if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); } else { annotationView.Annotation = annotation; } annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = false; // Set to true if you want to animate the pin dropping if ((annotation as AnnotationModel).isClaimed()) { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; } else { (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; } annotationView.SetSelected(true, false); annotationView.Annotation.GetTitle(); _annotationDetailButton = UIButton.FromType(UIButtonType.DetailDisclosure); _annotationDetailButton.TouchUpInside += (sender, e) => { this.PerformSegue("ShowView", this); }; annotationView.Image = UIImage.FromBundle("images/Icon-Small.png"); annotationView.RightCalloutAccessoryView = _annotationDetailButton; // Annotation icon may be specified like this, in case you want it. annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("images/Icon-Small.png")); return(annotationView); }
MKAnnotationView GetAirportAnnotationView(MKMapView map, NSObject annotation) { MKAnnotationView annotationView = mapView.DequeueReusableAnnotation("annotationViewID"); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, "annotationViewID"); } annotationView.Annotation = (MKAnnotation)annotation; return(annotationView); }
public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return(null); } if (annotation is StepAnnotation) { var annotationView = mapView.DequeueReusableAnnotation("StepAnnotation") as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, "StepAnnotation"); } annotationView.Annotation = annotation; annotationView.PinColor = MKPinAnnotationColor.Green; return(annotationView); } if (annotation is DestinationAnnotation) { var annotationView = mapView.DequeueReusableAnnotation("DesinationAnnotation") as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, "DesinationAnnotation"); } annotationView.Annotation = annotation; annotationView.PinColor = MKPinAnnotationColor.Purple; return(annotationView); } if (annotation is DirectionAnnotation) { DirectionAnnotation directionAnnotation = annotation as DirectionAnnotation; var annotationView = mapView.DequeueReusableAnnotation("DirectionAnnotation") as MKAnnotationView; if (annotationView == null) { annotationView = new MKAnnotationView(annotation, "DirectionAnnotation"); annotationView.Image = UIImage.FromFile("small_blue_icon_navigate.png"); } annotationView.Annotation = annotation; CGAffineTransform transform = CGAffineTransform.MakeRotation((nfloat)directionAnnotation.CurAngle + lastAngle); annotationView.Transform = transform; return(annotationView); } return(null); }
private MKAnnotationView getAvaiableAnnotationView(string annotationId, MKPinAnnotationColor penColor, NSObject annotation) { var annotationView = mapView.DequeueReusableAnnotation(annotationId) as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, annotationId); } annotationView.PinColor = penColor; annotationView.CanShowCallout = true; annotationView.Draggable = true; return(annotationView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKPointAnnotation) { var annotationPoint = (MKPointAnnotation)annotation; // create pin annotation view var pinView = new MKPinAnnotationView(annotation, "myPinId"); _renderer.UpdatePinColor(_renderer._dictionary.Pins.Get(annotationPoint), pinView); pinView.CanShowCallout = true; return(pinView); } return(null); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { Contract.Ensures(Contract.Result <MKAnnotationView>() != null); MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(identifier); //set current location of user and annotation // CLLocationCoordinate2D currentLocation = mapView.UserLocation.Coordinate; CLLocationCoordinate2D annotationLocation = annotation.Coordinate; //no special annotation for user (if using user location on map) // if (currentLocation.Latitude == annotationLocation.Latitude && // currentLocation.Longitude == annotationLocation.Longitude) // return null; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, identifier); } else { annotationView.Annotation = annotation; } annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; annotationView.SetSelected(true, false); UIButton annotationDetailButton = UIButton.FromType(UIButtonType.InfoDark); annotationDetailButton.TouchUpInside += (sender, e) => { var coord = annotation.Coordinate; storage.RemoveAnnotation(coord); mapView.RemoveAnnotation(annotation); }; annotationView.RightCalloutAccessoryView = annotationDetailButton; //if want to change icon on the left, maybe another button later //use left callout accessory view return(annotationView); }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { //Stop annotations if (annotation is StopAnnotation) { StopAnnotation stopAnn = annotation as StopAnnotation; //dequeue or create MKPinAnnotationView pin = mapView.DequeueReusableAnnotation(STOP_PIN_ID) as MKPinAnnotationView; if (pin==null){ pin = new MKPinAnnotationView(stopAnn, STOP_PIN_ID); pin.CanShowCallout=true; } return pin; }//end is stop annotations return null; }
void ColorCentersForDiseaseControlGreen() { map.GetViewForAnnotation = (mapView, annotation) => { if (annotation is MKUserLocation) return null; MKAnnotationView view = null; if (annotation is MKPointAnnotation) { view = mapView.DequeueReusableAnnotation (pinId); if (view == null) { view = new MKPinAnnotationView (annotation, pinId); ((MKPinAnnotationView)view).PinColor = MKPinAnnotationColor.Green; } } return view; }; }
public override void ViewDidLoad () { base.ViewDidLoad (); locationManager = new CLLocationManager () { DistanceFilter = CLLocationDistance.FilterNone, DesiredAccuracy = CLLocation.AccuracyBest }; locationManager.LocationsUpdated += OnLocationsUpdated; map.GetViewForAnnotation = (mapView, annotation) => { var view = new MKPinAnnotationView (annotation, string.Empty) { Draggable = true }; return view; }; locationManager.RequestAlwaysAuthorization (); locationManager.StartUpdatingLocation (); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { // if it's the user location just return if (annotation is MKUserLocation) return null; MKAnnotationView anView; // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); // if we didn't deque reuse if (anView == null) anView = new MKPinAnnotationView(annotation, pId); // set the accessory and pin ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); anView.CanShowCallout = true; // return the view return anView; }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) #endif { MKPinAnnotationView mapPin = null; // https://bugzilla.xamarin.com/show_bug.cgi?id=26416 var userLocationAnnotation = Runtime.GetNSObject(annotation.Handle) as MKUserLocation; if (userLocationAnnotation != null) return null; const string defaultPinId = "defaultPin"; mapPin = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(defaultPinId); if (mapPin == null) { mapPin = new MKPinAnnotationView(annotation, defaultPinId); mapPin.CanShowCallout = true; } mapPin.Annotation = annotation; AttachGestureToPin(mapPin, annotation); return mapPin; }
void AttachGestureToPin (MKPinAnnotationView mapPin, NSObject annotation) #endif { UIGestureRecognizer[] recognizers = mapPin.GestureRecognizers; if (recognizers != null) { foreach (UIGestureRecognizer r in recognizers) { mapPin.RemoveGestureRecognizer(r); } } Action<UITapGestureRecognizer> action = g => OnClick(annotation, g); var recognizer = new UITapGestureRecognizer(action) { ShouldReceiveTouch = (gestureRecognizer, touch) => { _lastTouchedView = touch.View; return true; } }; List.Add(action); List.Add(recognizer); mapPin.AddGestureRecognizer(recognizer); }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) return null; //modifications for MyCustomAnnotations if (annotation is MyCustomAnnotation) { anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (pinID); if(anView == null) anView = new MKPinAnnotationView (annotation,pinID); anView.CanShowCallout = true; anView.Draggable = true; ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure); } //modifications for MKPointAnnotation else { anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (pinGeneric); if(anView == null) anView = new MKPinAnnotationView (annotation,pinGeneric); anView.CanShowCallout = true; ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Green; } return anView; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { MKPinAnnotationView anv = new MKPinAnnotationView(annotation, "thisLocation"); anv.CanShowCallout = true; anv.AnimatesDrop = false; anv.Draggable = true; if(_controller.CurrentLogg.Treff > 0) anv.PinColor = MKPinAnnotationColor.Green; else if(_controller.CurrentLogg.Skudd > 0) anv.PinColor = MKPinAnnotationColor.Red; else anv.PinColor = MKPinAnnotationColor.Purple; return anv; }
void AttachGestureToPin(MKPinAnnotationView mapPin, IMKAnnotation annotation)
// TODO: Step 3c - Review new GetViewForAnnotation method that checks for annotation type before returning a view to use public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) return null; if (annotation is CustomAnnotation) { // show custom annotation anView = mapView.DequeueReusableAnnotation (cId); if (anView == null) anView = new MKAnnotationView (annotation, cId); anView.Image = UIImage.FromFile ("Icon-29.png"); anView.CanShowCallout = true; anView.Draggable = true; anView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure); } else { // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (pId); if (anView == null) anView = new MKPinAnnotationView (annotation, pId); ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Green; anView.CanShowCallout = true; } return anView; }
public override void ViewDidLoad() { base.ViewDidLoad (); View.BackgroundColor = UIColor.White; scrollView = new UIScrollView (View.Bounds) { BackgroundColor = UIColor.Gray }; // Setup mats view marsView = new UIImageView (UIImage.FromBundle ("mars.jpg")){ UserInteractionEnabled = true, }; marsView.AddGestureRecognizer (new UITapGestureRecognizer (()=> { // We'll introduce an artifical delay to feel more like MKMapView for this demonstration. NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, 0, 0, 333), ()=> InvokeOnMainThread (()=> calloutView.DismissCallout (true))); })); scrollView.AddSubview (marsView); scrollView.ContentSize = marsView.Frame.Size; scrollView.ContentOffset = new PointF (150, 50); //Setup top Pin topPin = new MKPinAnnotationView (null, "") { Center = new PointF (View.Frame.Width/2 + 230, View.Frame.Height/2) }; topPin.AddGestureRecognizer (new UITapGestureRecognizer (()=> { // now in this example we're going to introduce an artificial delay in order to make our popup feel identical to MKMapView. // MKMapView has a delay after tapping so that it can intercept a double-tap for zooming. We don't need that delay but we'll // add it just so things feel the same. NSTimer.CreateScheduledTimer (new TimeSpan (0, 0, 0, 0, 333), () => { InvokeOnMainThread (()=> { calloutView.ContentView = null; // clear any custom view that was set by another pin calloutView.BackgroundView = CalloutBackgroundView.SystemBackgroundView; // use the system graphics // This does all the magic. It present the CalloutView calloutView.PresentCallout (topPin.Frame, marsView, scrollView, CalloutArrowDirection.Any, true); // Here's an alternate method that adds the callout *inside* the pin view. This may seem strange, but it's how MKMapView // does it. It brings the selected pin to the front, then pops up the callout inside the pin's view. This way, the callout // is "anchored" to the pin itself. Visually, there's no difference; the callout still looks like it's floating outside the pin. // calloutView.PresentCallout (topPin.Bounds, topPin, scrollView, CalloutArrowDirection.Down, true); }); }); })); marsView.AddSubview (topPin); // Setup disclosure button var topDisclosure = UIButton.FromType (UIButtonType.DetailDisclosure); topDisclosure.AddGestureRecognizer (new UITapGestureRecognizer (()=> { InvokeOnMainThread (()=> new UIAlertView ("Tap!", "You tapped the disclosure button.", null, "Ok", null).Show ()); })); // Now lets stup our calloutView calloutView = new CalloutView () { Title = "Curiosity", Subtitle = "Mars Rover", RightAccessoryView = topDisclosure, CalloutOffset = topPin.CalloutOffset }; View.AddSubview (scrollView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { try { var ca = (ConferenceAnnotation)annotation; var aview = (MKPinAnnotationView)mapView.DequeueReusableAnnotation("pin"); if (aview == null) { aview = new MKPinAnnotationView(ca, "pin"); } else { aview.Annotation = ca; } aview.AnimatesDrop = true; aview.PinColor = MKPinAnnotationColor.Purple; aview.CanShowCallout = true; // UIButton rightCallout = UIButton.FromType(UIButtonType.DetailDisclosure); // rightCallout.Frame = new RectangleF(250,8f,25f,25f); // rightCallout.TouchDown += delegate // { // NSUrl url = new NSUrl("http://maps.google.com/maps?q=" + ca.Coordinate.ToLL() ); // UIApplication.SharedApplication.OpenUrl(url); // }; // aview.RightCalloutAccessoryView = rightCallout; return aview; } catch (Exception) { return null; } }
/// <summary> /// Returns our custom MKAnnotationView /// </summary> public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return null; } else { var annotationView = mapView.DequeueReusableAnnotation (Identifier) as MKPinAnnotationView; if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, Identifier); annotationView.PinColor = MKPinAnnotationColor.Green; annotationView.AnimatesDrop = true; annotationView.CanShowCallout = true; annotationView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure); } else { annotationView.Annotation = annotation; } return annotationView; } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { MKAnnotationView annotationView = null; if (annotation is CCHMapClusterAnnotation) { var mapClusterAnnotation = annotation as CCHMapClusterAnnotation; var pin = mapView.DequeueReusableAnnotation("Pin") as MKPinAnnotationView; if (pin == null) pin = new MKPinAnnotationView(null, "Pin"); pin.Annotation = mapClusterAnnotation; pin.CanShowCallout = true; annotationView = pin; } return annotationView; }
MKAnnotationView GetAirportAnnotationView(MKMapView map, NSObject annotation) { MKAnnotationView annotationView = mapView.DequeueReusableAnnotation ("annotationViewID"); if (annotationView == null) annotationView = new MKPinAnnotationView (annotation, "annotationViewID"); annotationView.Annotation = (MKAnnotation) annotation; return annotationView; }
MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation) { // if it's the user location, just return nil. if (annotation is MKUserLocation) return null; // handle our two custom annotations // if (annotation is BridgeAnnotation) { // for Golden Gate Bridge const string BridgeAnnotationIdentifier = "bridgeAnnotationIdentifier"; MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (BridgeAnnotationIdentifier); if (pinView == null) { MKPinAnnotationView customPinView = new MKPinAnnotationView (annotation, BridgeAnnotationIdentifier); customPinView.PinColor = MKPinAnnotationColor.Purple; customPinView.AnimatesDrop = true; customPinView.CanShowCallout = true; UIButton rightButton = UIButton.FromType (UIButtonType.DetailDisclosure); rightButton.AddTarget ((object sender, EventArgs ea) => showDetails (), UIControlEvent.TouchUpInside); customPinView.RightCalloutAccessoryView = rightButton; pinViews.Add (customPinView); return customPinView; } else { pinView.Annotation = annotation; } return pinView; } else if (annotation is SFAnnotation) { // for City of San Francisco const string SFAnnotationIdentifier = "SFAnnotationIdentifier"; MKAnnotationView pinView = (MKAnnotationView)mapView.DequeueReusableAnnotation (SFAnnotationIdentifier); if (pinView == null) { MKAnnotationView annotationView = new MKAnnotationView (annotation, SFAnnotationIdentifier); annotationView.CanShowCallout = true; UIImage flagImage = UIImage.FromFile ("flag.png"); CGRect resizeRect = CGRect.Empty; resizeRect.Size = flagImage.Size; CGSize maxSize = View.Bounds.Inset (AnnotationPadding, AnnotationPadding).Size; maxSize.Height -= NavigationController.NavigationBar.Frame.Size.Height - CalloutHeight; if (resizeRect.Size.Width > maxSize.Width) resizeRect.Size = new CGSize (maxSize.Width, resizeRect.Size.Height / resizeRect.Size.Width * maxSize.Width); if (resizeRect.Size.Height > maxSize.Height) resizeRect.Size = new CGSize (resizeRect.Size.Width / resizeRect.Size.Height * maxSize.Height, maxSize.Height); resizeRect.Location = CGPoint.Empty; UIGraphics.BeginImageContext (resizeRect.Size); flagImage.Draw (resizeRect); UIImage resizedImage = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); annotationView.Image = resizedImage; annotationView.Opaque = false; UIImageView sfIconView = new UIImageView (UIImage.FromFile ("SFIcon.png")); annotationView.LeftCalloutAccessoryView = sfIconView; pinViews.Add (annotationView); return annotationView; } else { pinView.Annotation = annotation; } return pinView; } return null; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKPinAnnotationView pinView = (MKPinAnnotationView) mapView.DequeueReusableAnnotation( AnnotationID ); if ( pinView == null ) { pinView = new MKPinAnnotationView( annotation, AnnotationID ); pinView.CanShowCallout = true; } // are we rendering the source location? if ( annotation.Coordinate.Latitude == Parent.SourceLocation.Latitude && annotation.Coordinate.Longitude == Parent.SourceLocation.Longitude ) { pinView.PinColor = MKPinAnnotationColor.Green; } else { pinView.PinColor = MKPinAnnotationColor.Red; } return pinView; }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { try { var anv = mapView.DequeueReusableAnnotation("thisLocation"); if (anv == null) { MKPinAnnotationView pinanv = new MKPinAnnotationView(annotation, "thisLocation"); pinanv.CanShowCallout = true; pinanv.Draggable =true; pinanv.AnimatesDrop = true; pinanv.PinColor = MKPinAnnotationColor.Green; anv = pinanv; } else { anv.Annotation = annotation; } return anv; } catch (Exception e) { Console.WriteLine("Failed to get view for annotation " + e); return null; } }
MKAnnotationView CreatePushPin(NinjaAnnotation annotation) { const string reuseIdentifier = "NinjaPushPin"; var view = _mapView.DequeueReusableAnnotation(reuseIdentifier) as MKPinAnnotationView; if (view != null) return view; view = new MKPinAnnotationView(annotation, reuseIdentifier) { PinColor = MKPinAnnotationColor.Purple, AnimatesDrop = true }; view.AddSubview(CreateLabel(annotation)); return view; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { var anv = mapView.DequeueReusableAnnotation("thislocation"); if (anv == null) { var pinanv = new MKPinAnnotationView(annotation, "thislocation"); pinanv.AnimatesDrop = true; pinanv.PinColor = MKPinAnnotationColor.Green; pinanv.CanShowCallout = false; anv = pinanv; } else { anv.Annotation = annotation; } return anv; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { Console.WriteLine("attempt to get view for MKAnnotation " + annotation); try { var anv = mapView.DequeueReusableAnnotation("thislocation"); if (anv == null) { Console.WriteLine("creating new MKAnnotationView"); var pinanv = new MKPinAnnotationView(annotation, "thislocation"); pinanv.AnimatesDrop = true; pinanv.PinColor = MKPinAnnotationColor.Green; pinanv.CanShowCallout = true; anv = pinanv; } else { anv.Annotation = annotation; } return anv; } catch (Exception ex) { Console.WriteLine("GetViewForAnnotation Exception " + ex); return null; } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { if(annotation is MonoTouch.MapKit.MKUserLocation) return null; var a = annotation as MyAnnotation; MKPinAnnotationView anv = new MKPinAnnotationView(annotation, "thisLocation"); anv.CanShowCallout = true; anv.AnimatesDrop = true; if(a.CurrentLogg.Treff > 0) anv.PinColor = MKPinAnnotationColor.Green; else if(a.CurrentLogg.Skudd > 0) anv.PinColor = MKPinAnnotationColor.Red; else anv.PinColor = MKPinAnnotationColor.Purple; return anv; }
/// <summary> /// Get the view for the annotation /// </summary> /// <param name="mapView">The map</param> /// <param name="annotation">The annotation</param> /// <returns>The annotation view</returns> private MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { var customAnnotation = annotation as TKCustomMapAnnotation; if (customAnnotation == null) return null; MKAnnotationView annotationView; if(customAnnotation.CustomPin.Image != null) annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifier); else annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifierDefaultPin); if (annotationView == null) { if(customAnnotation.CustomPin.Image != null) annotationView = new MKAnnotationView(); else annotationView = new MKPinAnnotationView(customAnnotation, AnnotationIdentifier); } else { annotationView.Annotation = customAnnotation; } annotationView.CanShowCallout = customAnnotation.CustomPin.ShowCallout; annotationView.Draggable = customAnnotation.CustomPin.IsDraggable; annotationView.Selected = this._selectedAnnotation != null && customAnnotation.Equals(this._selectedAnnotation); this.SetAnnotationViewVisibility(annotationView, customAnnotation.CustomPin); this.UpdateImage(annotationView, customAnnotation.CustomPin); if (FormsMap.CalloutClickedCommand != null) { var button = new UIButton(UIButtonType.InfoLight); button.Frame = new CGRect(0, 0, 23, 23); button.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; button.VerticalAlignment = UIControlContentVerticalAlignment.Center; annotationView.RightCalloutAccessoryView = button; } return annotationView; }
/// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // 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 MKPinAnnotationView(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; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green; 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.TouchUpInside += (s, e) => { Console.WriteLine ("Clicked"); //Create Alert var detailAlert = UIAlertController.Create ("Annotation Clicked", "You clicked on " + (annotation as MKAnnotation).Coordinate.Latitude.ToString() + ", " + (annotation as MKAnnotation).Coordinate.Longitude.ToString(), UIAlertControllerStyle.Alert); detailAlert.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, null)); parent.PresentViewController (detailAlert, true, null); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("29_icon.png")); return annotationView; }
public void BuildView() { if (mapView == null) { mapView = new MKMapView(); RectangleF frame = new RectangleF(0,0,320,367); mapView.Frame = frame; DV = new DistanceView(); frame = DV.View.Frame; //frame.Y = mapView.Frame.Bottom; frame.Y = -DV.View.Frame.Height; DV.View.Frame = frame; DV.TouchUpInside += delegate(object sender, EventArgs e) { RemoveRouteAnnotation(); HideDistanceView(); }; mapView.RegionWillChange += delegate(object sender, MKMapViewChangeEventArgs e) { if (routeView != null) { routeView.Hidden = true; } }; mapView.RegionChanged += delegate(object sender, MKMapViewChangeEventArgs e) { if (routeView != null) { routeView.Hidden = false; routeView.RegionChanged(); } }; mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) { if (annotation is MKUserLocation) return null; if (annotation is CycleAnnotation) { var mapAnnotation = annotation as CycleAnnotation; if (mapAnnotation == null) return null; MKPinAnnotationView pinView = (MKPinAnnotationView)mapViewForAnnotation.DequeueReusableAnnotation(MapPin); if (pinView == null) { pinView = new MKPinAnnotationView(mapAnnotation, MapPin); } else { pinView.Annotation = annotation; } int valueToCheck = 0; if (CurrentDisplayMode == DisplayMode.Bikes) { valueToCheck = mapAnnotation.Bike.BikesAvailable; } else { valueToCheck = mapAnnotation.Bike.DocksAvailable; } if ((valueToCheck < 5 && valueToCheck != -1)) { if (valueToCheck == 0) { pinView.PinColor = MKPinAnnotationColor.Red; } else { pinView.PinColor = MKPinAnnotationColor.Purple; } } else { pinView.PinColor = MKPinAnnotationColor.Green; } mapAnnotation.PinView = pinView; pinView.CanShowCallout = true; return pinView; } if (annotation is CSRouteAnnotation) { var routeAnnotation = annotation as CSRouteAnnotation; MKAnnotationView annotationView = null; if (annotationView == null) { routeView = new CSRouteView(new RectangleF (0,0, mapView.Frame.Size.Width, mapView.Frame.Size.Height)); routeView.Annotation = routeAnnotation; routeView.MapView = mapViewForAnnotation; annotationView = routeView; } return annotationView; } return null; }; List<MKAnnotation> locations = new List<MKAnnotation>(); double minLon = 200, minLat = 200, maxLon = -200, maxLat = -200; foreach(var bike in BikeLocation.AllBikes) { if (bike.Location.Longitude < minLon) minLon = bike.Location.Longitude; if (bike.Location.Latitude < minLat) minLat = bike.Location.Latitude; if (bike.Location.Longitude < maxLon) maxLon = bike.Location.Longitude; if (bike.Location.Latitude > maxLat) maxLat = bike.Location.Latitude; locations.Add(new CycleAnnotation(bike)); } if (locations.Count > 0) { mapView.AddAnnotation(locations.ToArray()); var tl = new CLLocationCoordinate2D(-90, 180); var br = new CLLocationCoordinate2D(90, -180); foreach(MKAnnotation an in mapView.Annotations) { tl.Longitude = Math.Min(tl.Longitude, an.Coordinate.Longitude); tl.Latitude = Math.Max(tl.Latitude, an.Coordinate.Latitude); br.Longitude = Math.Max(br.Longitude, an.Coordinate.Longitude); br.Latitude = Math.Min(br.Latitude, an.Coordinate.Latitude); } var center = new CLLocationCoordinate2D { Latitude = tl.Latitude - (tl.Latitude - br.Latitude) *0.5, Longitude = tl.Longitude - (tl.Longitude - br.Longitude) *0.5 }; var span = new MKCoordinateSpan { LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) *0.5, LongitudeDelta = Math.Abs(tl.Longitude - br.Longitude) *0.5 }; MKCoordinateRegion region = new MKCoordinateRegion (center, span ); region = mapView.RegionThatFits(region); mapView.SetRegion(region, true); } mapView.ShowsUserLocation = true; View.AddSubview(mapView); } }