MapForm.xaml.cs 1.6 KB

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