public override void DidSelectAnnotationView (MKMapView mapView, MKAnnotationView view) { var customView = view as CustomMKPinAnnotationView; customPinView = new UIView(); if (customView.FormsIdentifier == "Xamarin") { customPinView = new XamarinPinView (); customPinView.Center = new CGPoint (0, - (view.Frame.Height + 15)); view.AddSubview (customPinView); } else if (customView.FormsIdentifier == "Train") { customPinView = new TrainPinView (); customPinView.Center = new CGPoint (0, - (view.Frame.Height + 15)); view.AddSubview (customPinView); } }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { var customView = view as CustomMKPinAnnotationView; customPinView = new UIView(); if (customView.FormsIdentifier == "Xamarin") { customPinView = new XamarinPinView(); customPinView.Center = new CGPoint(0, -(view.Frame.Height + 15)); view.AddSubview(customPinView); } else if (customView.FormsIdentifier == "Train") { customPinView = new TrainPinView(); customPinView.Center = new CGPoint(0, -(view.Frame.Height + 15)); view.AddSubview(customPinView); } }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { if (view.Annotation is UserAnnotation) { venueView = new UIImageView(); venueView.ContentMode = UIViewContentMode.ScaleAspectFit; //venueImage = UIImage.FromFile ("image/venue.png"); // venueView.Image = venueImage; view.AddSubview(venueView); UIView.Animate(0.4, () => { venueView.Frame = new CGRect(-75, -75, 200, 200); }); } }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { // show an image view when the conference annotation view is selected if (view.Annotation is ConferenceAnnotation) { venueView = new UIImageView (); venueView.ContentMode = UIViewContentMode.ScaleAspectFit; venueImage = UIImage.FromFile ("venue.png"); venueView.Image = venueImage; view.AddSubview (venueView); UIView.Animate (0.4, () => { venueView.Frame = new CGRect (-75, -75, 200, 200); }); } }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { // show an image view when the conference annotation view is selected if (view.Annotation is ModeZoneAnnotation) { _venueView = new UIImageView(); _venueView.ContentMode = UIViewContentMode.ScaleAspectFit; _venueImage = UIImage.FromFile("venue.png"); _venueView.Image = _venueImage; view.AddSubview(_venueView); UIView.Animate(0.4, () => { _venueView.Frame = new CGRect(-75, -75, 200, 200); }); } }
private void AddLabelSubView(Marker marker, MKAnnotationView annotationView) { if (annotationView == null || annotationView.Image == null) { return; } UILabel label = new UILabel(); label.TextAlignment = UITextAlignment.Center; label.TextColor = UIColor.Black; label.Font = UIFont.FromName("GillSans-Light", annotationView.Image.Size.Height / 2.0f); label.Text = marker.Label.Text; label.SizeToFit(); label.Frame = new CGRect(-label.Bounds.Width * 0.25, annotationView.Image.Size.Height / 1.5f, label.Bounds.Width, label.Bounds.Height); annotationView.AddSubview(label); }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { // show an image view when the conference annotation view is selected if (view.Annotation is ConferenceAnnotation) { venueView = new UIImageView(); venueView.ContentMode = UIViewContentMode.ScaleAspectFit; venueImage = UIImage.FromBundle("carcash.png"); //venueView.BackgroundColor = UIColor.LightGray; venueView.Image = venueImage; view.AddSubview(venueView); UIView.Animate(0.4, () => { venueView.Frame = new CGRect(-40, -8, 120, 120); }); } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; if (annotation is MKUserLocation) { return(null); } if (annotation is BasicMapAnnotation) { var ann = annotation as BasicMapAnnotation; switch (ann.AnnotationType) { case BasicMapAnnotation.AnnotationTypeEnum.Point: annotationView = mapView.DequeueReusableAnnotation("iconAnnotation"); if (annotationView == null) { annotationView = new MKAnnotationView(annotation, "iconAnnotation"); } else { annotationView.Annotation = annotation; } UIImage icon = null; Console.WriteLine(((BasicMapAnnotation)annotation).Title); switch (((BasicMapAnnotation)annotation).Title) { case "sanitair": icon = UIImage.FromBundle("SharedAssets/Images/Map/sanitair.png"); break; case "centrale bar": icon = UIImage.FromBundle("SharedAssets/Images/Map/bar.png"); break; case "afwasbatterij": icon = UIImage.FromBundle("SharedAssets/Images/Map/afwasbatterij.png"); break; case "infopunt": icon = UIImage.FromBundle("SharedAssets/Images/Map/infopunt.png"); break; case "evacuatiepunt": icon = UIImage.FromBundle("SharedAssets/Images/Map/evacuatiepunt.png"); break; case "eten": icon = UIImage.FromBundle("SharedAssets/Images/Map/eten.png"); break; case "SIS": icon = UIImage.FromBundle("SharedAssets/Images/Map/sis.png"); break; case "EHBO": icon = UIImage.FromBundle("SharedAssets/Images/Map/ehbo.png"); break; default: break; } if (icon != null) { UIGraphics.BeginImageContext(new CGSize(12, 12)); icon.Draw(new CGRect(0, 0, 12, 12)); var resizedIcon = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); annotationView.Image = resizedIcon; } annotationView.CanShowCallout = true; return(annotationView); case BasicMapAnnotation.AnnotationTypeEnum.Region: // show conference annotation annotationView = mapView.DequeueReusableAnnotation("textAnnotation"); if (annotationView == null) { annotationView = new MKAnnotationView(annotation, "textAnnotation"); var label = new UILabel(); label.Tag = 42; label.Font = UIFont.SystemFontOfSize(8); label.ShadowColor = UIColor.Black; label.ShadowOffset = new CGSize(0, 1); label.TextColor = UIColor.White; label.TextAlignment = UITextAlignment.Center; annotationView?.AddSubview(label); annotationView.Frame = label.Frame; } else { annotationView.Annotation = annotation; } var lbl2 = annotationView?.ViewWithTag(42) as UILabel; if (lbl2 != null) { lbl2.Text = ((BasicMapAnnotation)annotation).Title; lbl2.SizeToFit(); } annotationView.Image = null; annotationView.CanShowCallout = false; return(annotationView); case BasicMapAnnotation.AnnotationTypeEnum.Campground: // show conference annotation annotationView = mapView.DequeueReusableAnnotation("textAnnotation"); if (annotationView == null) { annotationView = new MKAnnotationView(annotation, "textAnnotation"); var label = new UILabel() { Tag = 42, Font = UIFont.SystemFontOfSize(8), ShadowColor = UIColor.Black, ShadowOffset = new CGSize(0, 1), TextColor = UIColor.White, TextAlignment = UITextAlignment.Center }; annotationView?.AddSubview(label); annotationView.Frame = label.Frame; } else { annotationView.Annotation = annotation; } var lbl3 = annotationView?.ViewWithTag(42) as UILabel; if (lbl3 != null) { lbl3.Text = ((BasicMapAnnotation)annotation).Title; lbl3.SizeToFit(); } var iconTent = UIImage.FromBundle("SharedAssets/Images/Map/tent.png"); UIGraphics.BeginImageContext(new CGSize(40, 20)); iconTent.Draw(new CGRect(0, 0, 20, 10)); var resizedImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); annotationView.Image = resizedImage; annotationView.CanShowCallout = false; return(annotationView); break; } } return(null); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Create a random set of map locations List<IMKAnnotation> sampleAnnotations = new List<IMKAnnotation>(); Random rnd = new Random(); for (int i = 1; i <= 500; i++) { double lat = 51.7 + rnd.NextDouble(); double lon = 4.3 + rnd.NextDouble(); var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(lat, lon), "Marker " + i); sampleAnnotations.Add(annotation); } // Setup clustering manager FBClusteringManager clusteringManager = new FBClusteringManager(sampleAnnotations); // Setup map region to display initially CLLocationCoordinate2D center = new CLLocationCoordinate2D(52.2, 4.8); MKCoordinateRegion region = MKCoordinateRegion.FromDistance(center, 200000, 200000); MapView.SetRegion(region, false); // As the map moves, use the clusting manager update the clusters displayed on the map MapView.RegionChanged += (object sender, MKMapViewChangeEventArgs e) => { double scale = MapView.Bounds.Size.Width / MapView.VisibleMapRect.Size.Width; List<IMKAnnotation> annotationsToDisplay = clusteringManager.ClusteredAnnotationsWithinMapRect(MapView.VisibleMapRect, scale); clusteringManager.DisplayAnnotations(annotationsToDisplay, MapView); }; // Display a custom icon for the clusters MapView.GetViewForAnnotation += (mapView, annotation) => { MKAnnotationView anView; if (annotation is FBAnnotationCluster) { FBAnnotationCluster annotationcluster = (FBAnnotationCluster)annotation; anView = (MKAnnotationView)mapView.DequeueReusableAnnotation(kClusterAnnotationId); UILabel label = null; if (anView == null) { // nicely format the cluster icon and display the number of items in it anView = new MKAnnotationView(annotation, kClusterAnnotationId); anView.Image = UIImage.FromBundle("cluster"); label = new UILabel(new CGRect(0, 0, anView.Image.Size.Width, anView.Image.Size.Height)); label.Tag = kTagClusterLabel; label.TextAlignment = UITextAlignment.Center; label.TextColor = UIColor.White; anView.AddSubview(label); anView.CanShowCallout = false; } else { label = (UILabel)anView.ViewWithTag(kTagClusterLabel); } label.Text = annotationcluster.Annotations.Count.ToString(); return anView; } return null; }; }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView anView; Int32 annotationType = Convert.ToInt32(annotation is MKUserLocation) * 1 + Convert.ToInt32(annotation is CustomAnnotation) * 2; switch (annotationType) { case 1: { return(null); } case 2: { CustomAnnotation customAnnotation = annotation as CustomAnnotation; anView = new MKAnnotationView(annotation, cId); UILabel DocCountLabel = new UILabel(); DocCountLabel.Frame = new CGRect(-25, -25, 50, 50); DocCountLabel.BackgroundColor = UIColor.Red; DocCountLabel.TextColor = UIColor.White; DocCountLabel.TextAlignment = UITextAlignment.Center; DocCountLabel.Font = UIFont.BoldSystemFontOfSize(25f); if (null == customAnnotation.Annotations) { DocCountLabel.Text = customAnnotation.Count.ToString(); } else { DocCountLabel.Text = customAnnotation.Annotations.Count.ToString(); } DocCountLabel.Layer.MasksToBounds = true; DocCountLabel.Layer.CornerRadius = 8; //DocCountLabel.Alpha = 0.5f; anView.AddSubview(DocCountLabel); anView.CanShowCallout = true; break; } default: { anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (anView == null) { anView = new MKPinAnnotationView(annotation, pId); } ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.CanShowCallout = true; break; } } return(anView); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Create a random set of map locations List <IMKAnnotation> sampleAnnotations = new List <IMKAnnotation>(); Random rnd = new Random(); for (int i = 1; i <= 500; i++) { double lat = 51.7 + rnd.NextDouble(); double lon = 4.3 + rnd.NextDouble(); var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(lat, lon), "Marker " + i); sampleAnnotations.Add(annotation); } // Setup clustering manager FBClusteringManager clusteringManager = new FBClusteringManager(sampleAnnotations); // Setup map region to display initially CLLocationCoordinate2D center = new CLLocationCoordinate2D(52.2, 4.8); MKCoordinateRegion region = MKCoordinateRegion.FromDistance(center, 200000, 200000); MapView.SetRegion(region, false); // As the map moves, use the clusting manager update the clusters displayed on the map MapView.RegionChanged += (object sender, MKMapViewChangeEventArgs e) => { double scale = MapView.Bounds.Size.Width / MapView.VisibleMapRect.Size.Width; List <IMKAnnotation> annotationsToDisplay = clusteringManager.ClusteredAnnotationsWithinMapRect(MapView.VisibleMapRect, scale); clusteringManager.DisplayAnnotations(annotationsToDisplay, MapView); }; // Display a custom icon for the clusters MapView.GetViewForAnnotation += (mapView, annotation) => { MKAnnotationView anView; if (annotation is FBAnnotationCluster) { FBAnnotationCluster annotationcluster = (FBAnnotationCluster)annotation; anView = (MKAnnotationView)mapView.DequeueReusableAnnotation(kClusterAnnotationId); UILabel label = null; if (anView == null) { // nicely format the cluster icon and display the number of items in it anView = new MKAnnotationView(annotation, kClusterAnnotationId); anView.Image = UIImage.FromBundle("cluster"); label = new UILabel(new CGRect(0, 0, anView.Image.Size.Width, anView.Image.Size.Height)); label.Tag = kTagClusterLabel; label.TextAlignment = UITextAlignment.Center; label.TextColor = UIColor.White; anView.AddSubview(label); anView.CanShowCallout = false; } else { label = (UILabel)anView.ViewWithTag(kTagClusterLabel); } label.Text = annotationcluster.Annotations.Count.ToString(); return(anView); } return(null); }; }
/// ------------------------------------------------------------------------------------------------ /// ------------------------------------------------------------------------------------------------ #region MKAnnotationView Method /// ------------------------------------------------------------------------------------------------ /// /// ------------------------------------------------------------------------------------------------ /// Name GetViewForAnnotation /// /// Description Get the view for annotation in map /// ------------------------------------------------------------------------------------------------ /// MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { try { annotationView = new MKAnnotationView(); if (customPins == null) { throw new Exception("Custom pin not found"); } var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude); foreach (var pin in customPins) { if (pin.Pin.Position == position) { annotationView = new CustomMKAnnotationView(annotation, pin.Pin.Label); if (annotation != null) { if (pin.Pin.Address == "Current Location") { annotationView.Image = UIImage.FromFile("locCurrentPin.png"); annotationView.AddSubview(new UILabel(new CGRect(0, 0, 15, 15)) { BackgroundColor = UIColor.Clear, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(15, UIFontWeight.Semibold), TextAlignment = UITextAlignment.Center, Text = pin.Pin.Label }); } else { annotationView.Image = UIImage.FromFile("*****@*****.**"); annotationView.AddSubview(new UILabel(new CGRect(0, 0, annotationView.Image.Size.Width, annotationView.Image.Size.Width)) { BackgroundColor = UIColor.Clear, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(15, UIFontWeight.Semibold), TextAlignment = UITextAlignment.Center, Text = pin.Pin.Label }); } annotationView.CalloutOffset = new CGPoint(0, 0); ((CustomMKAnnotationView)annotationView).Id = pin.Pin.Label; ((CustomMKAnnotationView)annotationView).Url = "url.com"; } annotationView.CanShowCallout = true; } } return(annotationView); } catch (Exception ex) { return(null); } }