コード例 #1
0
        protected virtual IMKAnnotation CreateAnnotation(Pin pin)
        {
            var mk = new CustomMKAnnotation
            {
                Pin               = pin,
                Title             = pin.Label,
                Subtitle          = pin.Address ?? "",
                CustomMapRenderer = this,
                Coordinate        = new CLLocationCoordinate2D(pin.Position.Latitude, pin.Position.Longitude)
            };

            return(mk);
        }
コード例 #2
0
        protected virtual MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            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 = mapView.DequeueReusableAnnotation(defaultPinId) as MKPinAnnotationView;
            if (mapPin == null)
            {
                mapPin = new MKPinAnnotationView(annotation, defaultPinId);
                mapPin.CanShowCallout = true;
            }

            mapPin.Annotation = annotation;
            AttachGestureToPin(mapPin, annotation);
            if (annotation is CustomMKAnnotation)
            {
                CustomMKAnnotation ann = (CustomMKAnnotation)annotation;

                if (!(ann.Pin is CustomPin))
                {
                    return(mapPin);
                }

                CustomPin cpin = (CustomPin)ann.Pin;
                if (cpin.type == CustomPin.MOVABLE)
                {
                    mapPin.Draggable = true;
                    //mapPin.AccessibilityDragSourceDescriptors.
                    mapPin.Image         = UIImage.FromFile("shape_circle.png");
                    mapPin.CalloutOffset = new CGPoint(0, 0);
                    mapPin.PinColor      = MKPinAnnotationColor.Green;
                }
                else if (cpin.type == CustomPin.HOLE)
                {
                    //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.flag));
                    mapPin.Image         = UIImage.FromFile("flag.png");
                    mapPin.CalloutOffset = new CGPoint(0, 0);
                }
                else if (cpin.type == CustomPin.HOLE)
                {
                }
                else if (cpin.type == CustomPin.USER)
                {
                    mapPin.PinColor = MKPinAnnotationColor.Purple;
                }
                else if (cpin.type == CustomPin.LOCKED)
                {
                    mapPin.PinColor = MKPinAnnotationColor.Purple;
                }
            }


            return(mapPin);
        }