Beispiel #1
0
        public SvcInfoPage(string busSvcName)
        {
            Title = busSvcName + " Route Information";

            // show only for nus buses
            if (!BusHelper.IsPublic(busSvcName))
            {
                Label header = new Label {
                    Text              = busSvcName,
                    FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                    FontAttributes    = FontAttributes.Bold,
                    HorizontalOptions = LayoutOptions.Center
                };

                var view = new TableView()
                {
                    Intent = TableIntent.Data
                };
                var root    = new TableRoot();
                var section = new TableSection();

                foreach (string busStopCode in BusHelper.BusSvcs[busSvcName].stops)
                {
                    section.Add(new BusStopCell(busStopCode));
                }

                root.Add(section);
                view.Root = root;

                Content = new StackLayout {
                    Children =
                    {
                        header,
                        view
                    }
                };
            }
            else
            {
                Content = new Label {
                    Text = "Page under construction"
                };
            }
        }
Beispiel #2
0
        private void OnClickRoute(object sender, EventArgs e)
        {
            var routeName = ((Button)sender).StyleId;
            // take the correct list for public/nus bus
            var busSvcStops = (BusHelper.IsPublic(routeName)) ? BusHelper.PublicBusSvcStops[routeName] : BusHelper.BusSvcs [routeName].stops;

            if (((Button)sender).Opacity.Equals(0.3))
            {
                // activate bus service
                // add all stops from bus service into list if list does not contains bus stop
                ((Button)sender).Opacity = 1;
                enabledSvcs.Add(routeName);
                foreach (string busStopCode in busSvcStops)
                {
                    if (!stops.Contains(BusHelper.BusStops[busStopCode]))
                    {
                        stops.Add(BusHelper.BusStops[busStopCode]);
                    }
                }
            }
            else
            {
                // deactivate bus service
                // remove bus stop of bus service from list if no other enabled bus service shares the same bus stop
                // incl public bus
                ((Button)sender).Opacity = 0.3;
                enabledSvcs.Remove(routeName);
                foreach (string busStopCode in busSvcStops)
                {
                    var stop = BusHelper.BusStops [busStopCode];
                    var otherEnabledSvcsInStop = enabledSvcs.Intersect(stop.services.Union(stop.publicServices)).ToList();
                    if (otherEnabledSvcsInStop.Count == 0)
                    {
                        stops.Remove(stop);
                    }
                }
            }
        }
Beispiel #3
0
        private async void UpdateStopPins()
        {
            while (true)
            {
                // skip update pins if map is freezed (user clicks on pin)
                if (!FreezeMap)
                {
                    // remove all stop pins
                    foreach (CustomPin p in map.StopPins)
                    {
                        map.Pins.Remove(p.Pin);
                    }
                    map.StopPins.Clear();

                    // add stop pins, with change in arrival timing
                    foreach (BusStop busStop in BusHelper.BusStops.Values)
                    {
                        var description = "";
                        foreach (string svc in busStop.services)
                        {
                            // handle repeated service in bus stop case
                            // show timing for both directions
                            if (busStop.repeatedServices != null && busStop.repeatedServices.Contains(svc))
                            {
                                description += svc + "(to " + BusHelper.BusStops [BusHelper.BusSvcs [svc].loopStop].name + "): ";
                                description += BusHelper.GetArrivalTiming(busStop.busStopCode, svc, "BEFORE") + "\n";
                                description += svc + "(to " + BusHelper.BusStops [BusHelper.BusSvcs [svc].lastStop].name + "): ";
                                description += BusHelper.GetArrivalTiming(busStop.busStopCode, svc, "AFTER") + "\n";
                            }
                            else
                            {
                                description += svc + ": " + BusHelper.GetArrivalTiming(busStop.busStopCode, svc) + "\n";
                            }
                        }

                        // get public bus arrival timing for bus stop (if public buses pass by)
                        // busStopCode with all digits -> public bus will pass by
                        if (BusHelper.IsPublic(busStop.busStopCode))
                        {
                            description += await BusHelper.GetPublicBusesArrivalTiming(busStop.busStopCode);
                        }

                        var pin = new Pin {
                            Type     = PinType.Place,
                            Position = new Xamarin.Forms.Maps.Position(busStop.latitude, busStop.longitude),
                            Label    = busStop.name + " - " + busStop.busStopCode,
                            Address  = description
                        };
                        var stop = new CustomPin {
                            Pin = pin,
                            Id  = "stop",
                            Url = "stop.png"
                        };
                        map.Pins.Add(pin);
                        map.StopPins.Add(stop);
                    }
                }

                // continue after interval
                await Task.Delay(TimeSpan.FromSeconds(SettingsVars.Variables ["REFRESH_STOP_INTERVAL"].value));
            }
        }