ソースを参照

Fixed DynmaicMapColumn error when no geofence is provided

frogsoftware 1 週間 前
コミット
797a94f458

+ 1 - 1
prs.desktop/Forms/MapForm.xaml

@@ -36,7 +36,7 @@
                     <syncfusion:ImageryLayer.SubShapeFileLayers>
                         <syncfusion:SubShapeFileLayer x:Name="subLayer">
                             <syncfusion:SubShapeFileLayer.MapElements>
-
+                                
                                 <syncfusion:MapPolygon 
                                     x:Name="Polygon" 
                                     Stroke="Firebrick" 

+ 12 - 1
prs.desktop/Forms/MapForm.xaml.cs

@@ -2,10 +2,13 @@
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
+using System.Windows.Media;
 using Comal.Classes;
 using InABox.Clients;
 using InABox.Core;
 using InABox.Wpf;
+using Syncfusion.UI.Xaml.Maps;
+using Syncfusion.Windows.PdfViewer;
 using Syncfusion.XlsIO.Implementation.PivotTables;
 using Point = System.Windows.Point;
 
@@ -25,8 +28,16 @@ namespace PRSDesktop.Forms
 			InitializeComponent();
 			
 			var geopoint = new GeoPoint(latitude, longitude);
-			if (geofence != null)
+			if (geofence?.Coordinates.Any() == true)
 				Polygon.Points = new ObservableCollection<Point>(geofence.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
+			else
+			{
+				var circle = new MapCircle();
+				circle.Center = new Point(latitude, longitude);
+				circle.Radius = 25;
+				circle.Fill = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
+				subLayer.MapElements.Add(circle);
+			}
 			// var fences = Client.Query<GeoFence>().ToArray<GeoFence>();
 			// foreach (var fence in fences)
 			// {

+ 26 - 4
prs.desktop/Panels/DynamicMapColumn.cs

@@ -25,9 +25,17 @@ namespace PRSDesktop
             
             Longitude = $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Location)}.{nameof(Address.Location.Longitude)}";
             grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Longitude));
-            
-            Geofence =  $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Geofence)}";
-            grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Geofence));
+
+            try
+            {
+                Geofence =  $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Geofence)}";
+                grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Geofence));
+            }
+            catch (Exception e)
+            {
+                Geofence = "";
+            }
+
             
             Image = MapImage;
             Action = MapClick;
@@ -46,6 +54,16 @@ namespace PRSDesktop
             
             Longitude = CoreUtils.GetFullPropertyName(property, ".") + ".Longitude";
             grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Longitude));
+            try
+            {
+                Geofence =  $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Geofence)}";
+                grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Geofence));
+            }
+            catch (Exception e)
+            {
+                Geofence = "";
+            }
+
             
             Image = MapImage;
             Action = MapClick;
@@ -73,7 +91,11 @@ namespace PRSDesktop
         {
             if (row is not null && HasLocation(row))
             {
-                var geofence = Serialization.Deserialize<GeoFenceDefinition>(row.Get<string>(Geofence)) ?? new GeoFenceDefinition();
+                
+                var geofence = (!String.IsNullOrWhiteSpace(Geofence) 
+                    ? Serialization.Deserialize<GeoFenceDefinition>(row.Get<string>(Geofence)) 
+                    : null)
+                ?? new GeoFenceDefinition();
                 var mapform = new MapForm(row.Get<double>(Latitude), row.Get<double>(Longitude),geofence);
                 mapform.ShowDialog();