コード例 #1
0
        public void TestKml21File()
        {
            // set up
            string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "kml21.kml");

            // run
            var kmlFile = GeoLoader.LoadGeoDataFile(filename);

            // check
            Assert.IsTrue(kmlFile.HasLocations(), "file must have a location");
        }
コード例 #2
0
        public void TestGetTrackList()
        {
            // set up
            string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "track_linestring.kmz");
            var    kmlFile  = GeoLoader.LoadGeoDataFile(filename);

            // run
            var trackList = kmlFile.GetTrackList();

            // check
            Assert.IsTrue(trackList.Any(), "track list must contain any tracks");
        }
コード例 #3
0
        /// <summary>
        /// Opens file from given stream
        /// </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 OpenFileAsync(Stream stream, string filename)
        {
            if (Path.GetExtension(filename).ToLowerInvariant() == ".czml")
            {
                await ImportLayerFile(stream, filename);

                return;
            }

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

                bool hasTracks = geoDataFile.GetTrackList().Any();

                if (geoDataFile.HasLocations() && !hasTracks)
                {
                    await ImportLocationListAsync(geoDataFile.LoadLocationList());

                    return;
                }

                if (!geoDataFile.HasLocations() && hasTracks)
                {
                    await SelectAndImportTrackAsync(geoDataFile);

                    return;
                }

                if (!geoDataFile.HasLocations() && !hasTracks)
                {
                    await App.Current.MainPage.DisplayAlert(
                        Constants.AppTitle,
                        "No locations or tracks were found in the file",
                        "OK");

                    return;
                }

                // file has both locations and tracks; ask user
                await AskUserImportLocationsOrTracks(geoDataFile);
            }
            catch (Exception ex)
            {
                App.LogError(ex);

                await App.Current.MainPage.DisplayAlert(
                    Constants.AppTitle,
                    "Error while opening file: " + ex.Message,
                    "OK");
            }
        }
コード例 #4
0
        public void TestFileWithoutPlacemarks()
        {
            // set up
            string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "tracks.kmz");
            var    kmlFile  = GeoLoader.LoadGeoDataFile(filename);

            // run
            var locationList = kmlFile.LoadLocationList();

            // check
            Assert.IsFalse(kmlFile.HasLocations(), "kml file must not contain locations");
            Assert.IsFalse(locationList.Any(), "loaded location list must not contain locations");
        }
コード例 #5
0
        public void TestLoadLocationListKmz()
        {
            // set up
            string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "waypoints.kmz");
            var    kmlFile  = GeoLoader.LoadGeoDataFile(filename);

            // run
            Assert.IsTrue(kmlFile.HasLocations(), "kml file must contain locations");
            var locationList = kmlFile.LoadLocationList();

            // check
            Assert.IsTrue(locationList.Any(), "loaded location list must contain locations");
        }
コード例 #6
0
        public void TestLoadTrack()
        {
            // set up
            string filename = Path.Combine(UnitTestHelper.TestAssetsPath, "track_linestring.kmz");

            var kmlFile = GeoLoader.LoadGeoDataFile(filename);

            // run
            var track0 = kmlFile.LoadTrack(0);
            var track1 = kmlFile.LoadTrack(1);

            // check
            Assert.IsTrue(track0.TrackPoints.Any(), "track points list must not be empty");
            Assert.IsTrue(track1.TrackPoints.Any(), "track points list must not be empty");
        }
コード例 #7
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();
            }
        }
コード例 #8
0
ファイル: OpenFileHelper.cs プロジェクト: vividos/WhereToFly
        /// <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);
        }