Ejemplo n.º 1
0
        private void NewFoodMarkerOnLoad(object sender, EventArgs e)
        {
            FoodMarker           newMarker         = (FoodMarker)sender;
            AnnotationService    annotationService = new AnnotationService();
            FoodMarkerAnnotation annotation        = annotationService.LoadAnnotations(newMarker);

            _foodMarkerAnnotationDict.Add(newMarker.FoodMarkerId, annotation);
            MapView.AddAnnotation(annotation);
        }
        public MKAnnotationView GetAnnotationView(MKMapView mapView, IMKAnnotation annotation)
        {
            FoodMarkerAnnotation marker = annotation as FoodMarkerAnnotation;

            var view = mapView.DequeueReusableAnnotation(MKMapViewDefault.AnnotationViewReuseIdentifier) as FoodMarkerAnnotationView;

            if (view == null)
            {
                view = new FoodMarkerAnnotationView(marker,
                                                    MKMapViewDefault.AnnotationViewReuseIdentifier);
            }
            view.GenView(marker, _directoryAccess);

            return(view);
        }
        public FoodMarkerAnnotation LoadAnnotations(FoodMarker marker)
        {
            FoodMarkerAnnotation annotation = new FoodMarkerAnnotation(marker);

            annotation.imgFileName = marker.FoodMarkerId.ToString();

            UIImage uiImage;

            if (marker.FoodMarkerPhotos != null &&
                marker.FoodMarkerPhotos.Where(p => p.ImageRank == 1).Any())
            {
                var iconImage = marker.FoodMarkerPhotos.Where(p => p.ImageRank == 1).First();

                using (var url = new NSUrl(iconImage.ImageUrl))
                {
                    using (var data = NSData.FromUrl(url))
                    {
                        if (data != null)
                        {
                            uiImage = UIImage.LoadFromData(data);
                        }
                        else
                        {
                            uiImage = UIImage.FromBundle("DataBox");
                        }
                    }
                }
            }
            else
            {
                uiImage = UIImage.FromBundle("DataBox");
            }

            uiImage = uiImage.Scale(new CGSize(MapSettings.AnnotationSize.Width,
                                               MapSettings.AnnotationSize.Height));

            using (NSData data = uiImage.AsPNG())
            {
                byte[] buffer = new byte[data.Length];
                System.Runtime.InteropServices.Marshal.Copy(data.Bytes, buffer, 0, Convert.ToInt32(data.Length));
                _directoryAccess.UploadFile(buffer, annotation.imgFileName);
            }

            return(annotation);
        }
Ejemplo n.º 4
0
        private async Task AppendToFoodMarkerAnnotations()
        {
            FoodMarkerService foodMarkerService = new FoodMarkerService();

            foodMarkerService.OnFail += OnLogout;


            IEnumerable <FoodMarker> foodMarkers = await foodMarkerService.GetAllFoodMarkerPositions();

            AnnotationService annotationService = new AnnotationService();

            foreach (FoodMarker marker in foodMarkers)
            {
                var imageMetas = await foodMarkerService.GetFoodMarkerPhotos(marker.FoodMarkerId);

                marker.FoodMarkerPhotos = imageMetas;
                FoodMarkerAnnotation annotation = annotationService.LoadAnnotations(marker);
                MapView.AddAnnotation(annotation);
                _foodMarkerAnnotationDict.Add(marker.FoodMarkerId, annotation);
            }
        }