Exemple #1
0
        public ItineraryStep(GoogleApisLib.GoogleMapsApi.DirectionsStep item, int stepNumber)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            this.GeoCoordinate = item.start_location.AsGeoCoordinate();
            this.Instruction = item.instructions ?? item.html_instructions;
            this.TravelMode = item.travel_mode.ToString();
            this.BusNumber = item.transit != null ? item.transit.headsign : string.Empty;
            this.IconType = "bus";
            //this.StartTime = item.Time;
            //this.EndTime = item.Time;

            this._stepNumber = stepNumber;

            this.ChildItinerarySteps = new ObservableCollection<ItineraryStep>();
            //if (item.ChildItineraryItems != null)
            //{
            //    this.StartTime = item.ChildItineraryItems[0].Time;
            //    this.EndTime = item.ChildItineraryItems[item.ChildItineraryItems.Length - 1].Time;
            //    foreach (var itemStep in item.ChildItineraryItems)
            //    {
            //        this.ChildItinerarySteps.Add(new ItineraryStep(itemStep, 0));
            //    }
            //}
        }
        public TransitDescription(GoogleApisLib.GoogleMapsApi.DirectionsRoute route, DirectionType transitType)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }

            this.TransitType = transitType;
            this.StartLocation = route.legs[0].start_location.AsGeoCoordinate();
            this.EndLocation = route.legs[0].end_location.AsGeoCoordinate();
            this.TravelDuration = route.legs[0].duration.value;
            //this.ArrivalTime = route.legs[0].arrival_time.ToShortTimeString();
            //this.DepartureTime = route.legs[0].StartTime.ToShortTimeString();

            // TODO: need to add endpoint to the step list?
            this.ItinerarySteps = new ObservableCollection<ItineraryStep>();
            var stepNumber = 0;
            foreach (var topLeg in route.legs[0].steps)
            {
                this.ItinerarySteps.Add(new ItineraryStep(topLeg, ++stepNumber));

                // calculate the walking start and end times
                ////if (this.ItinerarySteps[stepNumber - 1].IconType == "Walk")
                ////{
                ////    if (stepNumber == 1)
                ////    {
                ////        // WalkOnly directions needs to be set a default time. Using current time
                ////        this.ItinerarySteps[stepNumber - 1].StartTime = this.TransitType == DirectionType.WalkOnly ? DateTime.Now : route.RouteLegs[0].StartTime;
                ////    }
                ////    else
                ////    {
                ////        this.ItinerarySteps[stepNumber - 1].StartTime = this.ItinerarySteps[stepNumber - 2].EndTime;
                ////    }

                ////    this.ItinerarySteps[stepNumber - 1].EndTime = this.ItinerarySteps[stepNumber - 1].StartTime + TimeSpan.FromSeconds(topLeg.TravelDuration);
                ////}
            }

            this.ItinerarySteps[0].StepType = ItineraryStep.ItineraryStepType.FirstStep;
            this.ItinerarySteps[this.ItinerarySteps.Count - 1].StepType = ItineraryStep.ItineraryStepType.LastStep;

            // check the first and last step for generic strings to replace
            // TODO: need a better place to put this
            this.ItinerarySteps[0].Instruction = this.ItinerarySteps[0].Instruction.Replace(SR.SourceLocation, ViewModelLocator.MainMapViewModelStatic.StartLocationText);
            this.ItinerarySteps[this.ItinerarySteps.Count - 1].Instruction = this.ItinerarySteps[this.ItinerarySteps.Count - 1].Instruction.Replace(SR.DestinationLocation, ViewModelLocator.MainMapViewModelStatic.EndLocationText);

            List<Point> lp = new List<Point>();
            foreach (var p in route.overview_polyline.DecodePolyline())
            {
                lp.Add(new Point(p.lat, p.lng));
            }

            this.PathPoints = lp.ToArray();

            this.MapView = new LocationRect(
                route.bounds.northeast.lat,
                route.bounds.southwest.lng,
                route.bounds.southwest.lat,
                route.bounds.northeast.lng);
        }