Example #1
0
        /// <summary>
        /// Samples track point heights and adjusts the track when it goes below terrain height.
        /// </summary>
        /// <param name="track">track to adjust point heights</param>
        /// <returns>task to wait on</returns>
        private static async Task AdjustTrackHeightsAsync(Track track)
        {
            var cts = new CancellationTokenSource();

            waitingDialog = new WaitingPopupPage("Sampling track point heights...", cts);
            await App.RunOnUiThreadAsync(async() => await waitingDialog.ShowAsync());

            await App.InitializedTask;

            try
            {
                var trackPointHeights =
                    await Task.Run(
                        async() => await App.MapView.SampleTrackHeights(track),
                        cts.Token);

                if (cts.IsCancellationRequested)
                {
                    return;
                }

                if (trackPointHeights != null)
                {
                    track.GroundHeightProfile = trackPointHeights.ToList();
                    track.AdjustTrackPointsByGroundProfile(trackPointHeights);
                }
            }
            finally
            {
                await waitingDialog.HideAsync();

                waitingDialog = null;
            }
        }
Example #2
0
        /// <summary>
        /// Closes waiting popup page when on stack (actually removes any popup page).
        /// </summary>
        /// <returns>task to wait on</returns>
        private static async Task CloseWaitingPopupPageAsync()
        {
            try
            {
                if (waitingDialog != null)
                {
                    await waitingDialog.HideAsync();

                    waitingDialog = null;
                }
            }
            catch (Exception)
            {
                // ignore when there's no popup page on stack
            }
        }
Example #3
0
        /// <summary>
        /// Samples track point heights and adjust track
        /// </summary>
        /// <param name="track">track to sample point heights</param>
        /// <returns>task to wait on</returns>
        private static async Task SampleTrackHeightsAsync(Track track)
        {
            waitingDialog = new WaitingPopupPage("Sampling track point heights...");
            App.RunOnUiThread(async() => await waitingDialog.ShowAsync());

            try
            {
                await App.SampleTrackHeightsAsync(track, 0.0);
            }
            finally
            {
                await waitingDialog.HideAsync();

                waitingDialog = null;
            }
        }
Example #4
0
        /// <summary>
        /// Opens and load location list from given stream object
        /// </summary>
        /// <param name="stream">stream object</param>
        /// <param name="filename">
        /// filename; extension of filename is used to determine file type
        /// </param>
        /// <returns>task to wait on</returns>
        public static async Task OpenLocationListAsync(Stream stream, string filename)
        {
            await CloseWaitingPopupPageAsync();

            waitingDialog = new WaitingPopupPage("Importing locations...");

            try
            {
                await waitingDialog.ShowAsync();

                var geoDataFile  = GeoLoader.LoadGeoDataFile(stream, filename);
                var locationList = geoDataFile.HasLocations() ? geoDataFile.LoadLocationList() : null;

                if (locationList == null ||
                    !locationList.Any())
                {
                    await App.Current.MainPage.DisplayAlert(
                        Constants.AppTitle,
                        "No locations were found in the file",
                        "OK");

                    return;
                }

                await ImportLocationListAsync(locationList);
            }
            catch (Exception ex)
            {
                App.LogError(ex);

                await App.Current.MainPage.DisplayAlert(
                    Constants.AppTitle,
                    "Error while loading locations: " + ex.Message,
                    "OK");

                return;
            }
            finally
            {
                await CloseWaitingPopupPageAsync();
            }
        }
Example #5
0
        /// <summary>
        /// Opens and loads track from given stream object
        /// </summary>
        /// <param name="stream">stream object</param>
        /// <param name="filename">
        /// filename; extension of filename is used to determine file type
        /// </param>
        /// <returns>true when loading track was successful, false when not</returns>
        public static async Task <bool> OpenTrackAsync(Stream stream, string filename)
        {
            waitingDialog = new WaitingPopupPage("Importing track...");

            try
            {
                await waitingDialog.ShowAsync();

                var geoDataFile = GeoLoader.LoadGeoDataFile(stream, filename);

                bool hasTracks = geoDataFile.GetTrackList().Any();
                if (!hasTracks)
                {
                    await App.Current.MainPage.DisplayAlert(
                        Constants.AppTitle,
                        "No tracks were found in the file",
                        "OK");

                    return(false);
                }

                return(await SelectAndImportTrackAsync(geoDataFile));
            }
            catch (Exception ex)
            {
                App.LogError(ex);

                await App.Current.MainPage.DisplayAlert(
                    Constants.AppTitle,
                    $"Error while loading track: {ex.Message}",
                    "OK");
            }
            finally
            {
                await CloseWaitingPopupPageAsync();
            }

            return(false);
        }