protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            // Hide PokeMenu panel just in case
            HidePokeMenuStoryboard.Begin();
            // See if we need to update the map
            if ((e.Parameter != null) && (e.NavigationMode != NavigationMode.Back))
            {
                GameMapNavigationModes mode =
                    ((JObject)JsonConvert.DeserializeObject((string)e.Parameter)).Last
                    .ToObject <GameMapNavigationModes>();
                if ((mode == GameMapNavigationModes.AppStart) || (mode == GameMapNavigationModes.SettingsUpdate))
                {
                    SetupMap();
                }
            }
            // Set first position if we shomehow missed it
            UpdateMap();
            await GameMapControl.TryRotateToAsync(SettingsService.Instance.MapHeading);

            await GameMapControl.TryTiltToAsync(SettingsService.Instance.MapPitch);

            SubscribeToCaptureEvents();
            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
        private async Task UpdateMap()
        {
            if (LocationServiceHelper.Instance.Geoposition != null)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        // Set player icon's position
                        MapControl.SetLocation(PlayerImage, LocationServiceHelper.Instance.Geoposition.Coordinate.Point);

                        // Update angle and center only if map is not being manipulated
                        if (lastAutoPosition == null)
                        {
                            //Reset of position or first run
                            //Save Center
                            lastAutoPosition = GameMapControl.Center;
                            //Reset orientation to default
                            if (double.IsNaN(GameMapControl.Heading))//DarkAngel: I love non nullable double that can be "!= null and not a number"...
                            {
                                await GameMapControl.TryRotateToAsync(0);
                            }
                        }

                        //Small Trick: I'm not testing lastAutoPosition == GameMapControl.Center because MapControl is not taking exact location when setting center!!
                        string currentCoord =
                            $"{GameMapControl.Center.Position.Latitude: 000.0000} ; {GameMapControl.Center.Position.Longitude: 000.0000}";
                        string previousCoord =
                            $"{lastAutoPosition.Position.Latitude: 000.0000} ; {lastAutoPosition.Position.Longitude: 000.0000}";
                        if (currentCoord == previousCoord && ReactivateMapAutoUpdateButton != null)
                        {
                            //Previous position was set automatically, continue!
                            ReactivateMapAutoUpdateButton.Visibility = Visibility.Collapsed;
                            GameMapControl.Center = LocationServiceHelper.Instance.Geoposition.Coordinate.Point;

                            lastAutoPosition = GameMapControl.Center;

                            if ((SettingsService.Instance.MapAutomaticOrientationMode == MapAutomaticOrientationModes.GPS) &&
                                (
                                    LocationServiceHelper.Instance.Geoposition.Coordinate.Heading.GetValueOrDefault(-1) >= 0 &&
                                    LocationServiceHelper.Instance.Geoposition.Coordinate.Heading.GetValueOrDefault(-1) <= 360
                                ))
                            {
                                await GameMapControl.TryRotateToAsync(LocationServiceHelper.Instance.Geoposition.Coordinate.Heading.GetValueOrDefault(GameMapControl.Heading));
                            }
                            if (SettingsService.Instance.IsRememberMapZoomEnabled)
                            {
                                GameMapControl.ZoomLevel = SettingsService.Instance.Zoomlevel;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        await ExceptionHandler.HandleException(ex);
                    }
                });
            }
        }
Exemple #3
0
        private async void UpdateMap()
        {
            if (LocationServiceHelper.Instance.Geoposition != null)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    // Set player icon's position
                    MapControl.SetLocation(PlayerImage, LocationServiceHelper.Instance.Geoposition.Coordinate.Point);

                    // Update angle and center only if map is not being manipulated
                    if (lastAutoPosition == null)
                    {
                        //Reset of position or first run
                        //Save Center
                        lastAutoPosition = GameMapControl.Center;
                        //Reset orientation to default
                        if (GameMapControl.Heading == LocationServiceHelper.Instance.Geoposition.Coordinate.Heading)
                        {
                            GameMapControl.Heading = 0;
                        }
                    }

                    //Small Trick: I'm not testing lastAutoPosition == GameMapControl.Center because MapControl is not taking exact location when setting center!!
                    string currentCoord =
                        $"{GameMapControl.Center.Position.Latitude: 000.0000} ; {GameMapControl.Center.Position.Longitude: 000.0000}";
                    string previousCoord =
                        $"{lastAutoPosition.Position.Latitude: 000.0000} ; {lastAutoPosition.Position.Longitude: 000.0000}";
                    if (currentCoord == previousCoord && ReactivateMapAutoUpdateButton != null)
                    {
                        //Previous position was set automatically, continue!
                        if (ReactivateMapAutoUpdateButton != null)
                        {
                            ReactivateMapAutoUpdateButton.Visibility = Visibility.Collapsed;
                        }
                        GameMapControl.Center = LocationServiceHelper.Instance.Geoposition.Coordinate.Point;

                        lastAutoPosition = GameMapControl.Center;

                        if ((SettingsService.Instance.MapAutomaticOrientationMode == MapAutomaticOrientationModes.GPS) &&
                            (LocationServiceHelper.Instance.Geoposition.Coordinate.Heading.HasValue))
                        {
                            await GameMapControl.TryRotateToAsync(LocationServiceHelper.Instance.Geoposition.Coordinate.Heading.Value);
                        }

                        if (SettingsService.Instance.IsRememberMapZoomEnabled)
                        {
                            GameMapControl.ZoomLevel = SettingsService.Instance.Zoomlevel;
                        }
                    }
                });
            }
        }
        private async void HeadingUpdated(object sender, CompassReading e)
        {
            var newTick = new TimeSpan(DateTime.Now.Ticks);

            if (newTick.Subtract(tick).TotalMilliseconds > 10)
            {
                await
                Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                    async() => { await GameMapControl.TryRotateToAsync(e.HeadingTrueNorth ?? e.HeadingMagneticNorth); });

                tick = newTick;
            }
        }
Exemple #5
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                base.OnNavigatedTo(e);
                // Hide panels just in case
                HidePokeMenuStoryboard.Begin();
                CoverGrid.Opacity = 0;

                // See if we need to update the map
                if ((e.Parameter != null) && (e.NavigationMode != NavigationMode.Back))
                {
                    GameMapNavigationModes mode =
                        ((JObject)JsonConvert.DeserializeObject((string)e.Parameter)).Last
                        .ToObject <GameMapNavigationModes>();
                    if ((mode == GameMapNavigationModes.AppStart) || (mode == GameMapNavigationModes.SettingsUpdate))
                    {
                        SetupMap();
                    }
                }
                // Set first position if we shomehow missed it
                await UpdateMap();

                //Changed order of calls, this allow to have events registration before trying to move map
                //appears that for some reason TryRotate and/or TryTilt fails sometimes!
                SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
                SubscribeToCaptureEvents();

                AudioUtils.SoundEnded += AudioUtils_SoundEnded;
            }
            catch (Exception ex)
            {
                //because we are in "async void" unhandled exception might not be raised
                await ExceptionHandler.HandleException(ex);
            }
            try
            {
                await GameMapControl.TryRotateToAsync(SettingsService.Instance.MapHeading);

                await GameMapControl.TryTiltToAsync(SettingsService.Instance.MapPitch);
            }
            catch
            {
                //we don't care :)
            }
        }