Esempio n. 1
0
        private void RemoveRoute_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var  button  = sender as Button;
            Guid LocalId = (Guid)button.Tag;

            RoutesOfPointOfInterest rpoi = ViewModel.syncRoutes.Single(p => p.LocalId == LocalId);

            if (rpoi != null)
            {
                rpoi.ToRemove = true;
                ViewModel.PlacesOrRoutesAreUpdated = true;
                RemoveRouteOnMap(rpoi);
            }
            Sync();
        }
Esempio n. 2
0
        private async void ZoomToRoute_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var  button  = sender as Button;
            Guid LocalId = (Guid)button.Tag;

            RoutesOfPointOfInterest rpoi = ViewModel.syncRoutes.Single(p => p.LocalId == LocalId);

            if (rpoi != null)
            {
                // Fit the MapControl to the route.
                await myMap.TrySetViewBoundsAsync(
                    rpoi.ViewOfRoute.Route.BoundingBox,
                    null,
                    Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
            }
        }
Esempio n. 3
0
        private async void AddRoute_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Errors.Clear();
            if (Start == null || End == null)
            {
                Errors.Add("Start or End is null");
                return;
            }
            if (Start.TravelPointOfInterestID == End.TravelPointOfInterestID)
            {
                Errors.Add("Start and End can't be the same");
                return;
            }
            RoutesOfPointOfInterest newRoute = new RoutesOfPointOfInterest();

            newRoute.TravelListItemID             = ViewModel.TravelListItemID;
            newRoute.StartTravelPointOfInterestID = Start.TravelPointOfInterestID;
            newRoute.Start = Start;
            newRoute.EndTravelPointOfInterestID = End.TravelPointOfInterestID;
            newRoute.End     = End;
            newRoute.Driving = SelectedRouteType.Equals(RouteTypes.Driving);
            newRoute.IsNew   = true;

            App.ViewModel.SetLoader();

            bool result = await ShowRouteOnMap(newRoute);

            if (result)
            {
                ViewModel.syncRoutes.Add(newRoute);
                ViewModel.PlacesOrRoutesAreUpdated = true;
                Sync();
            }
            else
            {
                Errors.Add("Route not found");
            }

            App.ViewModel.SetLoader();
        }
Esempio n. 4
0
 private void RemoveRouteOnMap(RoutesOfPointOfInterest route)
 {
     // Add the new MapRouteView to the Routes collection
     // of the MapControl.
     myMap.Routes.Remove(route.ViewOfRoute);
 }
Esempio n. 5
0
        private async Task <bool> ShowRouteOnMap(RoutesOfPointOfInterest route)
        {
            // Start.
            BasicGeoposition startLocation = new BasicGeoposition()
            {
                Latitude = (double)route.Start.Latitude, Longitude = (double)route.Start.Longitude
            };

            // End.
            BasicGeoposition endLocation = new BasicGeoposition()
            {
                Latitude = (double)route.End.Latitude, Longitude = (double)route.End.Longitude
            };


            // Get the route between the points.
            MapRouteFinderResult routeResult = null;

            if (route.Driving)
            {
                routeResult =
                    await MapRouteFinder.GetDrivingRouteAsync(
                        new Geopoint(startLocation),
                        new Geopoint(endLocation),
                        MapRouteOptimization.Time,
                        MapRouteRestrictions.None);
            }
            else
            {
                routeResult =
                    await MapRouteFinder.GetWalkingRouteAsync(
                        new Geopoint(startLocation),
                        new Geopoint(endLocation));
            }

            if (routeResult.Status == MapRouteFinderStatus.Success)
            {
                // Use the route to initialize a MapRouteView.
                MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
                if (route.Driving)
                {
                    viewOfRoute.RouteColor   = Colors.Yellow;
                    viewOfRoute.OutlineColor = Colors.Black;
                }
                else
                {
                    viewOfRoute.RouteColor   = Colors.Blue;
                    viewOfRoute.OutlineColor = Colors.Black;
                }

                // Assign viewOfRoute to Route object
                route.ViewOfRoute = viewOfRoute;

                // Add the new MapRouteView to the Routes collection
                // of the MapControl.
                myMap.Routes.Add(viewOfRoute);

                // Fit the MapControl to the route.
                await myMap.TrySetViewBoundsAsync(
                    routeResult.Route.BoundingBox,
                    null,
                    Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);

                return(true);
            }
            else
            {
                return(false);
            }
        }