Exemple #1
0
        // public RouteViewModel(VoyageDto voyage, IEnumerable<maps.RouteService.ItineraryItem> itinerary)
        public RouteViewModel(VoyageDto voyage, IEnumerable<maps.RouteService.Location> points)
        {
            Locations = new ObservableCollection<Location_Reference>();

            foreach (var point in points)
            {
                Locations.Add(new Location_Reference(new Microsoft.Maps.MapControl.Location { Latitude = point.Latitude, Longitude = point.Longitude }));

            }
        }
        protected void Refresh_Routes_Old()
        {
            if (SelectedSimulation == null)
            {
                SelectedSimulation = new SimulationDto {  Voyages = new ObservableCollection<VoyageDto>() };
                SelectedSimulation.Starting_Address = "Home";
                SelectedSimulation.Returning_Address = "Home";

                SelectedSimulation.Starting_Latitude =   44.1383781433105;
                SelectedSimulation.Starting_Longitude =   12.2387800216675;
                SelectedSimulation.Returning_Latitude =  44.1383781433105;
                SelectedSimulation.Returning_Longitude = 12.2387800216675;

                for (int i = 0; i < 1; i++)
                {
                    var v = new VoyageDto() { Orders = new ObservableCollection<int>() };
                    foreach(var order in Scenario.Orders)
                        v.Orders.Add(order.Number);

                    v.Departing = DateTime.Today.AddDays(1);
                    v.Exitmated_Time = TimeSpan.FromDays(1);
                    v.Extimated_Lenght_Km = 12;

                    SelectedSimulation.Voyages.Add(v);
                }
                Simulations.Add(SelectedSimulation);
            }

            var service = maps.ServiceHelper.GetRouteService();
            service.CalculateRouteCompleted += (sender, e) =>
            {
                var voyage = e.UserState as VoyageDto;

                Routes.Add(new RouteViewModel(voyage, e.Result.Result.RoutePath.Points));
            };

            foreach (var route in SelectedSimulation.Voyages)
            {
                var wp = route.Orders.Select(v => new maps.RouteService.Waypoint
                    {
                        Description = v + "",
                        Location = new maps.RouteService.Location { Latitude = GetOrder(v).Latitude, Longitude = GetOrder(v).Longitude }
                    }).To_ObservableCollection();

                wp.Add(new maps.RouteService.Waypoint { Description = SelectedSimulation.Starting_Address, Location = new maps.RouteService.Location { Latitude = SelectedSimulation.Starting_Latitude, Longitude= SelectedSimulation.Starting_Longitude } });
                //wp.Add(new maps.RouteService.Waypoint { Description = SelectedSimulation.Returning_Address, Location = new maps.RouteService.Location { Latitude = SelectedSimulation.Returning_Latitude, Longitude =SelectedSimulation.Returning_Longitude } });

                var request = new maps.RouteService.RouteRequest
                {
                    Credentials = new maps.RouteService.Credentials() { Token = maps.ServiceHelper.GeocodeServiceCredentials },
                    Culture = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString(),
                    Waypoints = wp

                };
                request.Options = new maps.RouteService.RouteOptions();
                request.Options.RoutePathType = maps.RouteService.RoutePathType.Points;

                service.CalculateRouteAsync(request, route);
            }
        }
        protected void Refresh_Routes()
        {
            if (SelectedSimulation == null)
            {
                SelectedSimulation = new SimulationDto {  Voyages = new ObservableCollection<VoyageDto>() };
                SelectedSimulation.Starting_Address = "Home";
                SelectedSimulation.Returning_Address = "Home";

                SelectedSimulation.Starting_Latitude =   44.1383781433105;
                SelectedSimulation.Starting_Longitude =   12.2387800216675;
                SelectedSimulation.Returning_Latitude =  44.1383781433105;
                SelectedSimulation.Returning_Longitude = 12.2387800216675;

                for (int i = 0; i < 1; i++)
                {
                    var v = new VoyageDto() { Orders = new ObservableCollection<int>() };
                    foreach(var order in Scenario.Orders)
                        v.Orders.Add(order.Number);

                    v.Departing = DateTime.Today.AddDays(1);
                    v.Exitmated_Time = TimeSpan.FromDays(1);
                    v.Extimated_Lenght_Km = 12;

                    SelectedSimulation.Voyages.Add(v);
                }
                Simulations.Add(SelectedSimulation);
            }

            var calculator = new BingRouteCalculator();
            calculator.Set_Starting_Point(SelectedSimulation.Starting_Latitude, SelectedSimulation.Starting_Longitude);
            calculator.Set_Ending_Point(SelectedSimulation.Returning_Latitude, SelectedSimulation.Returning_Longitude);

            foreach (var spot in SelectedSimulation.Voyages)
            {
                foreach(var orderId in spot.Orders)
                {
                    var order = GetOrder(orderId);
                    calculator.Add_Tour(order.Latitude, order.Longitude);
                }
            }

            var scheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();

            calculator.Calculate_Routes()
                .ContinueWith((t) =>
                {
                    var results = calculator.Result.ToList();

                    Routes.Add(new RouteViewModel(null, results.Select(r => new maps.RouteService.Location { Latitude = r.Latitude, Longitude = r.Longitude })));
                }, scheduler);
        }