protected override async void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     MainMap.Background = new SolidColorBrush(Colors.Black);
     if (e.Parameter is string)
     {
         Route = await Data.GetRoute(e.Parameter.ToString(), MasterCancellationTokenSource.Token);
         RouteNameBlock.Text = (Route.Name.All(chr => char.IsNumber(chr)) ? "Route " : "") + Route.Name;
         var stopInfo = await ApiLayer.GetStopsForRoute(Route.ID, MasterCancellationTokenSource.Token);
         foreach (var stop in stopInfo.Item1)
             MainMap.ShownStops.Add(stop);
         List<BasicGeoposition> allPoints = new List<BasicGeoposition>();
         foreach (var shape in stopInfo.Item2)
         {
             var points = HelperFunctions.DecodeShape(shape);
             MainMap.MapControl.MapElements.Add(new MapPolyline() { Path = new Windows.Devices.Geolocation.Geopath(points), StrokeColor = (Color)App.Current.Resources["SystemColorControlAccentColor"], StrokeThickness = 4, ZIndex = 0 });
             allPoints.AddRange(points);
         }
         if (allPoints.Count > 0)
         {
             GeoboundingBox box = GeoboundingBox.TryCompute(allPoints);
             await MainMap.MapControl.TrySetViewBoundsAsync(box, new Thickness(0), MapAnimationKind.Bow);
         }
     }
 }
        public static List <Tuple <BusRoute, string[], string[]> > DeformatRoutes(CompactFormatReader reader)
        {
            List <Tuple <BusRoute, string[], string[]> > result = new List <Tuple <BusRoute, string[], string[]> >();

            CompactFormatReader[] routeReader;
            List <string>         stops;
            List <string>         shapes;

            while ((routeReader = reader.Next()) != null)
            {
                BusRoute route = new BusRoute();
                route.ID          = routeReader[0].ReadString();
                route.Name        = routeReader[1].ReadString();
                route.Description = routeReader[2].ReadString();
                route.Agency      = routeReader[3].ReadString();
                stops             = new List <string>();
                shapes            = new List <string>();
                CompactFormatReader[] subReader;
                while ((subReader = routeReader[4].Next()) != null)
                {
                    stops.Add(subReader[0].ReadString());
                }
                while ((subReader = routeReader[5].Next()) != null)
                {
                    shapes.Add(subReader[0].ReadString());
                }
                result.Add(new Tuple <BusRoute, string[], string[]>(route, stops.ToArray(), shapes.ToArray()));
            }
            return(result);
        }
示例#3
0
        private static void OnRouteChangedStatic(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            RouteListingControl typedSender = (RouteListingControl)sender;
            BusRoute            route       = (BusRoute)e.NewValue;

            typedSender.RouteNameBlock.Text        = route.Name;
            typedSender.RouteDescriptionBlock.Text = route.Description;
        }
示例#4
0
        public static async Task <bool> IsRouteCached(BusRoute route)
        {
            bool result = false;

            await AccessRouteCache(delegate(List <Tuple <BusRoute, string[], string[]> > routeData)
            {
                result = routeData.Any(item => item.Item1 == route);
                return(false);
            });

            return(result);
        }
示例#5
0
 public static async Task SaveRoute(BusRoute route, string[] stops, string[] shapes)
 {
     await AccessRouteCache(delegate(List <Tuple <BusRoute, string[], string[]> > routes)
     {
         if (!routes.Any(item => item.Item1 == route))
         {
             routes.Add(new Tuple <BusRoute, string[], string[]>(route, stops, shapes));
             return(true);
         }
         return(false);
     });
 }
示例#6
0
        public static async Task <string[]> GetCachedStopIdsForRoute(BusRoute route)
        {
            string[] result = null;
            await AccessRouteCache(delegate(List <Tuple <BusRoute, string[], string[]> > rte)
            {
                var curRoute = rte.FirstOrDefault(item => item.Item1 == route);
                if (curRoute != null)
                {
                    result = curRoute.Item2;
                }
                return(false);
            });

            return(result ?? new string[0]);
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            Message.ShowMessage(new Message()
            {
                ShortSummary = "Not every trip serves every stop.", Caption = "Route Map Warning", FullText = "The path shown on the map is every path driven by this route in any circumstance. While sometimes every trip serves every stop, often times trips terminate earlier than others. Also, some routes have special extended trips that aren't normally served by the route, and this map shows all of them. A future update will allow you to more easily see which trips serve which stops.", Id = 4
            });
            MainMap.Background = new SolidColorBrush(Colors.Black);
            if (e.Parameter is string)
            {
                Route = (await Data.GetRoute(e.Parameter.ToString(), MasterCancellationTokenSource.Token)).Value;
                RouteNameBlock.Text = (char.IsNumber(Route.Name.FirstOrDefault()) ? "Route " : "") + Route.Name;
                var stopInfo = await Data.GetStopsAndShapesForRoute(Route.ID, new DataRetrievalOptions(DataSourceDescriptor.Local), MasterCancellationTokenSource.Token);

                if (stopInfo.Item2.FinalSource != null)
                {
                    foreach (var stop in stopInfo.Item1.Item1)
                    {
                        MainMap.ShownStops.Add(stop);
                    }
                    List <BasicGeoposition> allPoints = new List <BasicGeoposition>();
                    foreach (var shape in stopInfo.Item1.Item2)
                    {
                        var points = HelperFunctions.DecodeShape(shape);
                        MainMap.MapControl.MapElements.Add(new MapPolyline()
                        {
                            Path = new Windows.Devices.Geolocation.Geopath(points), StrokeColor = (Color)App.Current.Resources["SystemColorControlAccentColor"], StrokeThickness = 4, ZIndex = 0
                        });
                        allPoints.AddRange(points);
                    }
                    if (allPoints.Count > 0)
                    {
                        GeoboundingBox box = GeoboundingBox.TryCompute(allPoints);

                        await MainMap.MapControl.TrySetViewBoundsAsync(box, new Thickness(0), MapAnimationKind.Bow);
                    }
                }
                else
                {
                    await new MessageDialog("We could not download the data for the selected route, and you don't have that route downloaded.", "Error getting route").ShowAsync();
                }
            }
        }
示例#8
0
 public static List<Tuple<BusRoute, string[], string[]>> DeformatRoutes(CompactFormatReader reader)
 {
     List<Tuple<BusRoute, string[], string[]>> result = new List<Tuple<BusRoute, string[], string[]>>();
     CompactFormatReader[] routeReader;
     List<string> stops;
     List<string> shapes;
     while ((routeReader = reader.Next()) != null)
     {
         BusRoute route = new BusRoute();
         route.ID = routeReader[0].ReadString();
         route.Name = routeReader[1].ReadString();
         route.Description = routeReader[2].ReadString();
         route.Agency = routeReader[3].ReadString();
         stops = new List<string>();
         shapes = new List<string>();
         CompactFormatReader[] subReader;
         while ((subReader = routeReader[4].Next()) != null)
         {
             stops.Add(subReader[0].ReadString());
         }
         while ((subReader = routeReader[5].Next()) != null)
         {
             shapes.Add(subReader[0].ReadString());
         }
         result.Add(new Tuple<BusRoute, string[], string[]>(route, stops.ToArray(), shapes.ToArray()));
     }
     return result;
 }
示例#9
0
 public static async Task SaveRoute(BusRoute route, string[] stops, string[] shapes)
 {
     await EnsureFolders();
     await ModifyRouteCache(delegate (List<Tuple<BusRoute, string[], string[]>> routes)
     {
         routes.RemoveAll(item => item.Item1 == route);
         routes.Add(new Tuple<BusRoute, string[], string[]>(route, stops, shapes));
     });
 }
示例#10
0
 public RouteListing(BusRoute route)
 {
     Name = route.Name;
     Description = route.Description;
     Route = route;
 }
示例#11
0
 public static async Task<string[]> GetCachedStopIdsForRoute(BusRoute route)
 {
     string[] result = null;
     await AccessRouteCache(delegate (List<Tuple<BusRoute, string[], string[]>> rte)
         {
             var curRoute = rte.FirstOrDefault(item => item.Item1 == route);
             if (curRoute != null)
             {
                 result = curRoute.Item2;
             }
             return false;
         });
     return result ?? new string[0];
 }
示例#12
0
 public static async Task<bool> IsRouteCached(BusRoute route)
 {
     bool result = false;
     await AccessRouteCache(delegate (List<Tuple<BusRoute, string[], string[]>> routeData)
     {
         result = routeData.Any(item => item.Item1 == route);
         return false;
     });
     return result;
 }
示例#13
0
 public static async Task SaveRoute(BusRoute route, string[] stops, string[] shapes)
 {
     await AccessRouteCache(delegate (List<Tuple<BusRoute, string[], string[]>> routes)
     {
         if (!routes.Any(item => item.Item1 == route))
         {
             routes.Add(new Tuple<BusRoute, string[], string[]>(route, stops, shapes));
             return true;
         }
         return false;
     });
 }
示例#14
0
 public RouteListing(BusRoute route)
 {
     Name        = route.Name;
     Description = route.Description;
     Route       = route;
 }