예제 #1
0
        public async void Handle(ObservableCollection <Spostamento> message)
        {
            List <int>         toRemove = pushpinVecchietti.Keys.Except(message.Select(x => x.PartecipanteObj.IDSpostamento).ToList()).ToList();
            WaypointCollection wayColl  = new WaypointCollection();
            bool firstAdded             = false;

            while (MapLayer.GetPosition(posizioneAttuale) == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            wayColl.Add(new Waypoint(MapLayer.GetPosition(posizioneAttuale)));

            foreach (int idSpos in toRemove)
            {
                mappaBing.Children.Remove(pushpinVecchietti[idSpos]);
                pushpinVecchietti.Remove(idSpos);
            }

            foreach (Spostamento part in message)
            {
                if (pushpinVecchietti.ContainsKey(part.PartecipanteObj.IDSpostamento))
                {
                    if (part.PartecipanteObj.FKIDStato == 2)
                    {
                        pushpinVecchietti[part.PartecipanteObj.IDSpostamento].Template = this.Resources["DiscesaTemplate"] as ControlTemplate;
                    }
                    MapLayer.SetPosition(pushpinVecchietti[part.PartecipanteObj.IDSpostamento], new Location(part.Latitudine, part.Longitudine));
                }
                else
                {
                    pushpinVecchietti.Add(part.PartecipanteObj.IDSpostamento, CaricaVecchietti(part.Latitudine, part.Longitudine, part.PartecipanteObj.FKIDStato == 1));
                }
                if (!firstAdded)
                {
                    wayColl.Add(new Waypoint(MapLayer.GetPosition(pushpinVecchietti[part.PartecipanteObj.IDSpostamento])));
                    firstAdded = true;
                }
            }
            mappaBing.DirectionsManager.Waypoints = wayColl;
            mappaBing.DirectionsManager.CalculateDirectionsAsync();
        }
예제 #2
0
        public async void createRoute(List<Bing.Maps.Location> locs)
        {
            WaypointCollection col = new WaypointCollection();
            for (int i = 0; i < locs.Count; i = i + 2)
            {
                col.Add(new Waypoint(locs[i]));
                //System.Diagnostics.Debug.WriteLine("Lat: " + locs[i].Latitude);
                //System.Diagnostics.Debug.WriteLine("Lon: " + locs[i].Longitude);
            }
            //col.Add(new Waypoint(locs[0]));
            //col.Add(new Waypoint(locs[locs.Count - 1]));
            //foreach (Location loc in locs)
            //{
            //    col.Add(new Waypoint(loc));
            //    System.Diagnostics.Debug.WriteLine("Lat: " + loc.Latitude);
            //    System.Diagnostics.Debug.WriteLine("Lon: " + loc.Longitude);
            //}

            DirectionsManager manager = Map.DirectionsManager;
            manager.Waypoints = col;
            manager.RequestOptions.RouteMode = RouteModeOption.Walking;

            RouteResponse route_response = await manager.CalculateDirectionsAsync();
            route_response.Routes[0].RoutePath.LineColor = new Windows.UI.Color { A = 200, R = 0, B = 200, G = 0 };
            route_response.Routes[0].RoutePath.LineWidth = 10.0;
            manager.ShowRoutePath(route_response.Routes[0]);
            mc.Route = route_response.Routes[0];
        }
예제 #3
0
        public async void createRoute2(List<Bing.Maps.Location> locs)
        {
            double km = await getTotalDistanceKM(locs);
            int breakpoint;
            try
            {
                LocationCollection routePoints = new LocationCollection();
                WaypointCollection col = new WaypointCollection();

                for (int i = 0; i < locs.Count / 2; i++)
                {
                    col.Add(new Waypoint(locs[i]));
                }

                DirectionsManager manager = Map.DirectionsManager;
                manager.RequestOptions.RouteMode = RouteModeOption.Walking;
                manager.Waypoints = col;
                manager.RenderOptions.WaypointPushpinOptions.Visible = false;

                RouteResponse resp = await manager.CalculateDirectionsAsync();
                foreach (Bing.Maps.Location l in resp.Routes[0].RoutePath.PathPoints)
                {
                    routePoints.Add(l);
                }

                manager.Waypoints.Clear();
                col.Clear();

                for (int i = locs.Count / 2; i < locs.Count; i++)
                {
                    col.Add(new Waypoint(locs[i]));
                }

                manager.Waypoints = col;

                resp = await manager.CalculateDirectionsAsync();
                foreach (Bing.Maps.Location l in resp.Routes[0].RoutePath.PathPoints)
                {
                    routePoints.Add(l);
                }


                MapPolyline line = new MapPolyline { Locations = routePoints };
                line.Color = new Windows.UI.Color { A = 50, R = 0, G = 0, B = 200 };
                line.Width = 10.0;

                RouteLayer.Shapes.Add(line);
                mc.pathLocations = routePoints;
                Map.ShapeLayers.Add(RouteLayer);
            }
            catch(Exception d)
            {
                System.Diagnostics.Debug.WriteLine(d);
                showInternetPopup();
            }
        }
예제 #4
0
        public async Task calculateRoute(List<WeBreda.Model.Waypoint> wpList)
        {
            routeCollection.Clear();
            directionsManager.Waypoints.Clear();
            WaypointCollection wpCollection = new WaypointCollection();

            foreach (WeBreda.Model.Waypoint wp in wpList)
            {
                Bing.Maps.Directions.Waypoint bingwp = new Bing.Maps.Directions.Waypoint(new Location()
                {
                    Latitude = wp.Latitude,
                    Longitude = wp.Longitude
                });

                Debug.Print(wp.Latitude + " " + wp.Longitude);

                directionsManager.Waypoints.Add(bingwp);
                wpCollection.Add(bingwp);
 
                if (directionsManager.Waypoints.Count > 4)
                {
                    Bing.Maps.Directions.RouteResponse response = await directionsManager.CalculateDirectionsAsync();
                    if (response.Routes.Count > 0)
                    {
                        Bing.Maps.Directions.Route route = response.Routes[0];
                        routeCollection.Add(route);
                        waypointCollectionList.Add(wpCollection);
                        wpCollection = new WaypointCollection();
                        directionsManager.Waypoints.Clear();
                        directionsManager.Waypoints.Add(bingwp);
                        wpCollection.Add(bingwp);
                    }
                }
            }

            drawRouteLine(wpList);
            routeIndex = control.currentRoute.RouteIndex;
            directionsManager.ActiveRoute = routeCollection[routeIndex];
            routeCalculated = true;
        }
예제 #5
0
 private void OnEnable()
 {
     WayPoints.Add(this);
 }