コード例 #1
0
        // Constructor
        public MainPanoramaPage()
        {
            InitializeComponent();

            SystemTray.SetIsVisible(this, true);

            pins = new List<Pushpin>();

            if (watcher == null)
            {
                //---get the highest accuracy---
                watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
                {
                    //---the minimum distance (in meters) to travel before the next
                    // location update---
                    MovementThreshold = 10
                };

                //---event to fire when a new position is obtained---
                watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);

                //---event to fire when there is a status change in the location
                // service API---
                watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
                watcher.Start();

                map1.Center = new GeoCoordinate(58.383333, 26.716667);
                map1.ZoomLevel = 15;
                map1.Mode = new MyMapMode();
                var clusterer = new PushpinClusterer(map1, pins, this.Resources["ClusterTemplate"] as DataTemplate);

                // get list of stops
                OmnibussModel model = new OmnibussModel();
                List<Stop> stops = model.GetStops();
                Debug.WriteLine("Stops count: " + stops.Count);

                foreach (Stop stop in stops)
                {
                    Pushpin pin = addLocationPin(stop.Latitude, stop.Longitude, stop.Name);
                    int id = stop.Id;

                    pin.MouseLeftButtonUp += new MouseButtonEventHandler(
                        (object sender, MouseButtonEventArgs e) =>
                        {
                            NavigationService.Navigate(new Uri("/StopDetailsPanoramaPage.xaml?stopId=" + id, UriKind.Relative));
                        });
                }
            }
        }
コード例 #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            String idString = "";
            if (!NavigationContext.QueryString.TryGetValue("stopId", out idString))
            {
                Debug.WriteLine("No stop ID provided!");
                NavigationService.GoBack();
                return;
            }
            stopId = UInt32.Parse(idString);
            Debug.WriteLine("Stop id: " + stopId);

            OmnibussModel model = new OmnibussModel();
            Stop stop = model.GetStop(stopId);
            Panorama.Title = stop.Name;

            routeList.ItemsSource = routes = model.GetRoutesByStop(stop);

            addLocationPin(stop.Latitude, stop.Longitude, stop.Name);
            map1.Center = new GeoCoordinate((double)stop.Latitude, (double)stop.Longitude);
        }
コード例 #3
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            String stopIdStr, routeIdStr;
            if (!NavigationContext.QueryString.TryGetValue("stopId", out stopIdStr))
            {
                Debug.WriteLine("No stop ID provided!");
                NavigationService.GoBack();
                return;
            }

            if (!NavigationContext.QueryString.TryGetValue("routeId", out routeIdStr))
            {
                Debug.WriteLine("No route ID provided!");
                NavigationService.GoBack();
                return;
            }

            UInt32 stopId = UInt32.Parse(stopIdStr);
            Debug.WriteLine("Stop id: " + stopId);
            UInt32 routeId = UInt32.Parse(routeIdStr);
            Debug.WriteLine("Route id: " + routeId);

            OmnibussModel model = new OmnibussModel();

            Stop stop = model.GetStop(stopId);
            Route route = model.GetRoute(routeId);

            List<Stop_time> times = new List<Stop_time>();
            List<List<Stop>> stopsList = new List<List<Stop>>();

            ProgressIndicator progress = new ProgressIndicator();
            progress.IsVisible = true;
            progress.IsIndeterminate = true;
            SystemTray.SetProgressIndicator(this, progress);

            BackgroundWorker bgWorker = new BackgroundWorker();
            bgWorker.DoWork += new DoWorkEventHandler(
                (sender, args) =>
                {
                    for (int i = 0; i < 2; i++)
                    {
                        Trip trip = model.GetMaxTripByRoute(route, i);
                        if (trip != null)
                        {
                            Debug.WriteLine("TripID: " + trip.Trip_id);
                            List<Stop> stops = model.GetStopsByTrip(trip);
                            stopsList.Add(stops);
                        }
                    }

                    times.AddRange(model.GetTimesByRouteAndStop(route, stop));

                }
            );
            bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                (sender, args) =>
                {
                    if (times.Count == 0)
                    {
                        NextTime.Text = "Kahjuks see liin täna rohkem ei sõida.";
                    }
                    else if (myLocation != null)
                    {
                        DateTime now = DateTime.Now;
                        int dep = (int)times[0].Departure_time;
                        int cur = (now.Hour * 10000 + now.Minute * 100 + now.Second);

                        double _diff = 0.0;
                        _diff += (dep % 100) - (cur % 100);
                        dep /= 100; cur /= 100;
                        _diff += ((dep % 100) - (cur % 100)) * 60;
                        dep /= 100; cur /= 100;
                        _diff += ((dep % 100) - (cur % 100)) * 3600;

                        double timeInHours = _diff / 3600.0;
                        // TEMP END

                        NextTime.Text = "Buss väljub järgnevatel aegadel:";
                        Location stopLocation = new Location();
                        stopLocation.Latitude = (double)stop.Latitude;
                        stopLocation.Longitude = (double)stop.Longitude;
                        double distanceKm = calculateDistance(myLocation, stopLocation);
                        string warningText = "";
                        if (distanceKm > (10 * timeInHours))
                        {
                            warningText = " (Sinna bussile sa enam ei jõua. Kurb)";
                        }
                        else if (distanceKm < (10 * timeInHours) && distanceKm > (5 * timeInHours))
                        {
                            warningText = " (Jookse, sa jõuad veel!)";
                        }
                        NextTime.Text = "Buss väljub järgnevatel aegadel" + warningText + ":";

                    }

                    var timesList = new List<String>();

                    foreach (var time in times)
                    {
                        String timeString = time.Departure_time.ToString();
                        String hours = timeString.Substring(0, timeString.Length > 5 ? 2 : 1);
                        String minutes = timeString.Substring(timeString.Length > 5 ? 2 : 1, 2);
                        timesList.Add(String.Format("{0,2:d2}:{1,2:d2}", hours, minutes));
                    }

                    schedule.ItemsSource = timesList;
                    foreach (var stops in stopsList)
                    {
                        GetRoute(stops);
                        foreach (var _stop in stops)
                        {
                            Pushpin pin = addLocationPin(_stop.Latitude, _stop.Longitude, _stop.Name);
                            int id = _stop.Id;

                            pin.MouseLeftButtonUp += new MouseButtonEventHandler(
                                (sender1, e1) =>
                                {
                                    NavigationService.Navigate(new Uri("/StopDetailsPanoramaPage.xaml?stopId=" + id, UriKind.Relative));
                                });
                        }
                    }
                    progress.IsVisible = false;
                }
            );
            bgWorker.RunWorkerAsync();

            Panorama.Title = route;

            var panoramaItem = Panorama.Items[0] as PanoramaItem;
            if (panoramaItem != null)
            {
                panoramaItem.Header = stop.Name;
            }
        }