private void DrawPolygonOnBingMap(List <Node> route, Color color) { MapPolyline polygon = new MapPolyline(); polygon.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent); polygon.Stroke = new System.Windows.Media.SolidColorBrush(color); polygon.StrokeThickness = 5; polygon.Opacity = 0.7; LocationCollection path = new LocationCollection(); for (int i = 0; i < route.Count - 2; i++) { if (alg.NodeDistancesDisjkstry[route.ElementAt(i).Position, route.ElementAt(i + 1).Position] == 0) { Dijkstry di = new Dijkstry(incidenceList); int[] pathSD = di.GetPath(route.ElementAt(i).Position, route.ElementAt(i + 1).Position); List <Node> dijkstryPath = new List <Node>(); if (pathSD != null) { //convert from int[] to List<Node> foreach (var p in pathSD) { foreach (var n in alg.NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } foreach (var p in dijkstryPath) { path.Add(new Location(p.Y, p.X)); } } } else { path.Add(new Location(route.ElementAt(i).Y, route.ElementAt(i).X)); } } foreach (var node in route) { path.Add(new Location(node.Y, node.X)); } path.Add(path.ElementAt(0)); //i do punktu poczatkowego polygon.Locations = path; bingMap.Children.Add(polygon); }
//Dijkstry path private void MenuItem_Click_6(object sender, RoutedEventArgs e) { int SRC = 0; int DST = 0; DijkstryWindow dq = new DijkstryWindow(alg); dq.ShowDialog(); if (dq.DialogResult == true) { SRC = dq.FROM; DST = dq.TO; Dijkstry di = new Dijkstry(incidenceList); List <Node> dijkstryPath = new List <Node>(); int[] path = di.GetPath(SRC, DST); if (path != null) { //convert from int[] to List<Node> foreach (var p in path) { foreach (var n in alg.NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } if (what == true) { canvas.Children.Clear(); DrawPoints(); DrawRoute(dijkstryPath, Brushes.Red); } else { DrawRouteOnBingMap(dijkstryPath, Colors.Red, true); } } else { MessageBox.Show("Niespójność danych, trasa nie istnieje", "Błąd danych wejściowych", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public List <Node> getDijkstryNodes(int src, int dst) { Dijkstry di = new Dijkstry(incidenceList); List <Node> dijkstryPath = new List <Node>(); int[] path = di.GetPath(src, dst); if (path != null) { //convert from int[] to List<Node> foreach (var p in path) { foreach (var n in NodesList) { if (n.Position == p) { dijkstryPath.Add(n); break; } } } } return(dijkstryPath); }