Exemplo n.º 1
0
        private void addStopLabels(MapPage page, List <IGrouping <GeoCoordinate, Stop> > mapPoints, double priorityLimit = double.MaxValue)
        {
            foreach (var position in mapPoints)
            {
                var stops = position.ToList();

                bool isCurrent = this.mainStops.Intersect(stops).Count() > 0;
                var  control   = StopPushpin.Create(position.Key, isCurrent, stops, this.dateTime, this.location, this.sourceStop, !isCurrent);
                if (control != null && control.Priority <= priorityLimit)
                {
                    this.addedPushpins.Add(control);
                    this.markedStops.UnionWith(stops);
                    control.StopClicked += (sender, stop) =>
                    {
                        page.NavigationService.Navigate(new Uri("/StopPage.xaml?id=" + stop.Group.ID + getPostQuery((sender as StopPushpin).IsDistanceIgnored), UriKind.Relative));
                    };
                    control.TripClicked += (sender, route) =>
                    {
                        StopGroup stop = route.Stop.Group;
                        string    uri  = null;
                        if (route.NextTripTime != null)
                        {
                            uri = String.Format("/TripPage.xaml?tripID={0}&routeID={1}&stopID={2}&nexttrips=true{3}",
                                                route.NextTrip.ID,
                                                route.NextTrip.Route.ID,
                                                stop.ID,
                                                getPostQuery((sender as StopPushpin).IsDistanceIgnored));
                        }
                        else
                        {
                            uri = "/TimetablePage.xaml?stopID=" + stop.ID + "&routeID=" + route.Route.ID;
                            if (dateTime != null)
                            {
                                uri += "&selectedTime=" + dateTime.ToString();
                            }
                        }
                        page.NavigationService.Navigate(new Uri(uri, UriKind.Relative));
                    };
                    //if (fromMainPage)
                    //{
                    //    control.Content.PlanningFromClicked += (sender, args) =>
                    //    {
                    //        MainPage.Current.SetPlanningSource(stops.First().Group);
                    //        page.NavigationService.GoBack();
                    //    };
                    //    control.Content.PlanningToClicked += (sender, args) =>
                    //    {
                    //        MainPage.Current.SetPlanningDestination(stops.First().Group);
                    //        page.NavigationService.GoBack();
                    //    };
                    //}

                    MapLayer mapLayer = new MapLayer();
                    mapLayer.Add(new MapOverlay()
                    {
                        GeoCoordinate  = Convert(position.Key),
                        PositionOrigin = new Point(0.5, 0.5),
                        Content        = control
                    });
                    page.Map.Layers.Insert(0, mapLayer);

                    Action currentTapAction = delegate()
                    {
                        if (!control.IsExpanded)
                        {
                            clearSelection();
                            control.ShowContent();
                            Selected = control;
                            page.Map.Layers.Remove(mapLayer);
                            page.Map.Layers.Add(mapLayer);
                        }
                    };
                    tapActions[control] = currentTapAction;
                    //control.Tap += (sender, args) =>
                    //{
                    //    currentTapAction();
                    //};
                }
            }
        }
Exemplo n.º 2
0
        private void addStopLabels(IMapControl page, IList <IGrouping <GeoCoordinate, Stop> > mapPoints, double priorityLimit = double.MaxValue)
        {
            foreach (var position in mapPoints.Reverse())
            {
                var stops = position.ToList();

                bool isCurrent = this.mainStops.Intersect(stops).Count() > 0;
                var  control   = StopPushpin.Create(page, position.Key, isCurrent, stops, this.dateTime, this.location, this.sourceStop, !isCurrent);
                if (control != null && control.Priority <= priorityLimit)
                {
                    this.addedPushpins.Add(control);
                    this.markedStops.UnionWith(stops);
                    control.StopClicked += (sender, stop) =>
                    {
                        if (StopGroupSelected != null)
                        {
                            StopGroupSelected(this, createStopGroupParam(stop.Group, (sender as StopPushpin).IsDistanceIgnored));
                        }
                    };
                    control.TripClicked += (sender, route) =>
                    {
                        StopGroup stop = route.Stop.Group;
                        if (route.NextTripTime != null)
                        {
                            if (TripSelected != null)
                            {
                                TripSelected(this, createTripParam(route.NextTrip, route.Stop, (sender as StopPushpin).IsDistanceIgnored));
                            }
                        }
                        else
                        {
                            if (TimeTableSelected != null)
                            {
                                TimeTableSelected(this, new TimetableParameter {
                                    Stop = stop, Route = route.Route, SelectedTime = dateTime
                                });
                            }
                        }
                    };
                    //if (fromMainPage)
                    //{
                    //    control.Content.PlanningFromClicked += (sender, args) =>
                    //    {
                    //        MainPage.Current.SetPlanningSource(stops.First().Group);
                    //        page.NavigationService.GoBack();
                    //    };
                    //    control.Content.PlanningToClicked += (sender, args) =>
                    //    {
                    //        MainPage.Current.SetPlanningDestination(stops.First().Group);
                    //        page.NavigationService.GoBack();
                    //    };
                    //}

                    //AddControlToMapAt(0, control, position.Key, new Point(0.5, 0.5));
                    AddControlToMap(control, position.Key, new Point(0.5, 0.5));

                    Action currentTappedAction = async delegate()
                    {
                        if (!control.IsExpanded)
                        {
                            clearSelection();
                            var popup = await control.ShowPopup();

                            AddControlToMap(popup, position.Key, new Point(0.5, 1));
                            Selected = control;
                            //BringControlToForeground(control);
                        }
                    };
                    tapActions[control] = currentTappedAction;
                    //control.Tapped += (sender, args) =>
                    //{
                    //    currentTappedAction();
                    //};
                }
            }
        }