/// <summary> /// /// </summary> /// <param name="points"></param> private void DrawRoute(List<Location> points) { MapShapeLayer shapeLayer = new MapShapeLayer(); MapPolyline polyline = new MapPolyline(); LocationCollection lc = new LocationCollection(); foreach (Location p in points) { lc.Add(p); } polyline.Locations = lc; polyline.Color = Color.FromArgb(255, 102, 0, 0); polyline.Width = 5; shapeLayer.Shapes.Add(polyline); Map.ShapeLayers.Clear(); Map.ShapeLayers.Add(shapeLayer); Location midpoint = new Location(lc.FirstOrDefault().Latitude + ((lc.LastOrDefault().Latitude - lc.FirstOrDefault().Latitude) / 2.0), lc.FirstOrDefault().Longitude + ((lc.LastOrDefault().Longitude - lc.FirstOrDefault().Longitude) / 2.0)); Map.SetView(midpoint, 15.5F); }
private void Pushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e) { // Def Polyline: this.Polyline = new MapPolyline(); this.Polyline.Stroke = new SolidColorBrush(Colors.Red); // stroke; this.Polyline.StrokeThickness = 5; // strokeThinkness; this.Polyline.Opacity = 0.7; // opacity; var pushpin = sender as Pushpin; var locationsList = new LocationCollection(); List<GeoCoordinate> thisWayCoordinates = new List<GeoCoordinate>(); GeoCoordinate routeLoc = pushpin.Location; if (routeLoc == LocationManager.GetCurrentLocation()) { } else { RouteDesign routeDesign = this.ViewModel.NearbyRoutesCollection.Where(c => (c.Route.AllCoordinate[0] == pushpin.Location)).FirstOrDefault(); if (routeDesign.Draw == false) { thisWayCoordinates = routeDesign.Route.AllCoordinate; foreach (GeoCoordinate coor in thisWayCoordinates) { locationsList.Add(coor); } Polyline.Locations = locationsList; RouteBingMap.Children.Add(Polyline); RouteBingMap.SetView(locationsList.FirstOrDefault(), 15); // informations: double wayDistance = 0; for (int i = 0; i <= thisWayCoordinates.Count - 2; i++) { wayDistance += (thisWayCoordinates[i]).GetDistanceTo(thisWayCoordinates[i + 1]); } //ToolTipService.SetToolTip(pushpin, "The route length:" + wayDistance); // RouteBingMap.Children.Add(pushpin); ContextMenu contextMenu = ContextMenuService.GetContextMenu(pushpin); // contextMenu.DataContext = "llll"; contextMenu.DataContext = this.ViewModel.NearbyRoutesCollectionAndMe.Where(c => (c.Route.AllCoordinate[0] == pushpin.Location)).FirstOrDefault(); //RouteDesign r = (RouteDesign)(contextMenu.DataContext = this.ViewModel.NearbyRoutesCollectionAndMe.Where(c => (c.Route.AllCoordinate[0] == pushpin.Location)).FirstOrDefault()); if (contextMenu.Parent == null) { if (Open == "true") { Open = "false"; RouteView.Visibility = Visibility.Collapsed; } contextMenu.IsOpen = true; } // ToolTip t = new ToolTip(); // t = (ToolTip)ToolTipService.GetToolTip(pushpin); //// t.DataContext = this.ViewModel.NearbyRoutesCollectionAndMe.Where(c => (c.Route.AllCoordinate[0] == pushpin.Location)).FirstOrDefault(); // t.IsOpen = true; // ToolTip t; // t = new ToolTip(); //// t.Content = "The route length:" + wayDistance; // t.FontSize = 20; // t.DataContext="ttttttttttttttttttttt"+(this.ViewModel.NearbyRoutesCollectionAndMe.Where(c => (c.Route.AllCoordinate[0] == pushpin.Location)).FirstOrDefault()).Route.WayDistance.ToString(); // t.FontSize = 20; // t.IsOpen = true; // t.Visibility = Visibility.Visible; // MessageBox.Show("The route length:" + wayDistance); } } }