MatchView.xaml.cs 1.4 KB

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