예제 #1
0
        public static bool SaveMapState()
        {
            var mapState = MapControl.SerializeMapState(false, mapping.globalMapping.ApplicationPath);
            var filepath = $"{AppDomain.CurrentDomain.BaseDirectory}mapstate.txt";

            if (File.Exists(filepath))
            {
                try
                {
                    File.Delete(filepath);
                }
                catch (IOException)
                {
                    try
                    {
                        File.WriteAllText(filepath, String.Empty);
                    }
                    catch (Exception ex)
                    {
                        LastError = ex.Message;
                        return(false);;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    LastError = ex.Message;
                    return(false);
                }
            }

            //insert custom settings at this point
            string xml = InsertCustomSettingToMapState(mapState);

            using (StreamWriter writer = new StreamWriter(filepath, true))
            {
                writer.Write(PrettyXML.PrettyPrint(xml));
            }


            return(true);
        }
예제 #2
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            rowFile.Height   = new GridLength(0);
            rowDetail.Height = new GridLength(0);
            if (ShowAsXML)
            {
                rowFile.Height = new GridLength(1, GridUnitType.Star);
                txtGPX.Text    = PrettyXML.PrettyPrint(GPXFile.XML);
            }
            else
            {
                rowDetail.Height = new GridLength(1, GridUnitType.Star);
                if (GPXXML != null && GPXXML.Length > 0)
                {
                    labelFileName.Content = "Extracted track of fishing trip";
                    Track tr = new Track();
                    tr.Read(GPXXML, true);
                    var stats = tr.Statistics;
                    if (tr.Waypoints.Count > 0)
                    {
                        labelOfFileName.Content            = "Description";
                        labelOfTrackCount.Content          = "Length";
                        labelTrackCount.Content            = stats.Length.ToString("N2") + " km";
                        labelGPXType.Content               = "Track waypoints";
                        dataGridNamedWaypoints.DataContext = tr.TrackPtsInLocalTine;
                        labelWaypointCount.Content         = tr.Waypoints.Count.ToString();
                        labelWaypointLabel.Content         = "Number of track pts.";
                    }
                }
                else
                {
                    labelTrackCount.Content = GPXFile.TrackCount.ToString();
                    if (GPXFile.FileInfo != null)
                    {
                        labelFileName.Content = GPXFile.FileInfo.FullName;
                    }
                    else
                    {
                        labelFileName.Content = GPXFile.FileName;
                    }

                    if (GPXFile.WaypointCount > 0)
                    {
                        labelWaypointLabel.Content         = "Number of waypoints";
                        labelWaypointCount.Content         = GPXFile.WaypointCount.ToString();
                        labelGPXType.Content               = "Waypoints";
                        dataGridNamedWaypoints.DataContext = GPXFile.NamedWaypointsInLocalTime;
                    }
                    else
                    {
                        //foreach(var item in GPXFile.w)
                        labelGPXType.Content = "Track waypoints";
                        dataGridNamedWaypoints.DataContext = GPXFile.TrackWaypoinsInLocalTime;
                        labelWaypointCount.Content         = GPXFile.TrackPointsCount.ToString();
                        labelWaypointLabel.Content         = "Number of track pts.";
                    }
                }
                dataGridNamedWaypoints.Columns.Add(new DataGridTextColumn {
                    Header = "Name", Binding = new Binding("Name")
                });
                dataGridNamedWaypoints.Columns.Add(new DataGridTextColumn {
                    Header = "Longitude", Binding = new Binding("Longitude")
                });
                dataGridNamedWaypoints.Columns.Add(new DataGridTextColumn {
                    Header = "Latitude", Binding = new Binding("Latitude")
                });
                //dataGridNamedWaypoints.Columns.Add(new DataGridTextColumn { Header = "Time", Binding = new Binding("Time") });

                var col = new DataGridTextColumn()
                {
                    Binding = new Binding("Time"),
                    Header  = "Time stamp"
                };
                col.Binding.StringFormat = "MMM-dd-yyyy HH:mm";
                dataGridNamedWaypoints.Columns.Add(col);
            }
        }