示例#1
0
 public static List<BusStop> DeformatStops(CompactFormatReader reader)
 {
     List<BusStop> result = new List<BusStop>();
     CompactFormatReader[] stopReader;
     List<string> routes;
     while ((stopReader = reader.Next()) != null)
     {
         BusStop stop = new BusStop();
         stop.ID = stopReader[0].ReadString();
         stop.Direction = (StopDirection)stopReader[1].ReadInt();
         stop.Position = new BasicGeoposition() { Latitude = double.Parse(stopReader[2].ReadString()), Longitude = double.Parse(stopReader[3].ReadString()) };
         stop.Name = stopReader[4].ReadString();
         stop.Code = stopReader[5].ReadString();
         stop.LocationType = stopReader[6].ReadInt();
         routes = new List<string>();
         CompactFormatReader[] routeReader;
         while ((routeReader = stopReader[7].Next()) != null)
         {
             routes.Add(routeReader[0].ReadString());
         }
         stop.Routes = routes.ToArray();
         result.Add(stop);
     }
     return result;
 }
示例#2
0
 public static async Task SaveScheduleAsync(WeekSchedule schedule, BusStop stop)
 {
     await EnsureFolders();
     var file = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).CreateFileAsync(stop.ID.ToString() + ".txt", CreationCollisionOption.ReplaceExisting);
     CompactFormatWriter encoder = new CompactFormatWriter();
     schedule.Format(encoder);
     encoder.TrimDelimiter();
     await FileIO.WriteTextAsync(file, encoder.ToString());
     await ModifyStopCache(delegate (List<BusStop> cache)
     {
             if (!cache.Any(item => item == stop))
                 cache.Add(stop);
     }
         );
 }
示例#3
0
 private void OnStopsClicked(BusStop[] stops, BasicGeoposition location)
 {
     if (StopsClicked != null) StopsClicked(this, new StopClickedEventArgs(location, stops));
 }
示例#4
0
 private void MainMap_MapElementClick(MapControl sender, MapElementClickEventArgs args)
 {
     var mapIcons = args.MapElements.Where(me => me is MapIcon && BusStopIcons.Contains(me));
     BusStop[] stops = new BusStop[mapIcons.Count()];
     for (int i = 0; i < stops.Length; i++)
     {
         stops[i] = Stops[(MapIcon)mapIcons.ElementAt(i)];
     }
     OnStopsClicked(stops, args.Location.Position);
 }
示例#5
0
        private void AddStopToMap(BusStop stop)
        {
            MapIcon mico = new MapIcon();
            
            mico.ZIndex = 10;
            mico.Location = new Geopoint(stop.Position);
            mico.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
            string size = ZoomLevel < StopSizeThreshold ? "20" : "40";
            bool visibility = ZoomLevel >= StopVisibilityThreshold;
            mico.Image = RandomAccessStreamReference.CreateFromUri(new Uri(stop.Direction == StopDirection.Unspecified ? "ms-appx:///Assets/Icons/BusBase" + size + ".png" : "ms-appx:///Assets/Icons/BusDirection" + stop.Direction.ToString() + size + ".png"));
            mico.NormalizedAnchorPoint = new Point(0.5, 0.5);
            mico.Visible = visibility;
            MainMap.MapElements.Add(mico);
            Stops[mico] = stop;
            BusStopIcons.Add(mico);

            

            polygonCenter = stop.Position;
            SetPolygonSize();
        }
示例#6
0
 private void RemoveStopFromMap(BusStop stop)
 {
     MapIcon mico = Stops.FirstOrDefault(kvp => kvp.Value == stop).Key;
     Stops.Remove(mico);
     if (mico == null) return;
     MainMap.MapElements.Remove(mico);
 }
示例#7
0
        protected override async void OnLoadState(Dictionary<string, object> state, object navigationParameter)
        {
            if (state != null && state.ContainsKey("Lat") && state.ContainsKey("Lon") && state.ContainsKey("Zoom"))
            {
                MainMap.Center = new BasicGeoposition() { Latitude = (double)state["Lat"], Longitude = (double)state["Lon"] };
                MainMap.ZoomLevel = (double)state["Zoom"];
                if (state.ContainsKey("Stops") && state.ContainsKey("StopsLat") && state.ContainsKey("StopsLon"))
                {
                    var location = new BasicGeoposition() { Latitude = (double)state["StopsLat"], Longitude = (double)state["StopsLon"] };
                    var stopIds = (string[])state["Stops"];
                    BusStop[] stops = new BusStop[stopIds.Length];
                    for (int i = 0; i < stopIds.Length; i++)
                        stops[i] = await Data.GetBusStop(stopIds[i], MasterCancellationTokenSource.Token);
                    OnStopsClicked(stops, location);
                    CanGoBack = true;
                }
            }
            else if (navigationParameter?.ToString() == "CurrentLocation")
            {
                CenterOnCurrentLocation();

            }
        }
示例#8
0
        private async void OnStopsClicked(BusStop[] stops, BasicGeoposition location)
        {
            BasicGeoposition newCenter = location;
            newCenter.Latitude = location.Latitude + (MainMap.TopLeft.Latitude - MainMap.BottomRight.Latitude) / 2 - 50 * MainMap.LatitudePerPixel;
            double halfLatSpan = (MainMap.TopLeft.Latitude - MainMap.BottomRight.Latitude) / 2.5;
            double halfLonSpan = (MainMap.BottomRight.Longitude - MainMap.TopLeft.Longitude) / 2.5;
            await MainMap.MapControl.TrySetViewBoundsAsync(new GeoboundingBox(new BasicGeoposition() { Latitude = newCenter.Latitude + halfLatSpan, Longitude = newCenter.Longitude - halfLonSpan },
                new BasicGeoposition() { Latitude = newCenter.Latitude - halfLatSpan, Longitude = newCenter.Longitude + halfLonSpan }), null, MapAnimationKind.Linear);

            MapControl.SetLocation(StopArrivalBoxGrid, new Geopoint(location));
            StopArrivalBox.SetStops(stops);
            VisualStateManager.GoToState(this, "ArrivalBoxShown", true);
        }
示例#9
0
 public static async Task OverwriteScheduleAsync(WeekSchedule schedule, BusStop stop)
 {
     int hash = HashLocation(stop.Position);
     var file = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).CreateFileAsync(stop.ID.ToString() + ".txt", CreationCollisionOption.ReplaceExisting);
     CompactFormatWriter encoder = new CompactFormatWriter();
     schedule.Format(encoder);
     encoder.TrimDelimiter();
     await FileIO.WriteTextAsync(file, encoder.ToString());
     await AccessStopCache(hash, delegate (List<BusStop> cache)
     {
         if (!cache.Any(item => item == stop))
         {
             cache.Add(stop);
             return true;
         }
         return false;
     }
         );
 }
示例#10
0
 public static async Task DeleteSchedules(BusStop[] stops, params string[] routes)
 {
     Dictionary<string, StorageFile> files = new Dictionary<string, StorageFile>();
     var allFiles = await (await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("SavedSchedules")).GetFilesAsync();
     foreach (var file in allFiles)
     {
         if (stops.Any(stop => stop.Name + ".txt" == file.Name))
         {
             var curStop = stops.First(stop => stop.Name + ".txt" == file.Name);
             files.Add(curStop.ID, file);
         }
     }
     foreach (var stop in stops)
     {
         if (files.Any(kvp => kvp.Key == stop.ID))
         {
             var file = files.First(kvp => kvp.Key == stop.ID).Value;
             await DeleteSchedule(stop, file, routes);
         }
     }
 }
示例#11
0
 private static async Task DeleteSchedule(BusStop stop, StorageFile file, params string[] routes)
 {
     if (routes == null || routes.Length == 0)
     {
         await file.DeleteAsync();
     }
     else
     {
         WeekSchedule baseSchedule = (await LoadSchedule(stop.ID)) ?? new WeekSchedule();
         baseSchedule.RemoveRoutes(routes);
         if (baseSchedule.IsEmpty)
             await DeleteSchedule(stop, file);
         else
             await OverwriteScheduleAsync(baseSchedule, stop);
     }
 }
示例#12
0
 public static async Task SaveScheduleAsync(WeekSchedule schedule, BusStop stop)
 {
     WeekSchedule baseSchedule = (await LoadSchedule(stop.ID)) ?? new WeekSchedule();
     baseSchedule.RemoveRoutes(schedule.Routes);
     baseSchedule.MergeByRoute(schedule);
     await OverwriteScheduleAsync(baseSchedule, stop);
 }
示例#13
0
        private async void OnStopsClicked(BusStop[] stops, BasicGeoposition location)
        {
            BasicGeoposition newCenter = location;
            newCenter.Latitude = location.Latitude + (MainMap.TopLeft.Latitude - MainMap.BottomRight.Latitude) / 2 - 50 * MainMap.LatitudePerPixel;
            double halfLatSpan = (MainMap.TopLeft.Latitude - MainMap.BottomRight.Latitude) / 2.5;
            double halfLonSpan = (MainMap.BottomRight.Longitude - MainMap.TopLeft.Longitude) / 2.5;
            if (halfLatSpan > 0 && halfLonSpan > 0)
            {
                await MainMap.MapControl.TrySetViewBoundsAsync(new GeoboundingBox(new BasicGeoposition() { Latitude = newCenter.Latitude + halfLatSpan, Longitude = newCenter.Longitude - halfLonSpan },
                    new BasicGeoposition() { Latitude = newCenter.Latitude - halfLatSpan, Longitude = newCenter.Longitude + halfLonSpan }), null, MapAnimationKind.Linear);
            }

            MapControl.SetLocation(StopArrivalBoxGrid, new Geopoint(location));
            StopArrivalBox.SetStops(stops);
            VisualStateManager.GoToState(this, "ArrivalBoxShown", true);
            if (!SettingsManager.GetSetting("ShowStopPageTipShown", true, false) && (new Random()).NextDouble() < 0.05)
            {
                SettingsManager.SetSetting("ShowStopPageTipShown", true, true);
                await Task.Delay(1000);
                await StopArrivalBox.ShowHelpTip();
            }
        }