ソースを参照

avalonia: Fixed live maps view box sizzing

Kenric Nugteren 3 ヶ月 前
コミット
48fc6651bf

+ 20 - 2
PRS.Avalonia/PRS.Avalonia/Modules/EquipmentModule/EquipmentMaps/EquipmentMapsView.axaml.cs

@@ -25,10 +25,13 @@ public partial class EquipmentMapsView : UserControl
         = AvaloniaProperty.Register<EquipmentMapsView, ObservableCollection<Marker>>(nameof(EquipmentMarkers), new());
 
     public static readonly StyledProperty<Point> CoordinatesProperty
-        = AvaloniaProperty.Register<EquipmentMapsView, Point>(nameof(JobMarkers), new());
+        = AvaloniaProperty.Register<EquipmentMapsView, Point>(nameof(Coordinates), new());
 
     public static readonly StyledProperty<int> ZoomLevelProperty
-        = AvaloniaProperty.Register<EquipmentMapsView, int>(nameof(EquipmentMarkers), new());
+        = AvaloniaProperty.Register<EquipmentMapsView, int>(nameof(ZoomLevel), new());
+
+    public static readonly StyledProperty<Rect> BoxProperty
+        = AvaloniaProperty.Register<EquipmentMapsView, Rect>(nameof(Box), new());
 
     private readonly MemoryLayer _jobLayer;
     private readonly MemoryLayer _equipmentLayer;
@@ -53,12 +56,26 @@ public partial class EquipmentMapsView : UserControl
         get => GetValue(ZoomLevelProperty);
     }
 
+    public Rect Box
+    {
+        get => GetValue(BoxProperty);
+    }
+
     static EquipmentMapsView()
     {
         JobMarkersProperty.Changed.AddClassHandler<EquipmentMapsView>(JobMarkersChanged);
         EquipmentMarkersProperty.Changed.AddClassHandler<EquipmentMapsView>(EquipmentMarkersChanged);
         CoordinatesProperty.Changed.AddClassHandler<EquipmentMapsView>(CoordinatesChanged);
         ZoomLevelProperty.Changed.AddClassHandler<EquipmentMapsView>(ZoomLevelChanged);
+        BoxProperty.Changed.AddClassHandler<EquipmentMapsView>(BoxChanged);
+    }
+
+    private static void BoxChanged(EquipmentMapsView view, AvaloniaPropertyChangedEventArgs args)
+    {
+        var p1 = SphericalMercator.FromLonLat(view.Box.Left, view.Box.Top);
+        var p2 = SphericalMercator.FromLonLat(view.Box.Right, view.Box.Bottom);
+        view.Map.Map.Navigator.ZoomToBox(new(p1.x, p1.y, p2.x, p2.y));
+        view.Map.Map.Navigator.ZoomOut();
     }
 
     private static void ZoomLevelChanged(EquipmentMapsView view, AvaloniaPropertyChangedEventArgs args)
@@ -100,6 +117,7 @@ public partial class EquipmentMapsView : UserControl
         Bind(EquipmentMarkersProperty, new Binding(nameof(EquipmentMapsViewModel.EquipmentMarkers)));
         Bind(CoordinatesProperty, new Binding(nameof(EquipmentMapsViewModel.Coordinates)));
         Bind(ZoomLevelProperty, new Binding(nameof(EquipmentMapsViewModel.ZoomLevel)));
+        Bind(BoxProperty, new Binding(nameof(EquipmentMapsViewModel.Box)));
 
         _jobLayer = CreateJobLayer();
         _equipmentLayer = CreateEquipmentLayer();

+ 20 - 9
PRS.Avalonia/PRS.Avalonia/Modules/EquipmentModule/EquipmentMaps/EquipmentMapsViewModel.cs

@@ -49,6 +49,9 @@ public partial class EquipmentMapsViewModel : ModuleViewModel
     [ObservableProperty]
     private int _zoomLevel;
 
+    [ObservableProperty]
+    private Rect _box;
+
     public EquipmentMapsViewModel()
     {
         _settings = new LocalConfiguration<EquipmentMapsSettings>().Load();
@@ -108,6 +111,13 @@ public partial class EquipmentMapsViewModel : ModuleViewModel
             if(App.GPS is not null)
             {
                 coords = new Point(App.GPS.Latitude, App.GPS.Longitude);
+
+                // Change to some other value so that we can trigger an update.
+                Coordinates = new();
+                ZoomLevel = zoom + 1;
+                
+                Coordinates = coords;
+                ZoomLevel = zoom;
             }
             else
             {
@@ -117,6 +127,13 @@ public partial class EquipmentMapsViewModel : ModuleViewModel
         else if (points.Length == 1)
         {
             coords = new Point(points[0].Y, points[0].X);
+
+            // Change to some other value so that we can trigger an update.
+            Coordinates = new();
+            ZoomLevel = zoom + 1;
+            
+            Coordinates = coords;
+            ZoomLevel = zoom;
         }
         else
         {
@@ -135,16 +152,10 @@ public partial class EquipmentMapsViewModel : ModuleViewModel
             var lastLocation = new Location()
                 { Latitude = lastLat, Longitude = lastLong };
             var distance = firstLocation.DistanceTo(lastLocation, UnitOfLength.Kilometers);
-            coords = new Point(resultLat, resultLong);
-            zoom = CalculateZoom(distance);
-        }
 
-        // Change to some other value so that we can trigger an update.
-        Coordinates = new();
-        ZoomLevel = zoom + 1;
-        
-        Coordinates = coords;
-        ZoomLevel = zoom;
+            Box = new();
+            Box = new(new Point(firstLong, firstLat), new Point(lastLong, lastLat));
+        }
     }
 
     private static int CalculateZoom(double distance)