MapForm.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, GeoFenceDefinition? geofence = null, DateTime? timestamp = null)
  20. {
  21. InitializeComponent();
  22. var geopoint = new GeoPoint(latitude, longitude);
  23. if (geofence != null)
  24. Polygon.Points = new ObservableCollection<Point>(geofence.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
  25. // var fences = Client.Query<GeoFence>().ToArray<GeoFence>();
  26. // foreach (var fence in fences)
  27. // {
  28. // var def = Serialization.Deserialize<GeoFenceDefinition>(fence.Geofence) ?? new GeoFenceDefinition();
  29. // if (def.Contains(geopoint))
  30. // {
  31. // Polygon.Points = new ObservableCollection<Point>(def.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
  32. // break;
  33. // }
  34. // }
  35. if (timestamp.HasValue)
  36. TimeStamp.Content = $"Last Updated {timestamp:dd MMM yyy hh:mm:ss tt}";
  37. else
  38. TimeStamp.Visibility = Visibility.Collapsed;
  39. ImageryLayer.Center = new Point(latitude,longitude);
  40. }
  41. private void ZoomIn_OnClick(object sender, RoutedEventArgs e)
  42. {
  43. Map.MaxZoom = Math.Min(20, Map.ZoomLevel + 1);
  44. Map.ZoomLevel = Math.Min(20, Map.ZoomLevel + 1);
  45. }
  46. private void ZoomOut_OnClick(object sender, RoutedEventArgs e)
  47. {
  48. Map.MinZoom= Math.Max(5, Map.ZoomLevel - 1);
  49. Map.ZoomLevel = Math.Max(5, Map.ZoomLevel - 1);
  50. }
  51. }
  52. }