Beispiel #1
0
        public virtual MGLAnnotationImage ImageForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            if (annotation is MyCustomPointAnnotation)
            {
                var castAnnotation = (MyCustomPointAnnotation)annotation;
                if (!castAnnotation.WillUseImage)
                {
                    return(null);
                }

                // For better performance, always try to reuse existing annotations.
                var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("camera");

                // If there is no reusable annotation image available, initialize a new one.
                if (annotationImage == null)
                {
                    annotationImage = MGLAnnotationImage.AnnotationImageWithImage(UIImage.FromBundle("camera"), "camera");
                }

                return(annotationImage);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public virtual MGLAnnotationImage ImageForAnnotation(MGLMapView mapView, NSObject annotation)
        {
            // Try to reuse the existing ‘pisa’ annotation image, if it exists.
            var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("pisa");

            if (annotationImage == null)
            {
                // Leaning Tower of Pisa by Stefan Spieler from the Noun Project.
                var image = UIImage.FromBundle("pisavector");

                // The anchor point of an annotation is currently always the center. To
                // shift the anchor point to the bottom of the annotation, the image
                // asset includes transparent bottom padding equal to the original image
                // height.
                //
                // To make this padding non-interactive, we create another image object
                // with a custom alignment rect that excludes the padding.
                image = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(top: 0, left: 0, bottom: image.Size.Height / 2, right: 0));

                // Initialize the ‘pisa’ annotation image with the UIImage we just loaded.
                annotationImage = MGLAnnotationImage.AnnotationImageWithImage(image: image, reuseIdentifier: "pisa");
            }

            return(annotationImage);
        }
        public MGLAnnotationImage MapView_ImageForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var fannotation = Element.Annotations.FirstOrDefault(x => x.NativeHandle == annotation.Handle);

            switch (fannotation)
            {
                case SymbolAnnotation symbol:
                    switch (symbol.IconImage.Source)
                    {
                        case FileImageSource fileImageSource:
                            var cachedImage = mapView.DequeueReusableAnnotationImageWithIdentifier(fileImageSource.File);

                            if (cachedImage != null) return cachedImage;

                            var fileImageSourceHandler = new FileImageSourceHandler();
                            var image = fileImageSourceHandler.LoadImageAsync(fileImageSource).Result;

                            if (image == null) return null;

                            return MGLAnnotationImage.AnnotationImageWithImage(image, fileImageSource.File);
                    }
                    break;
            }

            return null;
        }
        public MGLAnnotationImage MapView_ImageForAnnotation(MGLMapView mapView, IMGLAnnotation annotation)
        {
            var annotationImage = mapView.DequeueReusableAnnotationImageWithIdentifier("temple");

            if (annotationImage == null)
            {
                var image = UIImage.FromBundle("temple");
                image           = image.ImageWithAlignmentRectInsets(new UIEdgeInsets(0, 0, image.Size.Height / 2, 0));
                annotationImage = MGLAnnotationImage.AnnotationImageWithImage(image, "temple");
            }
            return(annotationImage);
        }