public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
		{
			var pet = ((CustomAnnotation)annotation).Model;
			var petAnnotationType = GetPetAnnotationType (pet);

			var pin = (MapAnnotationView)mapView.DequeueReusableAnnotation(petAnnotationType);
			string pinImage = petAnnotationType + ".png";
			if (pin == null)
			{
				pin = new MapAnnotationView(annotation, petAnnotationType);
				pin.Image = UIImage.FromBundle(pinImage);
				pin.CenterOffset = new CGPoint (0, -15);
			}
			else
			{
				pin.Annotation = annotation;
			}

			pin.Draggable = _pinIsDraggable;
			pin.CanShowCallout = _canShowCallout;

			if (_canShowCallout) 
			{
				Task.Run( async () => pin.LeftCalloutAccessoryView = await GetImage(pet));
				pin.RightCalloutAccessoryView = GetDetailButton (pet);
			}
			return pin;
		}
Beispiel #2
0
        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;
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        private MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var customAnnotation = annotation as MKAnnotationClass;

            if (customAnnotation == null)
            {
                return(null);
            }

            var annotationView = mapView.DequeueReusableAnnotation(_annotationIdentifierDefaultClusterPin);

            if (annotationView == null)
            {
                annotationView = new MKAnnotationView(customAnnotation, _annotationIdentifierDefaultClusterPin);
            }
            else
            {
                annotationView.Annotation = customAnnotation;
            }
            annotationView.CanShowCallout = true;
            annotationView.Selected       = true;
            annotationView.Draggable      = true;

            return(annotationView);
        }
Beispiel #5
0
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var extendedAnnotation = annotation as ExtendedMapAnnotation;

            if (extendedAnnotation == null)
            {
                return(null);
            }

            // try and dequeue the annotation view
            var annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifier);

            // if we couldn't dequeue one, create a new one
            if (annotationView == null)
            {
                annotationView = new MKAnnotationView(extendedAnnotation, AnnotationIdentifier);
            }
            else // if we did dequeue one for reuse, assign the annotation to it
            {
                annotationView.Annotation = extendedAnnotation;
            }

            // configure our annotation view properties
            annotationView.CanShowCallout = false;
            annotationView.Selected       = true;

            if (!string.IsNullOrEmpty(extendedAnnotation.PinIcon))
            {
                annotationView.Image = UIImage.FromFile(extendedAnnotation.PinIcon);
            }

            return(annotationView);
        }
Beispiel #6
0
        //View do PINO
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            //Exclui se o ponto for a posição do usuário
            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var PinoFoto = ((MapAnnotation)annotation).PinoFoto;


            if (PinoFoto == null)
            {
                throw new Exception("Pino não encontrado");
            }

            MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(PinoFoto.POST.Id.ToString());

            if (annotationView == null)
            {
                annotationView = new CustomMKAnnotationView(annotation, PinoFoto.POST.Id.ToString());
                ((CustomMKAnnotationView)annotationView).POST = PinoFoto.POST;

                annotationView.Image         = UIImage.FromFile("PinoFoto.png");
                annotationView.CenterOffset  = new CGPoint(0, -28.5);
                annotationView.CalloutOffset = new CGPoint(0, 0);
            }
            annotationView.CanShowCallout = false;

            return(annotationView);
        }
        private MKAnnotationView HandleMKMapViewAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            if (annotation is Bike)
            {
                var marker = annotation as Bike;

                var view = mapView.DequeueReusableAnnotation(MKMapViewDefault.AnnotationViewReuseIdentifier) as BikeView;
                if (view == null)
                {
                    view = new BikeView(marker, MKMapViewDefault.AnnotationViewReuseIdentifier);
                }
                return(view);
            }
            else if (annotation is MKClusterAnnotation)
            {
                var cluster = annotation as MKClusterAnnotation;

                var view = mapView.DequeueReusableAnnotation(MKMapViewDefault.ClusterAnnotationViewReuseIdentifier) as ClusterView;
                if (view == null)
                {
                    view = new ClusterView(cluster, MKMapViewDefault.ClusterAnnotationViewReuseIdentifier);
                }
                return(view);
            }
            else if (annotation != null)
            {
                var unwrappedAnnotation = MKAnnotationWrapperExtensions.UnwrapClusterAnnotation(annotation);

                return(HandleMKMapViewAnnotation(mapView, unwrappedAnnotation));
            }
            return(null);
        }
	  public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation)
		{
      var extendedAnnotation = annotation as ExtendedMapAnnotation;

	    if (extendedAnnotation == null) return null;

	    // try and dequeue the annotation view
	    var annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifier);

	    // if we couldn't dequeue one, create a new one
	    if (annotationView == null)
	    {
	      annotationView = new MKAnnotationView(extendedAnnotation, AnnotationIdentifier);
	    }
	    else // if we did dequeue one for reuse, assign the annotation to it
	      annotationView.Annotation = extendedAnnotation;

	    // configure our annotation view properties
	    annotationView.CanShowCallout = false;
	    annotationView.Selected = true;

	    if (!string.IsNullOrEmpty(extendedAnnotation.PinIcon))
	    {
	      annotationView.Image = UIImage.FromFile(extendedAnnotation.PinIcon);
	    }

	    return annotationView;
		}
Beispiel #9
0
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var customPin = GetCustomPin(annotation);

            if (customPin == null)
            {
                return(new CustomMkAnnotationView(annotation, "")
                {
                    Id = "me",
                    Image = UIImage.FromFile("dot")
                });
            }
            var annotationView = mapView.DequeueReusableAnnotation(customPin.Id);

            if (annotationView == null)
            {
                annotationView = new CustomMkAnnotationView(annotation, customPin.Id)
                {
                    Image = UIImage.FromFile("pin")
                };
                ((CustomMkAnnotationView)annotationView).Id = customPin.Id;
            }
            annotationView.CanShowCallout = false;
            return(annotationView);
        }
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var anno      = annotation as MKPointAnnotation;
            var customPin = GetCustomPin(anno);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }

            annotationView = mapView.DequeueReusableAnnotation(customPin.Id);
            if (annotationView == null)
            {
                annotationView = new CustomMKAnnotationView(annotation, customPin.Id)
                {
                    Image         = UIImage.FromFile("NearMe.png"),
                    CalloutOffset = new CGPoint(0, 0),
                    //LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("kiwibuy_logo.png")),
                    RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure)
                };
                ((CustomMKAnnotationView)annotationView).Id  = customPin.Id;
                ((CustomMKAnnotationView)annotationView).Url = customPin.Url;
            }
            annotationView.CanShowCallout = true;
            return(annotationView);
        }
Beispiel #11
0
 public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
 {
     return(mapView.DequeueReusableAnnotation(MapAnnotationId) ?? new MKPinAnnotationView(annotation, MapAnnotationId)
     {
         CanShowCallout = true
     });
 }
		MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
		{
			MKAnnotationView annotationView = null;

			if (annotation is MKUserLocation)
				return null;

			var anno = annotation as MKPointAnnotation;
			var customPin = GetCustomPin(anno);
			if (customPin == null)
			{
				throw new Exception("Custom pin not found");
			}

			annotationView = mapView.DequeueReusableAnnotation(customPin.Id);
			if (annotationView == null)
			{
				annotationView = new CustomMKAnnotationView(annotation, customPin.Id);
				annotationView.Image = UIImage.FromFile("pin.png");
				annotationView.CalloutOffset = new CGPoint(0, 0);
				annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("monkey.png"));
				annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
				((CustomMKAnnotationView)annotationView).Id = customPin.Id;
				((CustomMKAnnotationView)annotationView).Url = customPin.Url;
			}
			annotationView.CanShowCallout = true;

			return annotationView;
		}
Beispiel #13
0
            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 annotationView = null;
			MKPointAnnotation anno = null;

			if (annotation is MKUserLocation) {
				return null; 
			} else {
				anno = annotation as MKPointAnnotation;
			}

			string identifier = GetIdentifier (anno);

			if (identifier == "")
				throw new Exception ("No Identifier found for pin");

			annotationView = mapView.DequeueReusableAnnotation (identifier);

			if (annotationView == null)
				annotationView = new CustomMKPinAnnotationView (annotation, identifier);

			//This removes the bubble that pops up with the title and everything
			((CustomMKPinAnnotationView)annotationView).FormsIdentifier = identifier;
			annotationView.CanShowCallout = false;

			return annotationView;
		}
Beispiel #15
0
        private MKAnnotationView CreateModeZoneAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            // queue for reuse the pin if it's already exist
            var annotationView = mapView.DequeueReusableAnnotation(_idModeZoneAnotation);

            if (annotationView == null)
            {
                // not existing, we create a new one
                annotationView = new MKAnnotationView(annotation, _idModeZoneAnotation);
            }
            // image of the annotation display on the map
            if ((annotation as ModeZoneAnnotation).IsLastAnnotation)
            {
                annotationView.Image = UIImage.FromBundle("MapPinLast");
            }
            else
            {
                annotationView.Image = UIImage.FromBundle("MapPin");
            }
            annotationView.CanShowCallout = true;
            annotationView.Selected       = true;
            annotationView.Draggable      = true;

            return(annotationView);
        }
Beispiel #16
0
 public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
 {
     // we don't handle the annotation for the user
     if (annotation is MKUserLocation)
     {
         return(null);
     }
     // annotation for the mode zone map
     else if (annotation is ModeZoneAnnotation)
     {
         return(CreateModeZoneAnnotation(mapView, annotation));
     }
     // annotation for historic map
     else if (annotation is HistoricAnnotation)
     {
         return(CreateHistoricAnnotation(mapView, annotation));
     }
     // annotation to display the seekios
     else if (annotation is SeekiosAnnotation)
     {
         return(CreateSeekiosAnnotation(mapView, annotation));
     }
     // annotation to display the tracking points
     else if (annotation is TrackingAnnotation)
     {
         return(CreateTrackingAnnotation(mapView, annotation));
     }
     else
     {
         return(null);
     }
 }
			public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation)
			{
				MKAnnotationView anView;

				if (annotation is MKUserLocation)
					return null; 

				if (annotation is MonkeyAnnotation) {

					// show monkey annotation
					anView = mapView.DequeueReusableAnnotation (mId);

					if (anView == null)
						anView = new MKAnnotationView (annotation, mId);
                
					anView.Image = UIImage.FromFile ("monkey.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.Red;
					anView.CanShowCallout = true;
				}

				return anView;
			}
Beispiel #18
0
        private MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var customPin = GetCustomPin(annotation as MKPointAnnotation);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }

            annotationView = mapView.DequeueReusableAnnotation(customPin.Id.ToString());
            if (annotationView == null)
            {
                annotationView = new CustomMKAnnotationView(annotation, customPin.Id.ToString())
                {
                    CalloutOffset = new CGPoint(0, 0),
                    Image         = UIImage.FromFile("pin.png"),
                    Id            = customPin.Id.ToString()
                };
            }
            annotationView.CanShowCallout = true;

            return(annotationView);
        }
Beispiel #19
0
        void OnCalloutClicked(IMKAnnotation annotation)
        {
            // lookup pin
            Pin targetPin = GetPinForAnnotation(annotation);

            // pin not found. Must have been activated outside of forms
            if (targetPin == null)
            {
                return;
            }

            // if the tap happened on the annotation view itself, skip because this is what happens when the callout is showing
            // when the callout is already visible the tap comes in on a different view
            if (_lastTouchedView is MKAnnotationView)
            {
                return;
            }

#pragma warning disable CS0618
            targetPin.SendTap();
#pragma warning restore CS0618

            // SendInfoWindowClick() returns the value of PinClickedEventArgs.HideInfoWindow
            // Hide the info window by deselecting the annotation
            bool deselect = targetPin.SendInfoWindowClick();
            if (deselect)
            {
                ((MKMapView)Control).DeselectAnnotation(annotation, true);
            }
        }
        protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var anno = annotation as MKPointAnnotation;

            if (anno == null)
            {
                return(null);
            }

            var pin = GetPin(anno);

            if (pin == null)
            {
                throw new Exception("pin not found");
            }

            annotationView = mapView.DequeueReusableAnnotation(pin.MarkerId.ToString());
            if (annotationView == null)
            {
                annotationView               = new CustomMKAnnotationView(annotation, pin.MarkerId.ToString());
                annotationView.Image         = UIImage.FromFile("pin.png");
                annotationView.CalloutOffset = new CGPoint(0, 0);
            }
            annotationView.CanShowCallout = true;

            return(annotationView);
        }
        public bool RemoveAnnotation(IMKAnnotation annotation, FBQuadTreeNode fromNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(fromNode.BoundingBox, annotation.Coordinate))
            {
                return(false);
            }

            if (fromNode.Annotations.Contains(annotation))
            {
                fromNode.Annotations.Remove(annotation);
                fromNode.Count--;
                return(true);
            }

            if (RemoveAnnotation(annotation, fromNode.NorthEast))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.NorthWest))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.SouthEast))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.SouthWest))
            {
                return(true);
            }

            return(false);
        }
Beispiel #22
0
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var anno      = annotation as MKPointAnnotation;
            var customPin = GetCustomPin(anno);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }

            // add custom image for map pin
            annotationView = mapView.DequeueReusableAnnotation(customPin.Id);
            if (annotationView == null)
            {
                annotationView       = new MKAnnotationView(annotation, customPin.Id);
                annotationView.Image = UIImage.FromFile(customPin.Url).Scale(new SizeF()
                {
                    Height = 20, Width = 20
                });
            }
            // hide default callout
            annotationView.CanShowCallout = false;
            return(annotationView);
        }
			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;
			}
        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);
        }
Beispiel #25
0
            public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
            {
                MKAnnotationView annotationView = null;

                if (annotation is MKUserLocation)
                {
                    return(null);
                }

                if (annotation is FoodMarkerAnnotation)
                {
                    AnnotationService service = new AnnotationService();
                    annotationView = service.GetAnnotationView(mapView, annotation);
                }
                else if (annotation is MKClusterAnnotation)
                {
                    AnnotationService service = new AnnotationService();
                    annotationView = service.GetClusterAnnotationView(mapView, annotation);
                }
                else if (annotation != null)
                {
                    var unwrappedAnnotation = MKAnnotationWrapperExtensions.UnwrapClusterAnnotation(annotation);

                    return(GetViewForAnnotation(mapView, unwrappedAnnotation));
                }

                return(annotationView);
            }
Beispiel #26
0
        //UIImage venueImage;

        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation mkAnnotation)
        {
            MKAnnotationView annotationView = null;

            if (mkAnnotation is MKUserLocation)
            {
                return(null);
            }

            if (mkAnnotation is UserAnnotation)
            {
                // show conference annotation
                annotationView = mapView.DequeueReusableAnnotation(annotationId);

                if (annotationView == null)
                {
                    annotationView = new MKAnnotationView(mkAnnotation, annotationId);
                }

                // annotationView.Image = UIImage.FromFile ("images/conference.png");
                annotationView.CanShowCallout = true;
                annotationView.Draggable      = true;
            }

            return(annotationView);
        }
Beispiel #27
0
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView    annotationView = null;
            StoreAnnotationView myView         = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }
            //var tmpPoint = _servicePoints?.Where(x => (x.Id == ((StoreAnnotation)annotation).Point.Id)).ToList().FirstOrDefault();// .Coordinate.Latitude) && (x.Lon == annotation.Coordinate.Longitude)).ToList().Fir;
            if (annotation is StoreAnnotation)
            {
                annotation     = annotation as StoreAnnotation;
                annotationView = mapView.DequeueReusableAnnotation(annotationId);
                if (annotationView == null)
                {
                    annotationView = new StoreAnnotationView();
                }
                myView       = StoreAnnotationView.Create();
                myView.Frame = new CGRect(0, 0, 30, 30);
                myView.UpdateView(((StoreAnnotation)annotation).Point);
                myView.Annotation             = annotation;
                annotationView.Annotation     = annotation;
                annotationView                = myView;
                annotationView.ContentMode    = UIViewContentMode.ScaleAspectFit;
                annotationView.CanShowCallout = true;
                var button = new UIButton();
                button.Bounds = new CGRect(0, 0, 22, 22);
                button.SetImage(UIImage.FromBundle("Directions").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);
                button.TintColor = UIColor.FromRGB(239, 60, 57);
                annotationView.RightCalloutAccessoryView = button;                // UIButton.FromType(UIButtonType.InfoDark);
            }
            return(myView);
        }
Beispiel #28
0
        protected void AttachGestureToPin(MKAnnotationView mapPin, IMKAnnotation annotation)
        {
            var recognizers = mapPin.GestureRecognizers;

            if (recognizers != null)
            {
                foreach (var r in recognizers)
                {
                    mapPin.RemoveGestureRecognizer(r);
                }
            }

#if __MOBILE__
            var recognizer = new UITapGestureRecognizer(g => OnCalloutClicked(annotation))
            {
                ShouldReceiveTouch = (gestureRecognizer, touch) =>
                {
                    _lastTouchedView = touch.View;
                    return(true);
                }
            };
#else
            var recognizer = new NSClickGestureRecognizer(g => OnCalloutClicked(annotation));
#endif
            mapPin.AddGestureRecognizer(recognizer);
        }
Beispiel #29
0
        private MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            var anno      = annotation as MKPointAnnotation;
            var customPin = GetCustomPin(anno);

            if (customPin == null)
            {
                return(null);
            }

            annotationView = mapView.DequeueReusableAnnotation("pin");
            if (annotationView == null)
            {
                annotationView = new MKAnnotationView(annotation, "pin");
                ColorPointAnnotation colorPointAnnotation = annotation as ColorPointAnnotation;
                if (colorPointAnnotation != null)
                {
                    annotationView.Image = GetPinImage(colorPointAnnotation.pinColor);
                }
            }
            annotationView.CanShowCallout = true;

            return(annotationView);
        }
Beispiel #30
0
        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);
        }
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            string annotationIdentifier = @"annotationIdentifier";
            var    pinView = mapView.DequeueReusableAnnotation(annotationIdentifier);

            if (pinView == null)
            {
                pinView = new MKAnnotationView(annotation, annotationIdentifier);

                var pointAnn = annotation as MKPointAnnotation;
                if (pointAnn != null)
                {
                    if (pointAnn.Title == "Driver Location")
                    {
                        pinView.Image = UIImage.FromBundle("car.png");
                    }
                    else
                    {
                        pinView.Image = UIImage.FromBundle("pin.png");
                    }
                }
            }
            else
            {
                pinView.Annotation = annotation;
            }

            return(pinView);
        }
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            if (annotation == null)
            {
                return(null);
            }


            var detailButton = UIButton.FromType(UIButtonType.DetailDisclosure);

            detailButton.TouchUpInside += (s, e) =>
            {
                var a = ((AnnotationOverride)annotation).Coordinate;

                if (a.Latitude.Equals(Location.MyCoordonate[0]) && a.Longitude.Equals(Location.MyCoordonate[1]))
                {
                    return;
                }

                LocationHelper.GoogleMap(Location.MyCoordonate, new[] { a.Latitude, a.Longitude });
            };

            var pnn = new MKAnnotationView(annotation, "icon")
            {
                RightCalloutAccessoryView = detailButton,
                CanShowCallout            = true,
                Image = (annotation as AnnotationOverride)?.ImageAnnotation
            };

            _items.Add(annotation);
            return(pnn);
        }
Beispiel #33
0
        private MKAnnotationView CreateHistoricAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            // queue for reuse the pin if it's already exist
            var annotationView = mapView.DequeueReusableAnnotation(_idHistoricAnnotation);

            if (annotationView == null)
            {
                // not existing, we create a new one
                annotationView = new MKAnnotationView(annotation, _idHistoricAnnotation);
            }
            // image of the annotation display on the map
            annotationView.Image          = UIImage.FromBundle("MapPin");
            annotationView.CanShowCallout = true;

            var seekiosLastLocationLabel = new UILabel();

            seekiosLastLocationLabel.LineBreakMode = UILineBreakMode.WordWrap;
            seekiosLastLocationLabel.Lines         = new nint(1);
            seekiosLastLocationLabel.Text          = ((HistoricAnnotation)annotation).Content;
            seekiosLastLocationLabel.Font          = UIFont.FromName("Helvetica", 14f);
            seekiosLastLocationLabel.TextColor     = UIColor.LightGray;
            seekiosLastLocationLabel.SizeToFit();
            seekiosLastLocationLabel.SetNeedsDisplay();

            // add the view in the annotation view
            annotationView.LeftCalloutAccessoryView = seekiosLastLocationLabel;

            return(annotationView);
        }
Beispiel #34
0
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }
            var customPin = GetCustomPin(annotation as MKPointAnnotation);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }
            annotationView = mapView.DequeueReusableAnnotation(customPin.Id.ToString());
            if (annotationView == null)
            {
                annotationView = new CustomMKAnnotationView(annotation, customPin.Id.ToString());
                annotationView.CalloutOffset = new CGPoint(0, 0);
                ((CustomMKAnnotationView)annotationView).Name           = customPin.Name;
                ((CustomMKAnnotationView)annotationView).PinDescription = customPin.Description;
                ((CustomMKAnnotationView)annotationView).Rating         = customPin.Rating;
            }
            return(annotationView);
        }
        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);
        }
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (IsUserLocation(mapView, annotation))
            {
                return(null);
            }

            var customPin = GetCustomPin(annotation);

            if (customPin == null)
            {
                return(null);
            }

            annotationView = mapView.DequeueReusableAnnotation(customPin.Id.ToString());
            if (annotationView == null)
            {
                annotationView               = new CustomMKAnnotationView(annotation, customPin.Id.ToString());
                annotationView.Image         = UIImage.FromFile("iLocationView");
                annotationView.CalloutOffset = new CGPoint(0, 0);
                ((CustomMKAnnotationView)annotationView).Id = customPin.Id.ToString();
            }
            annotationView.CanShowCallout = true;

            return(annotationView);
        }
Beispiel #37
0
        private MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
            {
                return(null);
            }

            var customPin = GetCustomPin(annotation as MKPointAnnotation);

            if (customPin == null)
            {
                throw new Exception("Custom pin not found");
            }

            annotationView = mapView.DequeueReusableAnnotation(customPin.Id.ToString());
            if (annotationView == null)
            {
                annotationView                               = new CustomMKAnnotationView(annotation, customPin.Id.ToString());
                annotationView.Image                         = UIImage.FromFile("pin.png");
                annotationView.CalloutOffset                 = new CGPoint(0, 0);
                annotationView.LeftCalloutAccessoryView      = new UIImageView(UIImage.FromFile("pin.png"));
                annotationView.RightCalloutAccessoryView     = UIButton.FromType(UIButtonType.DetailDisclosure);
                ((CustomMKAnnotationView)annotationView).Id  = customPin.Id.ToString();
                ((CustomMKAnnotationView)annotationView).Url = customPin.Url;
            }
            annotationView.CanShowCallout = true;

            return(annotationView);
        }
		public WeatherAnnotationView (IMKAnnotation annotation, string reuseIdentifier) : base (annotation, reuseIdentifier)
		{
			CGRect frame = Frame;
			frame.Size = new CGSize (60.0f, 85.0f);
			Frame = frame;

			BackgroundColor = UIColor.Clear;
			CenterOffset = new CGPoint (30.0f, 42.0f);
		}
		MKAnnotationView GetWeatherAnnotationView (MKMapView map, IMKAnnotation annotation)
		{
			MKAnnotationView annotationView = mapView.DequeueReusableAnnotation ("annotationViewID");

			if (annotationView == null)
				annotationView = new WeatherAnnotationView (annotation, "annotationViewID");

			annotationView.Annotation = (MKAnnotation) annotation;

			return annotationView;
		}
		public MapKitElement ( string aCaption, IMKAnnotation[] aMKAnnotationObjects, HandleGetViewForAnnotation aHandleGetViewForAnnotation, EventHandler<MKMapViewAccessoryTappedEventArgs> aHandleMapViewCalloutAccessoryControlTapped, EventHandler<MKAnnotationViewEventArgs> aHandleMapViewDidSelectAnnotationView ) : base(aCaption)
		{
			mkAnnotationObjects = aMKAnnotationObjects;
			mkHandleGetViewForAnnotation = aHandleGetViewForAnnotation;
			mkHandleMapViewCalloutAccessoryControlTapped = aHandleMapViewCalloutAccessoryControlTapped;
			mkHandleMapViewDidSelectAnnotationView = aHandleMapViewDidSelectAnnotationView;
			
			MapView = new MKMapView(){				
				BackgroundColor = UIColor.White,				
				AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
			};
		}
 public PulsingAnnotationView(IMKAnnotation annotation, string reuseIndentifier) : base(annotation, reuseIndentifier)
 {
     this.Layer.AnchorPoint = new CGPoint(0.5, 0.5);
     this.CalloutOffset = new CGPoint(0, -8);
     this.Bounds = new CGRect(0, 0, 22, 22);
     this.PulseScaleFactor = 5.3f;
     this.PulseAnimationDuration = 1.5;
     this.OuterPulseAnimationDuration = 3;
     this.DelayBetweenPulseCycles = 0;
     this.AnnotationColor = UIColor.FromRGB(0f, 0.478f, 1f);
     this.OuterColor = UIColor.White;
 }
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            if (Runtime.GetNSObject(annotation.Handle) is MKUserLocation)
            {
                return null;
            }

            var unifiedAnnotation = annotation as IUnifiedAnnotation;
            if (unifiedAnnotation == null)
            {
                return null;
            }

            var pinAnnotation = annotation as UnifiedPointAnnotation;
            if (pinAnnotation != null)
            {
                var data = pinAnnotation.Data;
                MKAnnotationView annotationView = null;

                if (data.Image == null)
                {
                    // Handle standard pins
                    var pinAnnotationView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(MKPinAnnotationIdentifier) ??
                        new MKPinAnnotationView(annotation, MKPinAnnotationIdentifier);

                    pinAnnotationView.PinTintColor = data.Color.ToUIColor();
                    annotationView = pinAnnotationView;
                }
                else {
                    // Handle pins with an image as pin icon
                    annotationView = mapView.DequeueReusableAnnotation(MKAnnotationIdentifier) ??
                        new MKAnnotationView(annotation, MKAnnotationIdentifier);

                    UpdateImage(annotationView, pinAnnotation.Data);
                }

                // Only show the callout if there is something to display
                annotationView.CanShowCallout = string.IsNullOrWhiteSpace(pinAnnotation.Data.Title) == false;

                if (annotationView.CanShowCallout
                    && _renderer.Element.PinCalloutTappedCommand != null
                    && pinAnnotation.Data != null)
                {
                    annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
                }

                annotationView.Annotation = annotation;
                return annotationView;
            }

            return null;
        }
        public bool RemoveAnnotation(IMKAnnotation annotation, FBQuadTreeNode fromNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(fromNode.BoundingBox, annotation.Coordinate)) {
                return false;
            }

            if (fromNode.Annotations.Contains(annotation)) 
            {
                fromNode.Annotations.Remove(annotation);
                fromNode.Count--;
                return true;
            }

            if (RemoveAnnotation(annotation, fromNode.NorthEast)) return true;
            if (RemoveAnnotation(annotation, fromNode.NorthWest)) return true;
            if (RemoveAnnotation(annotation, fromNode.SouthEast)) return true;
            if (RemoveAnnotation(annotation, fromNode.SouthWest)) return true;

            return false;
        }
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
                return null;

            if (annotation is ConferenceAnnotation) {

                // show conference annotation
                annotationView = mapView.DequeueReusableAnnotation (annotationId);

                if (annotationView == null)
                    annotationView = new MKAnnotationView (annotation, annotationId);

                annotationView.Image = UIImage.FromFile ("conference.png");
                annotationView.CanShowCallout = true;
            }

            return annotationView;
        }
        public bool InsertAnnotation(IMKAnnotation annotation, FBQuadTreeNode toNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(toNode.BoundingBox, annotation.Coordinate)) {
                return false;
            }

            if (toNode.Count < FBConsts.kNodeCapacity) {
                toNode.Annotations.Add(annotation);
                toNode.Count++;
                return true;
            }

            if (toNode.IsLeaf()) {
                toNode.Subdivide();
            }

            if (InsertAnnotation(annotation, toNode.NorthEast)) return true;
            if (InsertAnnotation(annotation, toNode.NorthWest)) return true;
            if (InsertAnnotation(annotation, toNode.SouthEast)) return true;
            if (InsertAnnotation(annotation, toNode.SouthWest)) return true;

            return false;
        }
		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;
		}
Beispiel #47
0
            /// <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;
            }
        MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

              if (annotation is MKUserLocation)
            return null;

              var anno = annotation as MKPointAnnotation;
              var customPin = GetCustomPin(anno);
              if (customPin == null)
              {
            throw new Exception("Custom pin not found");
              }

              annotationView = mapView.DequeueReusableAnnotation(customPin.Id);
              if (annotationView == null)
              {
            // RFP:: create the cutom annotation view setting its properties to match the CustomPin on the map
            annotationView = new CustomMKPinAnnotationView(annotation, customPin.Id);
            ((CustomMKPinAnnotationView)annotationView).Id = customPin.Id;
            ((CustomMKPinAnnotationView)annotationView).FirstLine = customPin.FirstLine;
            ((CustomMKPinAnnotationView)annotationView).SecondLine = customPin.SecondLine;
            ((CustomMKPinAnnotationView)annotationView).ThirdLine = customPin.ThirdLine;
            ((CustomMKPinAnnotationView)annotationView).FourthLine = customPin.FourthLine;

            // RFP:: create a new view to be used for annotationView.DetailCalloutAccessoryView
            var newCalloutView = new UIView();
            newCalloutView.TranslatesAutoresizingMaskIntoConstraints = false; // we are using autolayout, not struts

            // RFP:: create and add 3 new UILabels. The normal secondary line on the pin will be replaced by replacing the DetailCalloutAccessoryView, so in total there will be 4 lines
            var label1 = CreateBasicLabel();
            var label2 = CreateBasicLabel();
            var label3 = CreateBasicLabel();
            newCalloutView.Add(label1);
            newCalloutView.Add(label2);
            newCalloutView.Add(label3);

            // RFP:: measure how big a text field is and calculate the height needed for the callout
            label1.Text = "TEMP"; // used to measure height
            var heightOfLabel = label1.GetSizeRequest(double.PositiveInfinity, double.PositiveInfinity).Request.Height;
            var heightOfCallout = (float)(heightOfLabel * 3 + CALLOUT_Y_OFFSET); // the height of the callout is 3 times the height of the label subtracting height used to shift callout view up to be under main text

            // RFP:: setup the constraints for the new callout view
            newCalloutView.AddConstraints(new[]
            {
              NSLayoutConstraint.Create(newCalloutView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, heightOfCallout),
            });

            // RFP:: setup the constraints for each of the new labels
            newCalloutView.AddConstraints(new[]
            {
              NSLayoutConstraint.Create(label1, NSLayoutAttribute.Top, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Top, 1, CALLOUT_Y_OFFSET), // offsetting up X pixels to be right under primary text line (otherwise there is a gap)
              NSLayoutConstraint.Create(label1, NSLayoutAttribute.Left, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Left, 1, 0), // setting label to match parents left edge
              NSLayoutConstraint.Create(label1, NSLayoutAttribute.Right, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Right, 1, 0), // setting label to match parents right edge
            });
            newCalloutView.AddConstraints(new[]
            {
              NSLayoutConstraint.Create(label2, NSLayoutAttribute.Top, NSLayoutRelation.Equal, label1, NSLayoutAttribute.Bottom, 1, 0), // setting top of label to be at bottom of previous label
              NSLayoutConstraint.Create(label2, NSLayoutAttribute.Left, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Left, 1, 0), // setting label to match parents left edge
              NSLayoutConstraint.Create(label2, NSLayoutAttribute.Right, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Right, 1, 0), // setting label to match parents right edge
            });
            newCalloutView.AddConstraints(new[]
            {
              NSLayoutConstraint.Create(label3, NSLayoutAttribute.Top, NSLayoutRelation.Equal, label2, NSLayoutAttribute.Bottom, 1, 0), // setting top of label to be at bottom of previous label
              NSLayoutConstraint.Create(label3, NSLayoutAttribute.Left, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Left, 1, 0), // setting label to match parents left edge
              NSLayoutConstraint.Create(label3, NSLayoutAttribute.Right, NSLayoutRelation.Equal, newCalloutView, NSLayoutAttribute.Right, 1, 0), // setting label to match parents right edge
            });

            // RFP:: replace the DetailCalloutAccessoryView with our new view
            annotationView.DetailCalloutAccessoryView = newCalloutView;
              }

              // RFP:: Get a handle on the fields in the callout to update their text values (both if newly created or reused per DequeueReusableAnnotation)
              var textField1 = annotationView.DetailCalloutAccessoryView.Subviews[0] as UILabel;
              var textField2 = annotationView.DetailCalloutAccessoryView.Subviews[1] as UILabel;
              var textField3 = annotationView.DetailCalloutAccessoryView.Subviews[2] as UILabel;
              textField1.Text = customPin.SecondLine;
              textField2.Text = customPin.ThirdLine;
              textField3.Text = customPin.FourthLine;

              // RFP:: make sure the callout is shown
              annotationView.CanShowCallout = true;

              return annotationView;
        }
        /// <summary>
        /// Sets the selected pin
        /// </summary>
        private void SetSelectedPin()
        {
            var customAnnotion = this._selectedAnnotation as TKCustomMapAnnotation;

            if (customAnnotion != null)
            {
                if (customAnnotion.CustomPin.Equals(this.FormsMap.SelectedPin)) return;

                var annotationView = this.Map.ViewForAnnotation(customAnnotion);
                annotationView.Selected = false;

                this._selectedAnnotation = null;
            }
            if (this.FormsMap.SelectedPin != null)
            {
                var selectedAnnotation = this.Map.Annotations
                    .OfType<TKCustomMapAnnotation>()
                    .SingleOrDefault(i => i.CustomPin.Equals(this.FormsMap.SelectedPin));

                if (selectedAnnotation != null)
                {
                    var annotationView = this.Map.ViewForAnnotation(selectedAnnotation);
                    if (annotationView != null)
                    {
                        annotationView.Selected = true;
                    }
                    this._selectedAnnotation = selectedAnnotation;

                    if (this.FormsMap.PinSelectedCommand != null && this.FormsMap.PinSelectedCommand.CanExecute(null))
                    {
                        this.FormsMap.PinSelectedCommand.Execute(null);
                    }
                }
            }
        }
        /// <summary>
        /// When an annotation view got selected
        /// </summary>
        /// <param name="sender">Event Sender</param>
        /// <param name="e">Event Arguments</param>
        private void OnDidSelectAnnotationView(object sender, MKAnnotationViewEventArgs e)
        {
            var pin = e.View.Annotation as TKCustomMapAnnotation;
            if(pin == null) return;

            this._selectedAnnotation = e.View.Annotation;
            this.FormsMap.SelectedPin = pin.CustomPin;
            
            if (this.FormsMap.PinSelectedCommand != null && this.FormsMap.PinSelectedCommand.CanExecute(pin.CustomPin))
            {
                this.FormsMap.PinSelectedCommand.Execute(pin.CustomPin);
            }
        }
Beispiel #51
0
		void AttachGestureToPin(MKPinAnnotationView mapPin, IMKAnnotation annotation)
		public CustomMKAnnotationView(IMKAnnotation annotation, string id)
			: base(annotation, id)
		{
		}
            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;
            }
        int MapAnnotationToTableRow( IMKAnnotation marker )
        {
            // given a map annotation, we'll go thru each group entry and compare the coordinates
            // to find the matching location.

            for ( int i = 0; i < GroupEntries.Count; i++ )
            {
                // find the row index by matching coordinates
                GroupFinder.GroupEntry currGroup = GroupEntries[ i ];
                CLLocationCoordinate2D currCoord = new CLLocationCoordinate2D( currGroup.Latitude, currGroup.Longitude );

                if ( marker.Coordinate.Latitude == currCoord.Latitude &&
                     marker.Coordinate.Longitude == currCoord.Longitude )
                {
                    return i;
                }
            }

            return -1;
        }
			/// <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;
				}
			}
        /// <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;
        }
 public bool InsertAnnotation(IMKAnnotation annotation)
 {
     return InsertAnnotation(annotation, _rootNode);
 }
Beispiel #58
0
		public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
 public bool RemoveAnnotation(IMKAnnotation annotation)
 {
     return RemoveAnnotation(annotation, _rootNode);
 }
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            MKAnnotationView annotationView = null;

            if (annotation is MKUserLocation)
                return null;

            if (annotation is CarAnnotation)
            {
                annotationView = mapView.DequeueReusableAnnotation(CarAnnotation) ??
                                 new MKAnnotationView(annotation, CarAnnotation);

                if (((CarAnnotation) annotation).Color == UIColor.Blue)
                {
                    annotationView.Image = UIImage.FromBundle(Images.CarAnnotationBlue);
                }
                else
                {
                    annotationView.Image = UIImage.FromBundle(Images.CarAnnotationRed);
                }

                annotationView.CanShowCallout = false;
            }

            if (annotation is PoiAnnotation)
            {
                annotationView = mapView.DequeueReusableAnnotation(POI_ANNOTATION) ??
                                 new MKAnnotationView(annotation, POI_ANNOTATION);

                if (((PoiAnnotation) annotation).Description == "Hard Acceleration")
                {
                    annotationView.Image = UIImage.FromBundle(Images.TipAnnotation);
                }
                else
                {
                    annotationView.Image = UIImage.FromBundle(Images.TipAnnotation);
                }

                annotationView.CanShowCallout = false;
            }

            if (annotation is WaypointAnnotation)
            {
                annotationView = mapView.DequeueReusableAnnotation(WaypointAnnotation) ??
                                 new MKAnnotationView(annotation, WaypointAnnotation);

                if (((WaypointAnnotation) annotation).Waypoint == "A")
                {
                    annotationView.Image = UIImage.FromBundle(Images.WaypointAnnotationA);
                }
                else
                {
                    annotationView.Image = UIImage.FromBundle(Images.WaypointAnnotationB);
                }

                annotationView.CanShowCallout = false;
            }

            return annotationView;
        }