LiveMapsPanel.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Windows.Controls;
  5. using System.Windows.Input;
  6. using Comal.Classes;
  7. using Comal.Stores;
  8. using InABox.Core;
  9. using InABox.Wpf;
  10. using Syncfusion.UI.Xaml.Maps;
  11. using System.ComponentModel;
  12. using System.Linq;
  13. using System.Windows;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using Geocoding;
  17. using InABox.DynamicGrid;
  18. using InABox.WPF;
  19. using Microsoft.Xaml.Behaviors.Core;
  20. using net.sf.mpxj;
  21. using Brush = System.Drawing.Brush;
  22. using Location = InABox.Core.Location;
  23. namespace PRSDesktop
  24. {
  25. public class MarkerAlignmentConverter : AbstractConverter<Border?, Thickness>
  26. {
  27. public override Thickness Convert(Border? value)
  28. {
  29. return new Thickness(
  30. (value?.Width / 2.0) ?? 0.0,
  31. (value?.Height / 2.0) ?? 0.0,
  32. 0.0,
  33. 0.0);
  34. }
  35. }
  36. public class EquipmentThumbnailConverter : AbstractConverter<Guid, BitmapImage?>
  37. {
  38. public static Dictionary<Guid, BitmapImage?> Cache { get; set; } = new ();
  39. public override BitmapImage? Convert(Guid value)
  40. {
  41. if (Cache?.TryGetValue(value, out var result) == true)
  42. return result;
  43. return null;
  44. }
  45. }
  46. public class EquipmentColorConverter : AbstractConverter<Equipment?, System.Windows.Media.Color>
  47. {
  48. public static GPSTrackerLocation[] Pings { get; set; }
  49. public override System.Windows.Media.Color Convert(Equipment? value)
  50. {
  51. if (value != null)
  52. {
  53. if (Pings?.Any(x=>x.Tracker.ID == value.TrackerLink.ID) == true)
  54. return Colors.LightYellow;
  55. }
  56. return Colors.LightGray;
  57. }
  58. }
  59. public class MarkerTemplateSelector : DataTemplateSelector
  60. {
  61. public DataTemplate? AssetMarkerTemplate { get; set; }
  62. public DataTemplate? SiteMarkerTemplate { get; set; }
  63. public override DataTemplate? SelectTemplate(object? item, DependencyObject container)
  64. {
  65. if (item is CustomDataSymbol customDataSymbol && customDataSymbol.Data != null)
  66. {
  67. return customDataSymbol.Data is SiteMapMarker
  68. ? SiteMarkerTemplate
  69. : AssetMarkerTemplate;
  70. }
  71. return base.SelectTemplate(item, container);
  72. }
  73. }
  74. /// <summary>
  75. /// Interaction logic for MapsPanel.xaml
  76. /// </summary>
  77. public partial class LiveMapsPanel : UserControl, IPanel<GPSTracker>
  78. {
  79. public LiveMapsPanel()
  80. {
  81. InitializeComponent();
  82. }
  83. public bool IsReady { get; set; }
  84. public void CreateToolbarButtons(IPanelHost host)
  85. {
  86. }
  87. public string SectionName => "Maps";
  88. public DataModel DataModel(Selection selection)
  89. {
  90. return new MapsDataModel();
  91. }
  92. public void Heartbeat(TimeSpan time)
  93. {
  94. }
  95. public void Refresh()
  96. {
  97. ViewModel.Refresh();
  98. }
  99. public Dictionary<string, object[]> Selected()
  100. {
  101. return new Dictionary<string, object[]>();
  102. }
  103. public void Setup()
  104. {
  105. }
  106. public void Shutdown(CancelEventArgs? cancel)
  107. {
  108. }
  109. public event DataModelUpdateEvent? OnUpdateDataModel;
  110. private void Map_OnPanned(object sender, PanEventArgs args)
  111. {
  112. ViewModel.SelectedSite = null;
  113. }
  114. private void Map_OnZoomed(object sender, ZoomEventArgs args)
  115. {
  116. ViewModel.SelectedSite = null;
  117. }
  118. }
  119. }