MapForm.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Media;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.Wpf;
  10. using Syncfusion.UI.Xaml.Maps;
  11. using Syncfusion.Windows.PdfViewer;
  12. using Syncfusion.XlsIO.Implementation.PivotTables;
  13. using Point = System.Windows.Point;
  14. namespace PRSDesktop.Forms
  15. {
  16. /// <summary>
  17. /// Interaction logic for MapForm.xaml
  18. /// </summary>
  19. public partial class MapForm : ThemableWindow
  20. {
  21. private double _zoom = 18.0;
  22. public MapForm(double latitude, double longitude, GeoFenceDefinition? geofence = null, DateTime? timestamp = null)
  23. {
  24. InitializeComponent();
  25. var geopoint = new GeoPoint(latitude, longitude);
  26. if (geofence?.Coordinates.Any() == true)
  27. Polygon.Points = new ObservableCollection<Point>(geofence.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
  28. else
  29. {
  30. var circle = new MapCircle();
  31. circle.Center = new Point(latitude, longitude);
  32. circle.Radius = 25;
  33. circle.Fill = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
  34. subLayer.MapElements.Add(circle);
  35. }
  36. // var fences = Client.Query<GeoFence>().ToArray<GeoFence>();
  37. // foreach (var fence in fences)
  38. // {
  39. // var def = Serialization.Deserialize<GeoFenceDefinition>(fence.Geofence) ?? new GeoFenceDefinition();
  40. // if (def.Contains(geopoint))
  41. // {
  42. // Polygon.Points = new ObservableCollection<Point>(def.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
  43. // break;
  44. // }
  45. // }
  46. if (timestamp.HasValue)
  47. TimeStamp.Content = $"Last Updated {timestamp:dd MMM yyy hh:mm:ss tt}";
  48. else
  49. TimeStamp.Visibility = Visibility.Collapsed;
  50. ImageryLayer.Center = new Point(latitude,longitude);
  51. }
  52. private void ZoomIn_OnClick(object sender, RoutedEventArgs e)
  53. {
  54. Map.MaxZoom = Math.Min(20, Map.ZoomLevel + 1);
  55. Map.ZoomLevel = Math.Min(20, Map.ZoomLevel + 1);
  56. }
  57. private void ZoomOut_OnClick(object sender, RoutedEventArgs e)
  58. {
  59. Map.MinZoom= Math.Max(5, Map.ZoomLevel - 1);
  60. Map.ZoomLevel = Math.Max(5, Map.ZoomLevel - 1);
  61. }
  62. }
  63. }