Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var mapView = MapView;

            if (mapView == null)
            {
                return;
            }

            mapView.GetViewForAnnotation = GetViewForAnnotation;

            mapView.Register(typeof(RemarkableTreeView), "marker");
            mapView.Register(typeof(ClusterView), "cluster");

            mapView.AddAnnotations(FromTreesModelsToAnnotationsTrees(_trees));

            var button = MKUserTrackingButton.FromMapView(mapView);

            button.Layer.BackgroundColor = UIColor.FromRGBA(255, 255, 255, 80).CGColor;
            button.Layer.BorderColor     = UIColor.White.CGColor;
            button.Layer.BorderWidth     = 1;
            button.Layer.CornerRadius    = 5;
            button.TranslatesAutoresizingMaskIntoConstraints = false;
            mapView.AddSubview(button);
        }
        private void AddTrackingButton(MKMapView nativeMap)
        {
            MKUserTrackingButton button = MKUserTrackingButton.FromMapView(nativeMap);

            button.Layer.BackgroundColor = UIColor.White.ColorWithAlpha(0.9F).CGColor;
            button.Layer.BorderColor     = UIColor.White.ColorWithAlpha(0.9F).CGColor;
            button.Layer.ShadowColor     = UIColor.Black.CGColor;
            button.Layer.ShadowOpacity   = 0.3F;
            button.Layer.ShadowRadius    = 4;
            button.Layer.BorderWidth     = 1;
            button.Layer.CornerRadius    = 4;
            button.Layer.MasksToBounds   = false;
            button.TranslatesAutoresizingMaskIntoConstraints = false;

            nativeMap.AddSubview(button);
            button.TopAnchor.ConstraintEqualTo(nativeMap.TopAnchor, 58).Active      = true;
            button.RightAnchor.ConstraintEqualTo(nativeMap.RightAnchor, -12).Active = true;
        }
Example #3
0
        private void SetupUserTrackingAndScaleView()
        {
            var button = MKUserTrackingButton.FromMapView(MapView);

            button.Layer.BackgroundColor = UIColor.FromRGBA(255, 255, 255, 80).CGColor;
            button.Layer.BorderColor     = UIColor.White.CGColor;
            button.Layer.BorderWidth     = 1;
            button.Layer.CornerRadius    = 5;
            button.TranslatesAutoresizingMaskIntoConstraints = false;
            View.AddSubview(button);

            var scale = MKScaleView.FromMapView(MapView);

            scale.LegendAlignment = MKScaleViewAlignment.Trailing;
            scale.TranslatesAutoresizingMaskIntoConstraints = false;
            View.AddSubview(scale);

            NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
                button.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -10),
                button.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -10),
                scale.TrailingAnchor.ConstraintEqualTo(button.LeadingAnchor, -10),
                scale.CenterYAnchor.ConstraintEqualTo(button.CenterYAnchor)
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var navController = new UINavigationController();

            navController.NavigationBarHidden = false;

            this.NavigationItem.Title = "MAPA";

            //zobrazeni mapy na obrazovce
            MKMapView mapa = new MKMapView(View.Bounds);

            mapa.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            mapa.ZoomEnabled      = true;
            View.AddSubview(mapa);

            mapa.ShowsScale = true;

            mapa.ShowsPointsOfInterest = true;

            mapa.ShowsCompass = true;

            mapa.ShowsTraffic = true;



            //zobrazeni tlacitka pro polohu uzivatele
            var buttonLokace = MKUserTrackingButton.FromMapView(mapa);

            buttonLokace.Frame = new CGRect(320, 550, 32, 32);
            buttonLokace.Layer.BackgroundColor = UIColor.White.CGColor;
            buttonLokace.Layer.BorderColor     = UIColor.FromRGB(0, 122, 255).CGColor;
            buttonLokace.Layer.BorderWidth     = 1;
            buttonLokace.Layer.CornerRadius    = 5;
            View.AddSubview(buttonLokace);

            //zobrazeni hlasky pro povoleni lokacnich sluzeb a nastaveni lokalizace uzivatele na true
            lokace.RequestWhenInUseAuthorization();

            //zobrazeni uzivatelovy polohy
            mapa.ShowsUserLocation = true;

            //vycentrovani mapy na pozici uzivatele

            /*mapa.DidUpdateUserLocation += (sender, e) =>
             * {
             *  if (mapa.UserLocation != null)
             *  {
             *      CLLocationCoordinate2D souradnice = mapa.UserLocation.Coordinate;
             *      //nastaveni rozsahu zobrazovani mapy
             *      MKCoordinateSpan rozsah = new MKCoordinateSpan(MileNaZemepisnouSirku(0.25), MileNaZemepisnouDelku((0.25), souradnice.Latitude));
             *      mapa.Region = new MKCoordinateRegion(souradnice, rozsah);
             *
             *  }
             * };*/

            //pokud uzivatel nepovoli lokacni sluzby anebo nejsou k dispozici, mapa se vycentruje na Prahu a okoli
            if (!mapa.UserLocationVisible)
            {
                CLLocationCoordinate2D souradnice = new CLLocationCoordinate2D(50.1025011, 14.475905300000022);
                MKCoordinateSpan       rozsah     = new MKCoordinateSpan(MileNaZemepisnouSirku(10), MileNaZemepisnouDelku(10, souradnice.Latitude));
                mapa.Region = new MKCoordinateRegion(souradnice, rozsah);
            }

            //VYHLEDAVANI
            var searchResultsController = new SearchResultsViewController(mapa);
            var searchUpdater           = new SearchResultsUpdator();

            searchUpdater.UpdateSearchResults += searchResultsController.Search;

            searchController = new UISearchController(searchResultsController)
            {
                SearchResultsUpdater = searchUpdater
            };

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle             = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder                = "Vyhledejte váš oblíbený hrad či zámek...";
            searchController.HidesNavigationBarDuringPresentation = false;
            NavigationItem.TitleView   = searchController.SearchBar;
            DefinesPresentationContext = true;

            mapa.GetViewForAnnotation += GetViewForAnnotation;

            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Mělník",
                Coordinate = new CLLocationCoordinate2D(50.3508344, 14.4730828)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Lednice",
                Coordinate = new CLLocationCoordinate2D(48.8016903, 16.8054806)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Kácov",
                Coordinate = new CLLocationCoordinate2D(49.7768931, 15.0282231)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Slavkov",
                Coordinate = new CLLocationCoordinate2D(49.1547997, 16.8745169)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Pernštejn",
                Coordinate = new CLLocationCoordinate2D(49.4509142, 16.3182508)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Žebrák",
                Coordinate = new CLLocationCoordinate2D(49.8868308, 13.8815631)
            }); mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Karlštejn",
                Coordinate = new CLLocationCoordinate2D(49.9391167, 14.1882903)
            }); mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Křivoklát",
                Coordinate = new CLLocationCoordinate2D(50.0378419, 13.8722575)
            });
            mapa.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Houska",
                Coordinate = new CLLocationCoordinate2D(50.4909178, 14.6240339)
            });
            mapa.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Točník",
                Coordinate = new CLLocationCoordinate2D(49.8906097, 13.8872011)
            });
        }
Example #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //If no historyitem is selected
            var mainVM = this.ViewModel as MainViewModel; //To get the item from the ViewModel, Get it via the VM itself, and cast it as that type of VM.

            if (mainVM != null)
            {
                selectedHistoryItem = mainVM.SelectedHistoryItem;
            }

            //If you haven't selected an item,  show the History/... bottom bars + search bar
            if (selectedHistoryItem == null)
            {
                //Bottom Tab bar
                UIBarButtonItem recentHistoryBarButton = new UIBarButtonItem(UIBarButtonSystemItem.Rewind);
                recentHistoryBarButton.Title = "Recent History";
                UIBarButtonItem[] toolbarItems = new UIBarButtonItem[] {
                    recentHistoryBarButton//,
                    //...
                };

                this.SetToolbarItems(toolbarItems, false);
                this.NavigationController.ToolbarHidden = false;

                /////////////
                // BINDING //
                MvxFluentBindingDescriptionSet <MainView, MainViewModel> set = new MvxFluentBindingDescriptionSet <MainView, MainViewModel>(this);
                set.Bind(recentHistoryBarButton).To(vm => vm.SearchHistoryCommand); //show Search History window

                set.Apply();
            }


            ////////////
            // MapKit //
            locationManager.RequestWhenInUseAuthorization(); //Request authorisation to use location when app is in foreground. (Error in versions below 8.0)
            //Type
            MainMap.MapType = MapKit.MKMapType.Standard;
            //Panning and Zooming
            MainMap.ZoomEnabled   = true;
            MainMap.ScrollEnabled = true;
            //User Location
            MainMap.ShowsUserLocation = true;

            // set map center and region
            const double lat       = 50.8247952; //Stationsplein kortrijk
            const double lon       = 3.2643516000000545;
            var          mapCenter = new CLLocationCoordinate2D(lat, lon);
            var          mapRegion = MKCoordinateRegion.FromDistance(mapCenter /*MainMap.UserLocation.Coordinate*/, 2000, 2000);

            //MainMap.CenterCoordinate = mapCenter/*MainMap.UserLocation.Coordinate*/;
            MainMap.Region = mapRegion;


            if (selectedHistoryItem != null)
            {
                CLLocationCoordinate2D coordinate2D = new CLLocationCoordinate2D(double.Parse(selectedHistoryItem.Latitude), double.Parse(selectedHistoryItem.Longitude));
                //Adding an annotation
                MainMap.AddAnnotations(new MKPointAnnotation()
                {
                    Title      = selectedHistoryItem.Name,
                    Coordinate = coordinate2D,
                    Subtitle   = selectedHistoryItem.LatLong
                });
                MainMap.SetCenterCoordinate(coordinate2D, true);
                MainMap.Region = MKCoordinateRegion.FromDistance(coordinate2D, 10000, 10000);
            }


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


            ////////////
            //Local Search UIBar
            if (selectedHistoryItem == null)
            {
                var searchResultsController = new SearchResultsView(MainMap, mainVM); //Also give the Viewmodel, so we can access it for the Messenger/Posting

                var searchUpdater = new SearchResultsUpdater();
                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;
            }

            //Compass
            var compass = MKCompassButton.FromMapView(MainMap);

            compass.CompassVisibility         = MKFeatureVisibility.Visible;
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(compass);
            MainMap.ShowsCompass = false; // so we don't have two compasses!
            // User tracking button
            //Because of using it on a simulator, you can't actually SEE it, but it does work. probably.
            var button = MKUserTrackingButton.FromMapView(MainMap);

            button.Layer.BackgroundColor = UIColor.FromRGBA(255, 255, 255, 80).CGColor;
            button.Layer.BorderColor     = UIColor.White.CGColor;
            button.Layer.BorderWidth     = 1;
            button.Layer.CornerRadius    = 5;
            button.TranslatesAutoresizingMaskIntoConstraints = false;
            View.AddSubview(button);
        }