Пример #1
0
            public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation)
            {
                MKAnnotationView annotationView = null;

                if (annotation is CSMapAnnotation)
                {
                    var csAnnotation = (CSMapAnnotation)annotation;
                    if (csAnnotation.AnnotationType == CSMapAnnotationType.Start ||
                        csAnnotation.AnnotationType == CSMapAnnotationType.End)
                    {
                        var identifier          = "pin";
                        MKPinAnnotationView pin = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(identifier);
                        if (pin == null)
                        {
                            pin = new MKPinAnnotationView(csAnnotation, identifier);
                        }
                        pin.PinColor   = (csAnnotation.AnnotationType == CSMapAnnotationType.End) ? MKPinAnnotationColor.Red : MKPinAnnotationColor.Green;
                        annotationView = pin;
                    }
                    else if (csAnnotation.AnnotationType == CSMapAnnotationType.Image)
                    {
                        // TODO:
                    }
                    annotationView.Enabled        = true;
                    annotationView.CanShowCallout = true;
                }
                else if (annotation is CSRouteAnnotation)
                {
                    var routeAnnotation = (CSRouteAnnotation)annotation;

                    if (_viewController.RouteViews.ContainsKey(routeAnnotation.RouteId))
                    {
                        annotationView = _viewController.RouteViews[routeAnnotation.RouteId];
                    }

                    if (annotationView == null)
                    {
                        var routeView = new CSRouteView(new RectangleF(0, 0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                        routeView.Annotation = routeAnnotation;
                        routeView.MapView    = mapView;
                        _viewController.RouteViews.Add(routeAnnotation.RouteId, routeView);
                        annotationView = routeView;
                    }
                }
                return(annotationView);
            }
            public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation)
            {
                MKAnnotationView annotationView = null;

                if (annotation is CSMapAnnotation)
                {
                    var csAnnotation = (CSMapAnnotation)annotation;
                    if (csAnnotation.AnnotationType == CSMapAnnotationType.Start
                    || csAnnotation.AnnotationType == CSMapAnnotationType.End)
                    {
                        var identifier = "pin";
                        MKPinAnnotationView pin = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(identifier);
                        if (pin == null)
                        {
                            pin = new MKPinAnnotationView(csAnnotation, identifier);
                        }
                        pin.PinColor = (csAnnotation.AnnotationType == CSMapAnnotationType.End) ? MKPinAnnotationColor.Red : MKPinAnnotationColor.Green;
                        annotationView = pin;
                    }
                    else if (csAnnotation.AnnotationType == CSMapAnnotationType.Image)
                    {
                        // TODO:
                    }
                    annotationView.Enabled = true;
                    annotationView.CanShowCallout = true;
                }
                else if (annotation is CSRouteAnnotation)
                {
                    var routeAnnotation = (CSRouteAnnotation)annotation;

                    if (_viewController.RouteViews.ContainsKey(routeAnnotation.RouteId))
                        annotationView = _viewController.RouteViews[routeAnnotation.RouteId];

                    if (annotationView == null)
                    {
                        var routeView = new CSRouteView(new RectangleF (0,0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                        routeView.Annotation = routeAnnotation;
                        routeView.MapView = mapView;
                        _viewController.RouteViews.Add(routeAnnotation.RouteId, routeView);
                        annotationView = routeView;
                    }
                }
                return annotationView;
            }