private void Button_Click_1(object sender, RoutedEventArgs e) { if (sender == Hplus) { map1.Heading = (map1.Heading + 12); } else if (sender == Hmins) { map1.Heading = (map1.Heading - 12); } else if (sender == TrMod) { if (RTrav == TravelMode.Driving) { RTrav = TravelMode.Walking; TrMod.Content = "Walk"; } else { RTrav = TravelMode.Driving; TrMod.Content = "Drive"; } } else if (sender == Optim) { if (ROpti == RouteOptimization.MinimizeTime) { ROpti = RouteOptimization.MinimizeDistance; Optim.Content = "Shortest"; } else { ROpti = RouteOptimization.MinimizeTime; Optim.Content = "Quickest"; } } else if (sender == Rutte) { if (geoQ.IsBusy == true) { geoQ.CancelAsync(); } geoQ.InitialHeadingInDegrees = map1.Heading; geoQ.RouteOptimization = ROpti; geoQ.TravelMode = RTrav; List <GeoCoordinate> MyWayPoints = new List <GeoCoordinate>(); MyWayPoints.Add(startMark.GeoCoordinate); MyWayPoints.Add(enddMark.GeoCoordinate); geoQ.Waypoints = MyWayPoints; geoQ.QueryAsync(); } }
private void CalculateRoute(double latitudeA, double longitudeA, double latitudeB, double longitudeB, Color color) { RouteQuery geoQ = new RouteQuery(); geoQ.QueryCompleted += geoQ_QueryCompleted; if (geoQ.IsBusy == true) { geoQ.CancelAsync(); } List<GeoCoordinate> MyWayPoints = new List<GeoCoordinate>(); MyWayPoints.Add(new GeoCoordinate(latitudeA,longitudeA)); MyWayPoints.Add(new GeoCoordinate(latitudeB, longitudeB)); geoQ.Waypoints = MyWayPoints; geoQ.QueryAsync(); }
private async void ShufflePoints(object sender, EventArgs e) { if (Enabled) { MessageBoxResult m; if (MyCoordinates.Count < 2) { MessageBox.Show("You add too small number of map points!"); } else { if (MyCoordinates.Count < 3) { dot = 1; EnableAppButtons(false); calculate.Text = "Stop"; calculate.IconUri = new Uri("/Images/dark.transport.stop.png", UriKind.Relative); calculate.IsEnabled = true; if (MyMapRoute != null) { MyMap.RemoveRoute(MyMapRoute); } List <GeoCoordinate> tmp = DeepCopy(MyCoordinates); tmp.Add(MyCoordinates[0]); Navigate(tmp); } else { m = MessageBox.Show("Do you want find best optimal path?", "Starting shuffle", MessageBoxButton.OKCancel); if (m == MessageBoxResult.OK) { EnableAppButtons(false); calculate.IsEnabled = true; calculate.Text = "Stop"; calculate.IconUri = new Uri("/Images/dark.transport.stop.png", UriKind.Relative); shuffle = true; Algorithm A = new Algorithm(MyCoordinates); List <int> Result = new List <int>(); try { Result = await Task.Run(() => { thread = Thread.CurrentThread; return(A.Start()); }, Cts.Token); string Message = "Found route:\n"; for (int i = 0; i < Result.Count; i++) { Message += (Result[i] + 1) + " "; } Message += "\nDo You want accept changes?"; m = MessageBox.Show(Message, "Do You want accept new route?", MessageBoxButton.OKCancel); if (m == MessageBoxResult.OK) { for (int i = 0; i < MyCoordinates.Count; i++) { if (i != Result[i]) { SwapGeoPositions(i, Result[i]); int k = -1; for (int j = 0; j < Result.Count; j++) { if (i == Result[j]) { k = j; break; } } int tmp2 = Result[i]; Result[i] = Result[k]; Result[k] = tmp2; } } if (MyMapRoute != null) { MyMap.RemoveRoute(MyMapRoute); } MyMap.Layers.Clear(); AddAllPushpins(); } shuffle = false; dot = 1; List <GeoCoordinate> tmp = DeepCopy(MyCoordinates); tmp.Add(MyCoordinates[0]); Navigate(tmp); } catch (ThreadAbortException ex) { } } else { EnableAppButtons(false); calculate.Text = "Stop"; calculate.IconUri = new Uri("/Images/dark.transport.stop.png", UriKind.Relative); calculate.IsEnabled = true; if (MyMapRoute != null) { MyMap.RemoveRoute(MyMapRoute); } List <GeoCoordinate> tmp = DeepCopy(MyCoordinates); tmp.Add(MyCoordinates[0]); Navigate(tmp); } } } } else { if (shuffle) { Cts.Cancel(); thread.Abort(); calculate.Text = "Find cycle"; calculate.IconUri = new Uri("/Images/dark.shuffle.png", UriKind.Relative); EnableAppButtons(true); } else { MyQuery.CancelAsync(); calculate.Text = "Find cycle"; calculate.IconUri = new Uri("/Images/dark.shuffle.png", UriKind.Relative); EnableAppButtons(true); } } }