Example #1
0
        public MainPage()
        {
            // Check is the instance doesnt already exist.
            if (Current != null)
            {
                //if there is an instance in the app already present then simply throw an error.
                throw new Exception("Only one MainPage can exist in a App.");
            }

            // This is a static public property that allows downstream pages to get a handle to the MainPage instance
            // in order to call methods that are in this class.
            Current = this;

            // Create the LibraryManager
            new LibraryManager();
            LibraryManager.Current.PropertyChanged += LibraryManager_PropertyChanged;

            MapElements.IsSourceGrouped = false;

            this.InitializeComponent();
            (this.Content as FrameworkElement).DataContext = this;
            
            ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
            
            SearchBox.DataContext = LibraryManager.Current;

            /////////////////////////////////////////////////////////// NAVIGATION MANAGER INITIALIZATION ////////////////////////////////
            new NavigationManager(ref SheetsFrame, ref scrollViewer );
            NavigationManager.Current.PropertyChanged += NavigationManager_PropertyChanged;
            
            // Create the SettingsManager
            new SettingsManager(ref MapMain);
            this.RequestedTheme = SettingsManager.Current.AppTheme;
            SettingsManager.Current.PropertyChanged += SettingsManager_PropertyChanged;

            MapInteractionButtons.DataContext = SettingsManager.Current;

            #region TitleBar / StatusBar

            //PC customization
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
            {
                var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                if (titleBar != null)
                {
                    titleBar.BackgroundColor = Color.FromArgb(255, 30, 30, 30);
                    titleBar.ButtonBackgroundColor = titleBar.BackgroundColor;

                    titleBar.InactiveBackgroundColor = Colors.Black;
                    titleBar.ButtonInactiveBackgroundColor = titleBar.InactiveBackgroundColor;

                    titleBar.ForegroundColor = Colors.White;
                    titleBar.InactiveForegroundColor = titleBar.ForegroundColor;
                    titleBar.ButtonForegroundColor = titleBar.ForegroundColor;
                    titleBar.ButtonHoverForegroundColor = titleBar.ForegroundColor;
                    titleBar.ButtonInactiveForegroundColor = titleBar.ForegroundColor;
                    titleBar.ButtonPressedForegroundColor = titleBar.ForegroundColor;

                    titleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 60, 60, 60);
                    titleBar.ButtonPressedBackgroundColor = Color.FromArgb(255,80, 80,80);
                }
            }

            // Handle the StatusBar on Mobile
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                statusBar = StatusBar.GetForCurrentView();

                statusBar.BackgroundColor = Colors.Transparent;
                statusBar.ForegroundColor = Colors.Black;
            }

            #endregion
            
            SearchBox.GotFocus += SearchBox_GotFocus;
            SearchBox.LostFocus += SearchBox_LostFocus;

            // Center the map to the last position.
            MapMain.Center = new Geopoint(new BasicGeoposition() {
                Latitude = SettingsManager.Current.LastMapCenter.X,
                Longitude = SettingsManager.Current.LastMapCenter.Y
            });
            MapMain.ZoomLevel = SettingsManager.Current.LastMapZoom;
            MapMain.Heading = SettingsManager.Current.LastMapHeading;
            MapMain.DesiredPitch = SettingsManager.Current.LastMapPitch;

            MapMain.ZoomInteractionMode = SettingsManager.Current.ShowZoomControl ? MapInteractionMode.GestureAndControl : MapInteractionMode.GestureOnly;
            MapMain.RotateInteractionMode = SettingsManager.Current.ShowRotationControl ? MapInteractionMode.GestureAndControl : MapInteractionMode.GestureOnly;
            MapMain.TiltInteractionMode = SettingsManager.Current.ShowTiltControl ? MapInteractionMode.GestureAndControl : MapInteractionMode.GestureOnly;



            GeolocationPin = new MapGeolocationPin();
            MapMain.Children.Add(GeolocationPin);
            MapControl.SetNormalizedAnchorPoint(GeolocationPin, new Point(0.5, 1));
            MapControl.SetLocation(GeolocationPin, SettingsManager.Current.LastGeoPosition.ToGeopoint());

            AccuracyCircle = new MapPolygon()
            {
                FillColor = Windows.UI.Color.FromArgb(60, 97, 211, 32),
                StrokeColor = Windows.UI.Color.FromArgb(100, 255, 255, 255)
            };

            MapMain.MapElements.Add(AccuracyCircle);

            // Location tracking location and Compass
            StartTracking();


            SetSnapPoints();
        }
        public GeolocationManager(ref MapControl MapMain)
        {
            // Check is the instance doesnt already exist.
            if (Instance != null)
            {
                //if there is an instance in the app already present then simply throw an error.
                throw new Exception("Only one settings manager can exist in a App.");
            }

            // Setting the instance to the static instance field.
            Instance = this;

            this.MapMain = MapMain;

            GeolocationPin = new MapGeolocationPin();
            MapMain.Children.Add(GeolocationPin);
            MapControl.SetNormalizedAnchorPoint(GeolocationPin, new Point(0.5, 1));
            MapControl.SetLocation(GeolocationPin, MapMain.Center);

            AccuracyCircle = new MapPolygon()
            {
                FillColor = Windows.UI.Color.FromArgb(60, 97, 211, 32),
                StrokeColor = Windows.UI.Color.FromArgb(100, 255, 255, 255)
            };

            MapMain.MapElements.Add(AccuracyCircle);

            // Location tracking location and Compass
            StartTracking();
        }