Exemple #1
0
        protected virtual MKCircleRenderer GetViewForCircle(MKCircle mkCircle)
        {
            var    map          = (Map)Element;
            Circle targetCircle = null;

            for (int i = 0; i < map.MapElements.Count; i++)
            {
                var element = map.MapElements[i];
                if (ReferenceEquals(element.MapElementId, mkCircle))
                {
                    targetCircle = (Circle)element;
                    break;
                }
            }

            if (targetCircle == null)
            {
                return(null);
            }

            return(new MKCircleRenderer(mkCircle)
            {
#if __MOBILE__
                StrokeColor = targetCircle.StrokeColor.ToUIColor(Colors.Black),
                FillColor = targetCircle.FillColor.ToUIColor(),
#else
                StrokeColor = targetCircle.StrokeColor.ToNSColor(Colors.Black),
                FillColor = targetCircle.FillColor.ToNSColor(),
#endif
                LineWidth = targetCircle.StrokeWidth
            });
        }
        void didTapSaveButton(UIBarButtonItem sender)
        {
            double     circleDegreeDelta;
            CLLocation pointOnCircle;

            var span = MapView.Region.Span;

            if (span.LatitudeDelta > span.LongitudeDelta)
            {
                circleDegreeDelta = span.LongitudeDelta / MapRegionFraction;
                pointOnCircle     = new CLLocation(MapView.Region.Center.Latitude, MapView.Region.Center.Longitude - circleDegreeDelta);
            }
            else
            {
                circleDegreeDelta = span.LatitudeDelta / MapRegionFraction;
                pointOnCircle     = new CLLocation(MapView.Region.Center.Latitude - circleDegreeDelta, MapView.Region.Center.Longitude);
            }

            var mapCenterLocation = new CLLocation(MapView.Region.Center.Latitude, MapView.Region.Center.Longitude);
            var distance          = pointOnCircle.DistanceFrom(mapCenterLocation);
            var genericRegion     = new CLCircularRegion(MapView.Region.Center, distance, CircularRegion);

            circleOverlay = MKCircle.Circle(genericRegion.Center, genericRegion.Radius);
            var vcDelegate = Delegate;

            if (vcDelegate != null)
            {
                vcDelegate.MapViewDidUpdateRegion(genericRegion);
            }
            DismissViewController(true, null);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			this.Title = "Pyramids of Giza";
			
			// create our location and zoom for the pyramids.
			CLLocationCoordinate2D coords = new CLLocationCoordinate2D(29.976111, 31.132778);
			MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude));

			// set the coords and zoom on the map
			this.mapMain.Region = new MKCoordinateRegion(coords, span);
			
			// show the sat view.
			this.mapMain.MapType = MKMapType.Satellite;
			
			// add an overlay with the coords
			this._circleOverlay = MKCircle.Circle(coords, 200);
			this.mapMain.AddOverlay(this._circleOverlay);
						
			// set our delegate.
			//this.mapMain.Delegate = new MapDelegate();
			
			//-- OR --
			//- override the GetVIewForOverlay directly, in which case we don't need a delegate
			this.mapMain.GetViewForOverlay += (m, o) => {
				if(this._circleView == null)
				{
					this._circleView = new MKCircleView(this._circleOverlay);
					this._circleView.FillColor = UIColor.Blue;
					this._circleView.Alpha = 0.5f;
				}
				return this._circleView;
			};
		}
Exemple #4
0
        void AddMapElements(IEnumerable <MapElement> mapElements)
        {
            foreach (var element in mapElements)
            {
                element.PropertyChanged += MapElementPropertyChanged;

                IMKOverlay overlay = null;
                switch (element)
                {
                case Polyline polyline:
                    overlay = MKPolyline.FromCoordinates(polyline.Geopath
                                                         .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
                                                         .ToArray());
                    break;

                case Polygon polygon:
                    overlay = MKPolygon.FromCoordinates(polygon.Geopath
                                                        .Select(position => new CLLocationCoordinate2D(position.Latitude, position.Longitude))
                                                        .ToArray());
                    break;

                case Circle circle:
                    overlay = MKCircle.Circle(
                        new CLLocationCoordinate2D(circle.Center.Latitude, circle.Center.Longitude),
                        circle.Radius.Meters);
                    break;
                }

                element.MapElementId = overlay;

                ((MKMapView)Control).AddOverlay(overlay);
            }
        }
        public void AddOverlays()
        {
            // sample coordinates
            CLLocationCoordinate2D c1 = new CLLocationCoordinate2D(41.86337816, -72.56874647);
            CLLocationCoordinate2D c2 = new CLLocationCoordinate2D(41.96337816, -72.96874647);
            CLLocationCoordinate2D c3 = new CLLocationCoordinate2D(41.45537816, -72.76874647);
            CLLocationCoordinate2D c4 = new CLLocationCoordinate2D(42.34994, -71.09292);

            // circle
            MKCircle circle = MKCircle.Circle(c1, 10000.0);  // 10000 meter radius

            map.AddOverlay(circle);

            // polygon
            MKPolygon polygon = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] { c1, c2, c3 });

            map.AddOverlay(polygon);

            // triangle
            MKPolyline polyline = MKPolyline.FromCoordinates(new CLLocationCoordinate2D[] { c1, c2, c3 });

            map.AddOverlay(polyline);

            CustomOverlay co = new CustomOverlay(c4);

            map.AddOverlay(co);
        }
        private void showUserMap()
        {
            map.MapType           = MKMapType.HybridFlyover;
            map.ShowsUserLocation = true;
            map.ZoomEnabled       = true;
            map.ScrollEnabled     = true;
            map.ShowsBuildings    = true;
            map.PitchEnabled      = true;
            map.ShowsCompass      = false;
            double lat = 30.2652233534254;
            double lon = -97.73815460962083;
            CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon);
            CLLocationCoordinate2D viewPoint = new CLLocationCoordinate2D(lat + 0.0050, lon - 0.0072);
            MKCoordinateRegion     mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 1500, 1500);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;
            var camera = MKMapCamera.CameraLookingAtCenterCoordinate(mapCenter, viewPoint, 500);

            map.Camera   = camera;
            mapDelegate  = new MapDelegate();
            map.Delegate = mapDelegate;
            askUserPermissions();

            var tapRecogniser     = new UITapGestureRecognizer(this, new Selector("MapTapSelector:"));
            var longTapRecogniser = new UILongPressGestureRecognizer(this, new Selector("MapLongTapSelector:"));

            map.AddGestureRecognizer(tapRecogniser);
            map.AddGestureRecognizer(longTapRecogniser);
            var hotelOverlay = MKCircle.Circle(mapCenter, 1000);

            map.AddOverlay(hotelOverlay);
        }
        public override void ViewDidLoad()
        {
            Console.WriteLine("Map to load");
            base.ViewDidLoad ();

            Title = "MapView";

            //mapView = new MKMapView(View.Bounds);
            this.DDZMapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            //this.DDZMapView.MapType = MKMapType.Standard;	// this is the default
            //this.DDZMapView.MapType = MKMapType.Satellite;
            //this.DDZMapView.MapType = MKMapType.Hybrid;
            View.AddSubview(this.DDZMapView);

            // create our location and zoom
            CLLocationCoordinate2D coords = new CLLocationCoordinate2D(38.9686111, -77.3413889); // Reston
            MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));

            // set the coords and zoom on the map
            this.DDZMapView.Region = new MKCoordinateRegion(coords, span);

            circleOverlay = MKCircle.Circle (coords, 200);
            this.DDZMapView.AddOverlay (circleOverlay);

            this.DDZMapView.GetViewForOverlay = (m, o) => {
                if(circleView == null)
                {
                    circleView = new MKCircleView(o as MKCircle);
                    circleView.FillColor = UIColor.Purple;
                    circleView.Alpha = 0.5f;
                }
                return circleView;
            };
        }
        public void AddOverlay(IMapOverlay item)
        {
            if (item is ICircleOverlay)
            {
                var circle  = (ICircleOverlay)item;
                var overlay = new UnifiedCircleOverlay(MKCircle.Circle(circle.Location.ToCoordinate(), circle.Radius))
                {
                    Data = circle
                };

                _overlays.Add(overlay);
                Control.AddOverlay(overlay);
                return;
            }

            if (item is IPolylineOverlay)
            {
                var polyline    = (IPolylineOverlay)item;
                var coordinates = polyline
                                  .Select(p => new CLLocationCoordinate2D(p.Latitude, p.Longitude))
                                  .ToArray();

                var overlay = new UnifiedPolylineOverlay(MKPolyline.FromCoordinates(coordinates))
                {
                    Data = polyline
                };

                _overlays.Add(overlay);
                Control.AddOverlay(overlay);
                return;
            }
        }
            public override MKOverlayView GetViewForOverlay(MKMapView mapView, NSObject overlay)
            {
                MKOverlayView overlayView = null;

                if (overlay is MKPolygon)
                {
                    MKPolygon polygon     = overlay as MKPolygon;
                    var       polygonView = new MKPolygonView(polygon);
                    polygonView.FillColor = UIColor.Purple;
                    polygonView.Alpha     = 0.7f;
                    overlayView           = polygonView;
                }
                else if (overlay is MKCircle)
                {
                    MKCircle circle     = overlay as MKCircle;
                    var      circleView = new MKCircleView(circle);
                    circleView.FillColor = UIColor.Green;
                    overlayView          = circleView;
                }
                else if (overlay is MKPolyline)
                {
                    MKPolyline polyline     = overlay as MKPolyline;
                    var        polylineView = new MKPolylineView(polyline);
                    polylineView.StrokeColor = UIColor.Black;
                    overlayView = polylineView;
                }
                else if (overlay is CustomOverlay)
                {
                    CustomOverlay co = overlay as CustomOverlay;
                    var           v  = new CustomOverlayView(co);
                    overlayView = v;
                }

                return(overlayView);
            }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locationManager.RequestWhenInUseAuthorization();

            // set map type and show user location
            map.MapType           = MKMapType.Standard;
            map.ShowsUserLocation = true;
            map.Bounds            = View.Bounds;

            // set map center and region
            const double lat       = 42.374260;
            const double lon       = -71.120824;
            var          mapCenter = new CLLocationCoordinate2D(lat, lon);
            var          mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;

            // add an annotation
            map.AddAnnotation(new MKPointAnnotation {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // set the map delegate
            mapDel       = new MyMapDelegate();
            map.Delegate = mapDel;

            // add a custom annotation
            map.AddAnnotation(new MonkeyAnnotation("Xamarin", mapCenter));

            // add an overlay
            var circleOverlay = MKCircle.Circle(mapCenter, 1000);

            map.AddOverlay(circleOverlay);

            var searchResultsController = new SearchResultsViewController(map);


            var searchUpdater = new SearchResultsUpdator();

            searchUpdater.UpdateSearchResults += searchResultsController.Search;

            //add the search controller
            searchController = new UISearchController(searchResultsController)
            {
                SearchResultsUpdater = searchUpdater
            };

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder    = "Enter a search query";

            searchController.HidesNavigationBarDuringPresentation = false;
            NavigationItem.TitleView   = searchController.SearchBar;
            DefinesPresentationContext = true;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locationManager.RequestWhenInUseAuthorization();

            // set map center and region
            const double lat       = 42.374260;
            const double lon       = -71.120824;
            var          mapCenter = new CLLocationCoordinate2D(lat, lon);
            var          mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;

            // add an annotation
            map.AddAnnotation(new MKPointAnnotation
            {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // set the map delegate
            mapViewDelegate = new MapViewDelegate();
            map.Delegate    = mapViewDelegate;

            // add a custom annotation
            map.AddAnnotation(new MonkeyAnnotation("Xamarin", mapCenter));

            // add an overlay
            map.AddOverlay(MKCircle.Circle(mapCenter, 1000));

            // add search
            var searchResultsController = new SearchResultsViewController(map);

            var searchUpdater = new SearchResultsUpdator();

            searchUpdater.UpdateSearchResults += searchResultsController.UpdateSearchResults;

            // add the search controller
            searchController = new UISearchController(searchResultsController);
            searchController.SearchResultsUpdater = searchUpdater;

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder    = "Enter a search query";

            searchController.HidesNavigationBarDuringPresentation = false;
            NavigationItem.TitleView   = searchController.SearchBar;
            DefinesPresentationContext = true;


            //adresse in koordinaten umwandeln
            getCoordinates("Chennai International Airport");
            mapCenter            = newLocation;
            map.CenterCoordinate = mapCenter;

            getAdress();
        }
        void AnnotateAndZoomToRegion(CLCircularRegion region)
        {
            circleOverlay = MKCircle.Circle(region.Center, region.Radius);
            const double multiplier = MapRegionFraction;
            var          mapRegion  = MKCoordinateRegion.FromDistance(region.Center, region.Radius * multiplier, region.Radius * multiplier);

            MapView.SetRegion(mapRegion, false);
        }
Exemple #13
0
        public void Annotations_BackingFields()
        {
            if (MapViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

            using (var a = new MKCircle())                      // MKAnnotation is abstract
#if XAMCORE_2_0
                using (var o1 = new MKPolygon())                // it must export 'coordinate' or this will fail
                    using (var o2 = new MKPolyline())
#else
                using (NSObject o1 = new MKPolygon())           // it must export 'coordinate' or this will fail
                    using (NSObject o2 = new MKPolyline())
#endif
                        using (var mv = new MapViewPoker()) {
                            Assert.Null(mv.AnnotationsBackingField, "1a");
                            Assert.That(mv.Annotations, Is.Empty, "1b");

                            mv.AddAnnotation(a);
                            Assert.AreSame(a, mv.AnnotationsBackingField [0], "2a");
                            Assert.AreSame(a, mv.Annotations [0], "2b");

                            mv.RemoveAnnotation(a);
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "3a");
                            Assert.That(mv.Annotations, Is.Empty, "3b");

#if XAMCORE_2_0
                            mv.AddAnnotation(o1);
#else
                            mv.AddAnnotationObject(o1);
#endif
                            Assert.AreSame(o1, mv.AnnotationsBackingField [0], "4a");
                            Assert.AreSame(o1, mv.Annotations [0], "4b");

                            mv.RemoveAnnotation(o1);
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "5a");
                            Assert.That(mv.Annotations, Is.Empty, "5b");

#if XAMCORE_2_0
                            mv.AddAnnotations(new IMKAnnotation[] { o1, o2 });
#else
                            mv.AddAnnotationObjects(new NSObject[] { o1, o2 });
#endif
                            // don't assume ordering
                            Assert.That(mv.AnnotationsBackingField.Length, Is.EqualTo(2), "6a");
                            Assert.That(mv.Annotations.Length, Is.EqualTo(2), "6b");

#if XAMCORE_2_0
                            mv.RemoveAnnotations(new IMKAnnotation[] { o2, o1 });
#else
                            mv.RemoveAnnotations(new NSObject[] { o2, o1 });
#endif
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "7a");
                            Assert.That(mv.Annotations, Is.Empty, "7b");
                        }
        }
Exemple #14
0
 public void OnChange(object o, PropertyChangedEventArgs ar)
 {
     Device.BeginInvokeOnMainThread(() => {
         var pos       = mapWithRoute.CurrentPosition;
         var cords     = new CLLocationCoordinate2D(pos.Lat, pos.Lon);
         circleOverlay = MKCircle.Circle(cords, 20);
         nativeMap.AddOverlay(circleOverlay);
     });
 }
Exemple #15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Pyramids of Giza";

            mapView = new MKMapView(View.Bounds);
            mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            View.AddSubview(mapView);

            var coords = new CLLocationCoordinate2D(29.976111, 31.132778);             // pyramids of giza, egypt
            var span   = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude));

            // set the coords and zoom on the map
            mapView.MapType = MKMapType.Satellite;
            mapView.Region  = new MKCoordinateRegion(coords, span);

            mapView.OverlayRenderer = (m, o) => {
                if (circleRenderer == null)
                {
                    circleRenderer           = new MKCircleRenderer(o as MKCircle);
                    circleRenderer.FillColor = UIColor.Purple;
                    circleRenderer.Alpha     = 0.5f;
                }
                return(circleRenderer);
            };

            circleOverlay = MKCircle.Circle(coords, 200);
            mapView.AddOverlay(circleOverlay);

            #region Not related to this sample
            int typesWidth = 260, typesHeight = 30, distanceFromBottom = 60;
            mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight));
            mapTypes.InsertSegment("Road", 0, false);
            mapTypes.InsertSegment("Satellite", 1, false);
            mapTypes.InsertSegment("Hybrid", 2, false);
            mapTypes.SelectedSegment  = 1;            // Road is the default
            mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
            mapTypes.ValueChanged    += (s, e) => {
                switch (mapTypes.SelectedSegment)
                {
                case 0:
                    mapView.MapType = MKMapType.Standard;
                    break;

                case 1:
                    mapView.MapType = MKMapType.Satellite;
                    break;

                case 2:
                    mapView.MapType = MKMapType.Hybrid;
                    break;
                }
            };
            View.AddSubview(mapTypes);
            #endregion
        }
Exemple #16
0
        public override void Refresh(ChallengeResponseModel challengeResponse)
        {
            Crashlytics.Instance.Log("ChallengeDetailViewController_Refresh()");
            base.Refresh(challengeResponse);

            if (challengeResponse == null)
            {
                return;
            }

            Challenge             = challengeResponse.Challenge;
            TimeText.Text         = Challenge.NextEventCountDown;
            PointsText.Text       = "+" + Challenge.PointValue.ToString() + " pts";
            ChallengeTextLbl.Text = Challenge.Name;

            var navigationDelegate = new ChallengeDetailWebViewNavigationDelegate();

            navigationDelegate.NavigationFinished += SetupConstraint;
            this.WebView.NavigationDelegate        = navigationDelegate;
            WebView.LoadHtmlString(Challenge.Desc, null);
            ImageService.Instance.LoadUrl(Challenge.Image).Into(ChallengeImage);

            if (!DidSetupMap && Challenge.LocationLat != null && Challenge.LocationLong != null)
            {
                ChallengeImage.Hidden = true;
                vImagePlaceholder.RemoveConstraint(cnImagePlaceholderAspect);
                vImagePlaceholder.AddConstraint(cnImagePlaceholderAspect = NSLayoutConstraint.Create(vImagePlaceholder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 0));

                double radius = Challenge.RadiusMeters ?? 100.0;
                if (radius > 6000000)
                {
                    radius = 6000000;
                }
                double mapRegion = radius * 2.5;

                CLLocationCoordinate2D mapCoordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapViewBase.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, mapRegion, mapRegion), true);

                MKCircle circle = MKCircle.Circle(mapCoordinate, radius);
                MapViewBase.AddOverlay(circle);

                MKPointAnnotation annotation = new MKPointAnnotation();
                annotation.Coordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapViewBase.AddAnnotation(annotation);

                DidSetupMap = true;
            }
            else
            {
                MapViewBase.Hidden = true;
                paddingMap.RemoveConstraint(cnMapPlaceholderAspect);
                paddingMap.AddConstraint(cnMapPlaceholderAspect = NSLayoutConstraint.Create(paddingMap, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 0));
            }

            CheckStatus();
        }
Exemple #17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);

            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }
            map.ShowsUserLocation = true;

            // specify a custom map delegate
            var mapDelegate = new MyMapDelegate();

            map.Delegate = mapDelegate;

            // add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // add a custom annotation
            // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 4a - draw a circle overlay
            var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile

            map.AddOverlay(circleOverlay);

            // TODO: Step 4b - draw a polygon (Wyoming)
            var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(45.00, -111.00),
                new CLLocationCoordinate2D(45, -104),
                new CLLocationCoordinate2D(41, -104),
                new CLLocationCoordinate2D(41, -111)
            });

            map.AddOverlay(stateOverlay);
        }
Exemple #18
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            if (isLoaded)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }

            if (e.NewElement == null)
            {
                return;
            }
            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
            }
            element            = Element as ExtendedMap;
            mapDelegate        = new MapDelegate();
            nativeMap          = Control as MKMapView;
            nativeMap.Delegate = null;
            nativeMap.Delegate = mapDelegate;

            var formsMap = (ExtendedMap)e.NewElement;

            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[element.RouteCoordinates.Count];

            int    index     = 0;
            int    idCounter = 1;
            string icon      = "";

            icon = element.ImageSource;
            foreach (var circle in element.Circles)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                nativeMap.AddOverlay(circleOverlay);
            }

            foreach (var position in element.RouteCoordinates)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(position.Latitude, position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }
            var routeOverlay = MKPolyline.FromCoordinates(coords);

            nativeMap.AddOverlay(routeOverlay);
        }
Exemple #19
0
        /// <summary>
        /// Adds a bubble that reflects the expiry range of a helicopter carrying organ
        /// </summary>
        /// <param name="heliPin"></param>
        private void addOrganRange(CustomPin heliPin)
        {
            //TODO Add proper radius
            var circleOptions = MKCircle.Circle(
                new CoreLocation.CLLocationCoordinate2D(heliPin.Position.Latitude, heliPin.Position.Longitude), 40000);

            nativeMap.AddOverlay(circleOptions);

            highlightedOrganRange = new Tuple <CustomPin, MKCircle>(heliPin, circleOptions);
        }
Exemple #20
0
        public void SelectedAnnotations_BackingFields()
        {
            if (MapViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

#if !MONOMAC
            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0))
            {
                // This test selects annotations on a map view, but according to apple's docs
                // and a lot of googling this will not necessarily work until the map view is
                // show. Since we can't relinquish control of the UI thread, we have no option
                // but ignoring this test. For now I've only seen it fail on iOS 7 DP4.
                Assert.Inconclusive("This test is not deterministic on iOS7 DP4.");
            }
#endif

            using (var a = new MKCircle())                      // MKAnnotation is abstract
#if XAMCORE_2_0
                using (var o1 = new MKPolygon())                // it must export 'coordinate' or this will fail
                    using (var o2 = new MKPolyline())
#else
                using (NSObject o1 = new MKPolygon())           // it must export 'coordinate' or this will fail
                    using (NSObject o2 = new MKPolyline())
#endif
                        using (var mv = new MapViewPoker()) {
                            Assert.Null(mv.SelectedAnnotationsBackingField, "1a");
                            Assert.Null(mv.SelectedAnnotations, "1b");      // not an empty array

                            mv.SelectAnnotation(a, false);
                            Assert.AreSame(a, mv.SelectedAnnotationsBackingField [0], "2a");
                            Assert.AreSame(a, mv.SelectedAnnotations [0], "2b");

                            // sanity
                            Assert.Null(mv.AnnotationsBackingField, "3a");
                            Assert.That(mv.Annotations, Is.Empty, "3b");

#if XAMCORE_2_0
                            mv.SelectedAnnotations = new IMKAnnotation[] { o1, o2 };
#else
                            mv.SelectedAnnotations = new NSObject[] { o1, o2 };
#endif
                            // note: when assigning the property only the first item is selected (by design)
                            // so we're not exactly backing up correctly (we still hold 'o2')
                            // OTOH we do not want to recursively [PostGet] the same property (unless handled by the generator)
                            Assert.That(mv.SelectedAnnotationsBackingField.Length, Is.EqualTo(2), "4a");
                            Assert.That(mv.SelectedAnnotations.Length, Is.EqualTo(1), "4b");

                            mv.DeselectAnnotation(o1, false);
                            // since only 'o1' was really selected, unselecting it will return null
                            Assert.Null(mv.SelectedAnnotationsBackingField, "5a");
                            Assert.Null(mv.SelectedAnnotations, "5b");      // not an empty array
                        }
        }
Exemple #21
0
        public void CtorOverlay()
        {
            TestRuntime.AssertXcodeVersion(5, 0, 1);

            var loc = new CLLocationCoordinate2D(40, 70);

            using (var overlay = MKCircle.Circle(loc, 2000))
                using (var opr = new MKOverlayPathRenderer(overlay)) {
                    Assert.Null(opr.Path, "Path");
                }
        }
Exemple #22
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            Title = "Pyramids of Giza";

            mapView = new MKMapView(View.Bounds);
            mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            View.AddSubview(mapView);

            var coords = new CLLocationCoordinate2D(29.976111, 31.132778); // pyramids of giza, egypt
            var span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude));
            // set the coords and zoom on the map
            mapView.MapType = MKMapType.Satellite;
            mapView.Region = new MKCoordinateRegion(coords, span);

            mapView.OverlayRenderer = (m, o) => {
                if(circleRenderer == null)
                {
                    circleRenderer = new MKCircleRenderer(o as MKCircle);
                    circleRenderer.FillColor = UIColor.Purple;
                    circleRenderer.Alpha = 0.5f;
                }
                return circleRenderer;
            };

            circleOverlay = MKCircle.Circle (coords, 200);
            mapView.AddOverlay (circleOverlay);

            #region Not related to this sample
            int typesWidth=260, typesHeight=30, distanceFromBottom=60;
            mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight));
            mapTypes.InsertSegment("Road", 0, false);
            mapTypes.InsertSegment("Satellite", 1, false);
            mapTypes.InsertSegment("Hybrid", 2, false);
            mapTypes.SelectedSegment = 1; // Road is the default
            mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
            mapTypes.ValueChanged += (s, e) => {
                switch(mapTypes.SelectedSegment) {
                case 0:
                    mapView.MapType = MKMapType.Standard;
                    break;
                case 1:
                    mapView.MapType = MKMapType.Satellite;
                    break;
                case 2:
                    mapView.MapType = MKMapType.Hybrid;
                    break;
                }
            };
            View.AddSubview(mapTypes);
            #endregion
        }
Exemple #23
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                nativeMap.GetViewForAnnotation           = null;
                nativeMap.OverlayRenderer                = null;
                nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       -= OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     -= OnDidDeselectAnnotationView;
            }

            if (e.NewElement != null)
            {
                formsMap  = (LocationMap)e.NewElement;
                nativeMap = Control as MKMapView;

                var circle = formsMap.Circle;
                nativeMap.OverlayRenderer = GetOverlayRenderer;


                if (circle.Position.Latitude != 0.0)
                {
                    _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                    nativeMap.AddOverlay(_circle);
                }

                /* Listen for circle change events */
                MessagingCenter.Subscribe <CustomCircle>(this, "CircleChanged", (obj) =>
                {
                    if (_circle == null)
                    {
                        _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius);
                        nativeMap.AddOverlay(_circle);
                    }
                    else
                    {
                        nativeMap.RemoveOverlay(_circle);
                        _circle.Dispose();
                        _circle = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(obj.Position.Latitude, obj.Position.Longitude), obj.Radius);
                        nativeMap.AddOverlay(_circle);
                    }
                });

                nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       += OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     += OnDidDeselectAnnotationView;
            }
        }
        public void Circle_BackingFields()
        {
            if (CircleViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

            using (var c = new MKCircle())
                using (var cv = new CircleViewPoker(c)) {
                    Assert.AreSame(c, cv.CircleBackingField, "1a");
                    Assert.AreSame(c, cv.Circle, "2a");
                }
        }
Exemple #25
0
        public void Overlay_BackingFields()
        {
            if (OverlayViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

            using (var c = new MKCircle())
                using (var ov = new OverlayViewPoker(c)) {
                    Assert.AreSame(c, ov.Overlay, "1a");
                    Assert.AreSame(c, ov.Overlay, "2a");
                }
        }
        public void CtorOverlay()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(7, 0))
            {
                Assert.Inconclusive("Requires iOS 7.0");
            }

            var loc = new CLLocationCoordinate2D(40, 70);

            using (var overlay = MKCircle.Circle(loc, 2000))
                using (var opr = new MKOverlayPathRenderer(overlay)) {
                    Assert.Null(opr.Path, "Path");
                }
        }
Exemple #27
0
        private void AddOverlays()
        {
            var circle = MKCircle.Circle(AtlantaCoords, 100 * METERS_IN_A_MILE);

            MyMapView.AddOverlay(circle);

            var poly = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(25.25, -80.27),
                new CLLocationCoordinate2D(32.14, -64.97),
                new CLLocationCoordinate2D(18.23, -66.56)
            });

            MyMapView.AddOverlay(poly);
        }
Exemple #28
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locationManager.RequestWhenInUseAuthorization();
            // set map type and show user location
            map.MapType           = MKMapType.Standard;
            map.ShowsUserLocation = true;
            map.Bounds            = View.Bounds;
            // set map center and region
            double lat       = 42.374260;
            double lon       = -71.120824;
            var    mapCenter = new CLLocationCoordinate2D(lat, lon);
            var    mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;

            // add an annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // set the map delegate
            mapDel       = new MyMapDelegate();
            map.Delegate = mapDel;

            // add a custom annotation
            map.AddAnnotation(new MonkeyAnnotation("Xamarin", mapCenter));

            // add an overlay
            var circleOverlay = MKCircle.Circle(mapCenter, 1000);

            map.AddOverlay(circleOverlay);

            // create search controller
            searchBar = new UISearchBar(new CGRect(0, 20, View.Frame.Width, 50))
            {
                Placeholder = "Enter a search query"
            };

            searchController                     = new UISearchDisplayController(searchBar, this);
            searchController.Delegate            = new SearchDelegate(map);
            searchController.SearchResultsSource = new SearchSource(searchController, map);
            View.AddSubview(searchBar);
        }
        protected void OnMapTapped(UIGestureRecognizer sender)
        {
            CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map);

            if (annotationMode)
            {
                var annotation = new MKPointAnnotation(tappedLocationCoord, "User annotation", "");
                annotations.Add(annotation);
                map.AddAnnotation(annotation);
            }
            else
            {
                var overlay = MKCircle.Circle(tappedLocationCoord, 1000);
                map.AddOverlay(overlay);
            }
        }
        public void RefreshOrganCircleOnMap(object o)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                organTimeLeft--;

                if (organTimeLeft <= 0)
                {
                    return;
                }
                else
                {
                    double mapRadius;
                    double distanceTime = organTimeLeft * 70;

                    if (distanceTime > 500000)
                    {
                        mapRadius = 500000;
                    }
                    else
                    {
                        mapRadius = distanceTime;
                    }
                    Position currentPosition = customPin.Position;

                    map.Circle = new CustomCircle
                    {
                        Position = currentPosition,
                        Radius   = mapRadius
                    };
                    var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(map.Circle.Position.Latitude, map.Circle.Position.Longitude), map.Circle.Radius);
                    if (nativeMap.Overlays == null || nativeMap.Overlays.Length == 0)
                    {
                        return;
                    }
                    else
                    {
                        nativeMap.RemoveOverlay(nativeMap.Overlays[0]);

                        customMapRenderer.circleRenderer = null;
                        nativeMap.OverlayRenderer        = customMapRenderer.GetOverlayRenderer;

                        nativeMap.AddOverlay(circleOverlay);
                    }
                }
            });
        }
Exemple #31
0
        public bool CenterInMarker(string seekiosId
                                   , bool showAnnotation = false
                                   , bool withAnimation  = false)
        {
            var idAnnotationAsso = _annotationIdAssociation.FirstOrDefault(id => id.SeekiosId == seekiosId);

            if (idAnnotationAsso == null)
            {
                return(false);
            }
            var seekiosAnnotation = _annotations.FirstOrDefault(annotation => annotation.Id.Equals(idAnnotationAsso.MarkerId));

            if (seekiosAnnotation == null)
            {
                return(false);
            }

            var seekios = App.CurrentUserEnvironment.LsSeekios.FirstOrDefault(f => f.Idseekios.ToString() == seekiosId);

            if (seekios != null)
            {
                if (seekios.LastKnownLocation_accuracy > 0)
                {
                    var centerPostion = new CLLocationCoordinate2D(seekios.LastKnownLocation_latitude
                                                                   , seekios.LastKnownLocation_longitude);
                    var circle = MKCircle.Circle(centerPostion
                                                 , seekios.LastKnownLocation_accuracy);
                    MapViewControl.SetVisibleMapRect(circle.BoundingMapRect, new UIEdgeInsets(50, 20, 100, 20), true);
                }
                else
                {
                    CenterInLocalisation(seekios.LastKnownLocation_latitude
                                         , seekios.LastKnownLocation_longitude
                                         , (float)ZoomLevelEnum.BigZoom
                                         , withAnimation);
                }
            }

            if (showAnnotation)
            {
                SelectedAnnotation = seekiosAnnotation;
                MapViewControl.SelectAnnotation(seekiosAnnotation, withAnimation);
            }

            return(true);
        }
Exemple #32
0
        public void Overlays()
        {
            using (var polygon = new MKPolygon())
                using (var polyline = new MKPolyline())
                    using (var circle = new MKCircle())
                        using (MKMapView mv = new MKMapView()) {
                            // old API accepted NSObject (limited protocol support)
                            mv.AddOverlay(polygon);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(1), "1");
                            mv.RemoveOverlay(polygon);
                            Assert.That(mv.Overlays, Is.Empty, "2");

                            IMKOverlay[] list = { polygon, polyline, circle };
                            mv.AddOverlays(list);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(3), "3");
                            mv.RemoveOverlays(list);
                            Assert.That(mv.Overlays, Is.Empty, "4");
                        }
        }
Exemple #33
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            if (isLoaded)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }
            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = null;
            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                nativeMap = Control as MKMapView;
                isCircle  = formsMap.DrawCircle;
                if (!isCircle)
                {
                    nativeMap.OverlayRenderer = GetOverlayRenderer;

                    CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];

                    int index = 0;
                    foreach (var position in formsMap.RouteCoordinates)
                    {
                        coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                        index++;
                    }

                    var routeOverlay = MKPolyline.FromCoordinates(coords);
                    nativeMap.AddOverlay(routeOverlay);
                }
                if (isCircle)
                {
                    var circle = formsMap.Circle;
                    nativeMap.OverlayRenderer = GetOverlayRenderer;
                    var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                    nativeMap.AddOverlay(circleOverlay);
                }
            }
        }
			public MapDelegate(MKCircle circle, MKCircleView circleView)
			{
				this._circle = circle;
				this._circleView = circleView;
			}
		void AnnotateAndZoomToRegion (CLCircularRegion region)
		{
			circleOverlay = MKCircle.Circle (region.Center, region.Radius);
			const double multiplier = MapRegionFraction;
			var mapRegion = MKCoordinateRegion.FromDistance (region.Center, region.Radius * multiplier, region.Radius * multiplier);
			MapView.SetRegion (mapRegion, false);
		}
		void didTapSaveButton (UIBarButtonItem sender)
		{
			double circleDegreeDelta;
			CLLocation pointOnCircle;

			var span = MapView.Region.Span;
			if (span.LatitudeDelta > span.LongitudeDelta) {
				circleDegreeDelta = span.LongitudeDelta / MapRegionFraction;
				pointOnCircle = new CLLocation (MapView.Region.Center.Latitude, MapView.Region.Center.Longitude - circleDegreeDelta);
			} else {
				circleDegreeDelta = span.LatitudeDelta / MapRegionFraction;
				pointOnCircle = new CLLocation (MapView.Region.Center.Latitude - circleDegreeDelta, MapView.Region.Center.Longitude);
			}

			var mapCenterLocation = new CLLocation (MapView.Region.Center.Latitude, MapView.Region.Center.Longitude);
			var distance = pointOnCircle.DistanceFrom (mapCenterLocation);
			var genericRegion = new CLCircularRegion (MapView.Region.Center, distance, CircularRegion);

			circleOverlay = MKCircle.Circle (genericRegion.Center, genericRegion.Radius);
			var vcDelegate = Delegate;
			if (vcDelegate != null)
				vcDelegate.MapViewDidUpdateRegion (genericRegion);
			DismissViewController (true, null);
		}
 public UnifiedCircleOverlay(MKCircle circle)
     : base(circle.Handle)
 {
 }