Exemple #1
0
        public MGLAnnotationView ViewForAnnotation(IMGLAnnotation annotation)
        {
            if (annotation is MyCustomPointAnnotation)
            {
                var anno = (MyCustomPointAnnotation)annotation;
                if (!anno.WillUseImage)
                {
                    return(null);
                }
                var reuseIdentifier = "reusableDotView";

                // For better performance, always try to reuse existing annotations.
                var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier(reuseIdentifier);
                if (annotationView == null)
                {
                    annotationView       = new MGLAnnotationView(reuseIdentifier);
                    annotationView.Frame = new CGRect(0, 0, 30, 30);
                    annotationView.Layer.CornerRadius = (annotationView.Frame.Size.Width) / 2;
                    annotationView.Layer.BorderWidth  = (nfloat)4.0;
                    annotationView.Layer.BorderColor  = UIColor.White.CGColor;
                    annotationView.BackgroundColor    = new UIColor((nfloat)0.03, (nfloat)0.80, (nfloat)0.69, (nfloat)1.0);
                }

                return(annotationView);
            }
            else
            {
                return(null);
            }
        }
        public MGLAnnotationView ViewForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            if (annotation is MGLPointAnnotation)
            {
                var anno            = (MGLPointAnnotation)annotation;
                var reuseIdentifier = $"{anno.Coordinate.Longitude}";

                // For better performance, always try to reuse existing annotations.
                var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier(reuseIdentifier);
                if (annotationView == null)
                {
                    annotationView = new CustomAnnotationView(reuseIdentifier);

                    annotationView.Frame = new CGRect(x: 0, y: 0, width: 40, height: 40);

                    // Set the annotation view’s background color to a value determined by its longitude.
                    var hue = anno.Coordinate.Longitude / 100;

                    annotationView.BackgroundColor = UIColor.FromHSB((nfloat)hue, (nfloat)0.5, (nfloat)1);
                }

                return(annotationView);
            }
            else
            {
                return(null);
            }
        }
        public MGLAnnotationView MapView_ViewForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
                case SymbolAnnotation symbol:
                    if (symbol.IconImage?.Source != null)
                    {
                        return null;
                    }
                    break;
            }

            var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier("draggablePoint");
            if (annotationView != null) return annotationView;
            var view = new DraggableAnnotationView(reuseIdentifier: "draggablePoint", size: 24);
            view.DragFinished += (sender, e) =>
            {
                var point = new SymbolAnnotation();
                point.NativeHandle = annotation.Handle;
                point.Coordinates = annotation.Coordinate.ToLatLng();
                Element.DragFinishedCommand?.Execute(point);
            };

            view.AddGestureRecognizer(new UITapGestureRecognizer(tap =>
            {
                Element.DidTapOnMarkerCommand?.Execute(fannotation.Id);
            }));

            //mapView.SelectAnnotation(annotation, true, null);

            return view;
        }
        public MGLAnnotationView MapView_ViewForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
            case SymbolAnnotation symbol:
                if (symbol.IconImage?.Source != null)
                {
                    return(null);
                }
                break;
            }

            var annotationView = mapView.DequeueReusableAnnotationViewWithIdentifier("draggablePoint");

            if (annotationView != null)
            {
                return(annotationView);
            }
            var view = new DraggableAnnotationView(reuseIdentifier: "draggablePoint", size: 24);

            view.DragFinished += (sender, e) =>
            {
                var point = new SymbolAnnotation();
                point.NativeHandle = annotation.Handle;
                point.Coordinates  = annotation.Coordinate.ToLatLng();
                Element.DragFinishedCommand?.Execute(point);
            };

            return(view);
        }