Exemplo n.º 1
0
        public override async void Bind(MapPage page)
        {
            base.Bind(page);
            base.RegisterElementTypes(typeof(PlanItemPopup), typeof(Ellipse));

            Way selected = PlanningTab.Current.SelectedWay.Way;

            double north = double.MinValue, west = double.MaxValue, south = double.MaxValue, east = double.MinValue;

            foreach (var item in selected)
            {
                Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline
                {
                    StrokeColor     = item.Route.RouteGroup.GetColors().MainColor,
                    StrokeThickness = 8
                };

                foreach (var x in item.ShapePoints)
                {
                    line.Path.Add(Convert(x));
                    north = Math.Max(north, x.Latitude);
                    east  = Math.Max(east, x.Longitude);
                    south = Math.Min(south, x.Latitude);
                    west  = Math.Min(west, x.Longitude);
                }
                page.Map.MapElements.Add(line);

                //Microsoft.Phone.Maps.Controls.MapLayer mapLayer = new Microsoft.Phone.Maps.Controls.MapLayer();
                //mapLayer.Add(new MapOverlay()
                //{
                //    GeoCoordinate = line.Path[line.Path.Count / 2],
                //    Content = new Pushpin() { Content = item.Route.RouteGroup.Name + " - " + item.Route.Name }
                //});
                //Map.Layers.Add(mapLayer);

                PutStopCircle(page, item.Route, item.StartStop, item.StartTime, item.StopCount, item == selected.First() ? PlanItemPopupType.Start : PlanItemPopupType.MidStart);
                PutStopCircle(page, item.Route, item.EndStop, item.EndTime, item.StopCount, item == selected.Last() ? PlanItemPopupType.Finish : PlanItemPopupType.MidFinish);
            }

            this.EmptyMapTap   += (sender, args) => closePopups(page);
            this.MapElementTap += (sender, element) =>
            {
                if (element is Ellipse)
                {
                    tapActions[(Ellipse)element].Invoke();
                }
            };

            await Task.Delay(250);

            page.Map.SetView(new LocationRectangle(north, west, south, east), MapAnimationKind.None);
        }
Exemplo n.º 2
0
        public override async void Bind(MapPage page)
        {
            base.Bind(page);
            base.RegisterElementTypes(typeof(TripStopPopup), typeof(Ellipse));

            var trip = App.Model.GetTripByID(
                int.Parse(page.NavigationContext.QueryString["tripId"]),
                int.Parse(page.NavigationContext.QueryString["routeId"])
                );
            var      routeGroup = trip.Route.RouteGroup;
            int      position   = int.Parse(page.NavigationContext.QueryString["position"]);
            DateTime dateTime   = DateTime.Parse(page.NavigationContext.QueryString["dateTime"]);

            Microsoft.Phone.Maps.Controls.MapPolyline line = new Microsoft.Phone.Maps.Controls.MapPolyline
            {
                StrokeColor     = trip.Route.RouteGroup.GetColors().MainColor,
                StrokeThickness = 8
            };
            Way.Entry entry = new Way.Entry(trip.TripType);
            line.Path.AddRange(entry.ShapePoints.Select(c => Convert(c)));
            page.Map.MapElements.Add(line);

            int i     = 0;
            var stops = trip.Stops;

            foreach (var stop in stops)
            {
                MapLayer mapLayer = new MapLayer();
                var      content  = new Ellipse
                {
                    Fill            = new SolidColorBrush(i == 0 ? routeGroup.GetColors().SecondaryColorBrush.Color : i == position ? Colors.White : i < position ? routeGroup.GetColors().PrimaryColorBrush.Color : Colors.White),
                    Stroke          = trip.Route.RouteGroup.GetColors().MainColorBrush,
                    StrokeThickness = 3,
                    Width           = 26,
                    Height          = 26
                };
                mapLayer.Add(new MapOverlay()
                {
                    GeoCoordinate  = Convert(stop.Item2.Coordinate),
                    PositionOrigin = new Point(0.5, 0.5),
                    Content        = content
                });
                page.Map.Layers.Add(mapLayer);

                int curPos = i;
                tapActions[content] = delegate()
                {
                    clearOpenedOpopup(page);

                    var popupContent = new TripStopPopup();
                    popupContent.Initialize(trip, curPos, stops[position].Item1);
                    popupContent.StopClick += (sender1, clickedStop) =>
                    {
                        string uri = String.Format("/StopPage.xaml?id={0}&dateTime={1}&location={2}", clickedStop.Group.ID, dateTime + stops[curPos].Item1 - stops[position].Item1, clickedStop.ID);
                        page.NavigationService.Navigate(new Uri(uri, UriKind.Relative));
                    };
                    MapLayer popupLayer = new MapLayer();
                    popupLayer.Add(new MapOverlay()
                    {
                        GeoCoordinate  = Convert(stop.Item2.Coordinate),
                        PositionOrigin = new Point(0.5, 1),
                        Content        = popupContent
                    });
                    currentPopupLayer = popupLayer;
                    page.Map.Layers.Add(popupLayer);
                };

                i++;
            }

            this.EmptyMapTap   += (sender, args) => clearOpenedOpopup(page);
            this.MapElementTap += (sender, element) =>
            {
                if (element is Ellipse)
                {
                    tapActions[(Ellipse)element].Invoke();
                }
            };

            var boundaries = GetBoundaries(stops.Select(s => Convert(s.Item2.Coordinate)));
            await Task.Delay(250);

            page.Map.SetView(boundaries, MapAnimationKind.None);
        }