MatchView.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Threading.Tasks;
  3. using Windows.Devices.Geolocation;
  4. using Windows.UI;
  5. using Windows.UI.Xaml.Controls;
  6. using Windows.UI.Xaml.Controls.Maps;
  7. using YJMPD_UWP.Helpers;
  8. using YJMPD_UWP.ViewModels;
  9. namespace YJMPD_UWP.Views
  10. {
  11. public sealed partial class MatchView : Page
  12. {
  13. MatchVM matchvm;
  14. MapIcon pos;
  15. Geoposition old;
  16. public MatchView()
  17. {
  18. matchvm = new MatchVM();
  19. this.DataContext = matchvm;
  20. this.InitializeComponent();
  21. pos = new MapIcon();
  22. pos.Title = "You";
  23. pos.ZIndex = 100;
  24. App.Geo.OnPositionUpdate += Geo_OnPositionUpdate;
  25. }
  26. private void Geo_OnPositionUpdate(object sender, Helpers.EventArgs.PositionUpdatedEventArgs e)
  27. {
  28. Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
  29. {
  30. pos.Location = e.Position.Coordinate.Point;
  31. if (!Map.MapElements.Contains(pos))
  32. Map.MapElements.Add(pos);
  33. if(old != null && !App.Game.Selected)
  34. {
  35. Map.MapElements.Add(Util.GetRouteLine(old.Coordinate.Point.Position, e.Position.Coordinate.Point.Position, Color.FromArgb(255, 200, 50, 50), 50));
  36. }
  37. old = e.Position;
  38. ZoomMap(e.Position.Coordinate.Point);
  39. });
  40. }
  41. private async void ZoomMap(Geopoint p)
  42. {
  43. await Task.Delay(TimeSpan.FromMilliseconds(200));
  44. await Map.TrySetViewAsync(p);
  45. await Task.Delay(TimeSpan.FromMilliseconds(500));
  46. await Map.TryZoomToAsync(13);
  47. }
  48. }
  49. }