wyq 1 year ago
parent
commit
5dc4357b2f

+ 73 - 4
DataSimulation.Forms/ExtensionsDev/MapControlEx.cs

@@ -24,6 +24,7 @@ using System.Linq;
 using System.Reflection;
 using System.Text;
 using System.Threading;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 
 public enum GoogleMapType
@@ -899,10 +900,10 @@ public static class MapControlEx
     /// </summary>
     /// <param name="ctrl"></param>
     /// <returns></returns>
-    public static IEnumerable<FlightInfo> GetFlightLine(this MapControl ctrl)
+    public static IEnumerable<T> GetFlightLine<T>(this MapControl ctrl) where T : FlightInfo
     {
         var innerData = ctrl.Tag as InnerData;
-        return innerData._flightCache.Select(m => m.Value);
+        return innerData._flightCache.Select(m => (T)m.Value);
     }
 
     private static void AddFlightPoint(object sender, MouseEventArgs e)
@@ -926,10 +927,78 @@ public static class MapControlEx
         innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
         innerData.mMapStorage.Items.Add(innerData.hoverPoint);
         innerData.flightpath.Points.Add(innerData.hoverPoint.Location);
-        if (!innerData._flightCache[Name].flights.Any(m => m.FlightLon == lon && m.FlightLat == lat))
+        innerData._flightCache[Name].flights.Add(new FlightData(lon, lat));
+    }
+
+    public static void SetFlightLine<T>(this MapControl ctrl, IEnumerable<T> items, bool clearDrawLayer = true) where T : FlightInfo, new()
+    {
+        var innerData = ctrl.Tag as InnerData;
+        innerData._flightCache.Clear();
+        if (clearDrawLayer)
+            ctrl.ClearDrawObj();
+        if (items == null || !items.Any())
         {
-            innerData._flightCache[Name].flights.Add(new FlightData(lon, lat));
+            ctrl.Refresh();
+            return;
+        }
+
+        for (int i = 0; i < items.Count(); i++)
+        {
+            var f = items.ElementAt(i);
+            ctrl.ShowFlightLine(innerData, f);
+
         }
+
+
+    }
+    private static void ShowFlightLine(this MapControl ctrl, InnerData innerData, FlightInfo flight)
+    {
+        string filghtName = $"DrawFlightLine{flight.FlightName}";
+        var flightpath = new MapSpline()
+        {
+            Stroke = Color.FromArgb(127, 255, 0, 199),
+            StrokeWidth = 2,
+            CanResize = true,
+            CanEdit = true,
+            CanRotate = true,
+            IsHitTestVisible = false,
+            CanMove = true,
+            Tag = filghtName
+
+        };
+        innerData.mMapStorage.Items.Add(flightpath);
+        var hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
+        hoverPoint.Fill = ColorHelper.GetColor(hoverPoint.Tag.ToString());
+        innerData.mMapStorage.Items.Add(hoverPoint);
+        if (flight.flights.Count > 0)
+        {
+            var center = new GeoPoint(flight.flights.First().FlightLat, flight.flights.First().FlightLon);
+            ctrl.SetCenterPoint(center, true);
+        }
+        Task.Run(() =>
+          {
+              flight.flights.ForEach((finfo) =>
+                {
+                    var location = new GeoPoint(finfo.FlightLat, finfo.FlightLon);
+                   
+                    var hoverPointj = new MapDot()
+                    {
+                        CanResize = false,
+                        CanMove = false,
+                        ToolTipPattern = $"航迹:{flight.FlightName}\r\n{finfo.FlightLon},{finfo.FlightLat}°",
+                        Tag = flightpath.Tag,
+                        Size = 8
+                    };
+                    hoverPointj.Location = location;
+                    hoverPointj.Fill = ColorHelper.GetColor(hoverPointj.Tag.ToString());
+                    innerData.mMapStorage.Items.Add(hoverPointj);
+                    flightpath.Points.Add(hoverPointj.Location);
+                    Thread.Sleep(1000);
+                });
+
+          });
+        innerData._flightCache.Add(flight.FlightName, flight);
+
     }
     #endregion
     /// <summary>

+ 5 - 3
DataSimulation.Forms/UserControl/CtrlHome.cs

@@ -4,6 +4,7 @@ using DataSimulation.Repostory.EFContext;
 using DataSimulation.Repostory.Model;
 using DevExpress.Utils;
 using DevExpress.XtraEditors.ButtonsPanelControl;
+using DevExpress.XtraMap;
 using DxHelper;
 using ExtensionsDev;
 using System;
@@ -40,8 +41,8 @@ namespace DataSimulation.Forms.UserControl
           .UseDrawRect(rect =>
           {
               (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
-          }).UseFlightLine();
-            
+          }).UseFlightLine()
+         ;
 
         }
 
@@ -49,7 +50,6 @@ namespace DataSimulation.Forms.UserControl
         {
             try
             {
-
                 var yearDirs = Directory.EnumerateDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart")).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
                 foreach (var yearDir in yearDirs)
                 {
@@ -85,6 +85,7 @@ namespace DataSimulation.Forms.UserControl
 
         private async void layoutControlGroup_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
         {
+           
             var txt = (e.Button as GroupBoxButton).Caption;
             if (txt == "新建任务")
             {
@@ -130,4 +131,5 @@ namespace DataSimulation.Forms.UserControl
             }
         }
     }
+
 }

+ 3 - 0
DataSimulation.Repostory/PosData.cs

@@ -172,6 +172,9 @@ namespace DataSimulation.Repostory
 
     public class FlightInfo
     {
+        public FlightInfo()
+        { 
+        }
         public FlightInfo(string name, double Speed)
         {
             this.FlightName = name;