wyq 1 жил өмнө
parent
commit
2bfb4e08c2

+ 7 - 0
DataSimulation.Forms/EditForms/FlightEditor.cs

@@ -4,6 +4,7 @@ using DataSimulation.Repostory.Model;
 using DevExpress.Utils.About;
 using DevExpress.XtraEditors.Controls;
 using DevExpress.XtraEditors.DXErrorProvider;
+using DevExpress.XtraMap;
 using DxHelper;
 using ExtensionsDev;
 using System;
@@ -65,6 +66,12 @@ namespace DataSimulation.Forms.EditForms
                 List<FlightInfo> flights = new List<FlightInfo>();
                 points.ForEach(m => flights.Add(new FlightInfo(info.SimulationName, info.SimulationSpeed, m.SimulationLon, m.SimulationLat)));
                 mapControl.SetFlightLine(flights);
+                mapControl.AddRectMenu<FlightInfo>("删除航迹点", SvgHelper.CreateClose(), items =>
+                {
+                    var flightInfos = mapControl.GetRectItem<FlightInfo>();
+                    mapControl.DelFlightItem(flightInfos);
+
+                });
                 layoutControlItem12.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                 layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
             }

+ 58 - 23
DataSimulation.Forms/ExtensionsDev/MapControlEx.cs

@@ -4,6 +4,7 @@ using DevExpress.Export.Xl;
 using DevExpress.Map;
 using DevExpress.Map.Native;
 using DevExpress.Utils;
+using DevExpress.Utils.Extensions;
 using DevExpress.Utils.Filtering;
 using DevExpress.Utils.Svg;
 using DevExpress.XtraBars;
@@ -67,7 +68,6 @@ public static class MapControlEx
     {
         internal GeoPoint _mapMenuGeoPoint;
         internal Dictionary<int, MapItem> _clusterCache = new Dictionary<int, MapItem>();
-        internal Dictionary<PosData, MapItem> _dataCache = new Dictionary<PosData, MapItem>();
         internal BarManager barM;
         internal PopupMenu mapMenu;
         internal PopupMenu posMenu;
@@ -82,7 +82,7 @@ public static class MapControlEx
         /// 航迹线
         /// </summary>
         internal MapSpline flightpath;
-        internal List<FlightInfo> _flightCache = new List<FlightInfo>();
+        internal Dictionary<FlightInfo, MapItem> _flightCache = new Dictionary<FlightInfo, MapItem>();
         internal MapDot hoverPoint;
         internal ToolTipControllerShowEventArgs hoverTip;
         internal ToolTipController mapToolTip;
@@ -573,7 +573,7 @@ public static class MapControlEx
         double startLat = rect.startLat;
         double endLon = rect.endLon;
         double endLat = rect.endLat;
-        var temp = innerData._flightCache.Where(p => p.InRectangle(startLon, startLat, endLon, endLat));
+        var temp = innerData._flightCache.Keys.Where(p => p.InRectangle(startLon, startLat, endLon, endLat));
         var res = temp.Select(p => (T)p);
         return res;
     }
@@ -629,7 +629,7 @@ public static class MapControlEx
         var innerData = ctrl.Tag as InnerData;
         btnFlight.ItemClick += (sender, e) =>
         {
-            var flights = innerData._flightCache.GroupBy(m => m.FlightName);
+            var flights = innerData._flightCache.Keys.GroupBy(m => m.FlightName);
             var frm = new MapFlightLineView(flights.Select(f => f.Key).ToList());
             frm.onClick = (reslut) =>
             {
@@ -760,7 +760,7 @@ public static class MapControlEx
     public static IEnumerable<T> GetFlightLine<T>(this MapControl ctrl) where T : FlightInfo
     {
         var innerData = ctrl.Tag as InnerData;
-        return innerData._flightCache.Select(m => (T)m);
+        return innerData._flightCache.Keys.Select(m => (T)m);
     }
 
     private static void AddFlightPoint(object sender, MouseEventArgs e)
@@ -786,14 +786,48 @@ public static class MapControlEx
         innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
         innerData.flightStorge.Items.Add(innerData.hoverPoint);
         innerData.flightpath.Points.Add(innerData.hoverPoint.Location);
-        if (!innerData._flightCache.Any(m => m.FlightLon == lon && m.FlightName == name && m.Speed == speed && m.FlightLat == lat))
+        if (!innerData._flightCache.Keys.Any(m => m.FlightLon == lon && m.FlightName == name && m.Speed == speed && m.FlightLat == lat))
         {
-            innerData._flightCache.Add(new FlightInfo(name, speed, lon, lat));
+            innerData._flightCache.Add(new FlightInfo(name, speed, lon, lat), innerData.hoverPoint);
         }
     }
 
+    public static void DelFlightItem<T>(this MapControl ctrl, IEnumerable<T> data) where T : FlightInfo, new()
+    {
+        var fs = data.ToList();
+        if (fs == null || !fs.Any()) return;
+        foreach (var item in fs)
+        {
+            ctrl.DelFlightItem(item);
+        }
+        ctrl.Refresh();
+    }
+
+    public static void DelFlightItem<T>(this MapControl ctrl, T item) where T : FlightInfo, new()
+    {
+        if (item == null) return;
+        var innerData = ctrl.Tag as InnerData;
+        if (innerData._flightCache.ContainsKey(item))
+        {
+            innerData.flightStorge.Items.Remove(innerData._flightCache[item]);
+            innerData._flightCache.Remove(item);
+            var geoPoint = new GeoPoint(item.FlightLat, item.FlightLon);
+            string filghtName = $"DrawFlightLine_{item.FlightName}_{item.Speed}";
+            var mapspline = innerData.flightStorge.Items.First(s => s.Tag.ToString() == filghtName && s is MapSpline);
+            var spline = (mapspline as MapSpline);
+            spline.Points.Remove(geoPoint);
+            if (spline.Points.Count == 0)
+            {
+                innerData.flightStorge.Items.Remove(spline);
+            }
+        }
+        ctrl.Refresh();
+
+    }
+
     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)
@@ -833,10 +867,10 @@ public static class MapControlEx
             Tag = filghtName
 
         };
+        //var hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
+        //hoverPoint.Fill = ColorHelper.GetColor(hoverPoint.Tag.ToString());
+        //innerData.flightStorge.Items.Add(hoverPoint);
         innerData.flightStorge.Items.Add(flightpath);
-        var hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = filghtName, Size = 8 };
-        hoverPoint.Fill = ColorHelper.GetColor(hoverPoint.Tag.ToString());
-        innerData.flightStorge.Items.Add(hoverPoint);
         if (points.Count > 0)
         {
 
@@ -852,7 +886,7 @@ public static class MapControlEx
                     var hoverPointj = new MapDot()
                     {
                         CanResize = false,
-                        CanMove = false,
+                        CanMove = true,
                         ToolTipPattern = $"航迹:{finfo.FlightName}\r\n{finfo.FlightLon},{finfo.FlightLat}°",
                         Tag = flightpath.Tag,
                         Size = 8
@@ -861,11 +895,12 @@ public static class MapControlEx
                     hoverPointj.Fill = ColorHelper.GetColor(hoverPointj.Tag.ToString());
                     innerData.flightStorge.Items.Add(hoverPointj);
                     flightpath.Points.Add(hoverPointj.Location);
+                    innerData._flightCache.Add(finfo, hoverPointj);
                     Thread.Sleep(1000);
                 });
 
           });
-        innerData._flightCache.AddRange(points);
+
 
     }
 
@@ -878,7 +913,7 @@ public static class MapControlEx
         btnExportFlightLine.ItemClick += (sender, e) =>
         {
             if (!innerData._flightCache.Any()) return;
-            List<FlightInfo> list = innerData._flightCache;
+            List<FlightInfo> list = innerData._flightCache.Keys.ToList();
             Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
             var props = list.First().GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
             List<(int ColumnIndex, PropertyInfo Prop, string Header)> listPorps = new List<(int, PropertyInfo, string)>();
@@ -1035,10 +1070,10 @@ public static class MapControlEx
         btnExportCsv.Tag = ctrl;
         btnExportCsv.ItemClick += (sender, e) =>
         {
-            if (!innerData._dataCache.Any()) return;
+            if (!innerData._flightCache.Any()) return;
             bool exportSigTime = false;
             Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
-            var props = innerData._dataCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
+            var props = innerData._flightCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
             List<(int ColumnIndex, PropertyInfo Prop, string Header)> listPorps = new List<(int, PropertyInfo, string)>();
             foreach (var prop in props)
             {
@@ -1067,9 +1102,9 @@ public static class MapControlEx
                 dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.csv";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
-                    var list = innerData._dataCache.Keys as IEnumerable<PosData>;
-                    if (exportSigTime)
-                        list = list.OrderByDescending(p => p.SigTime);//如果导出了SigTime,则自动按照SigTime降序排列后导出
+                    var list = innerData._flightCache.Keys as IEnumerable<FlightInfo>;
+                    //if (exportSigTime)
+                    //   list = list.OrderByDescending(p => p.SigTime);//如果导出了SigTime,则自动按照SigTime降序排列后导出
                     StreamWriter sw = new StreamWriter(dialog.FileName, false, new UTF8Encoding(true));//utf8-bom
 
                     if (exportHeader)
@@ -1145,7 +1180,7 @@ public static class MapControlEx
 
             btnExportXlsx.ItemClick += (sender, e) =>
             {
-                if (!innerData._dataCache.Any()) return;
+                if (!innerData._flightCache.Any()) return;
                 GridControl gc = new GridControl();
                 GridView view = new GridView();
                 view.GridControl = gc;
@@ -1154,7 +1189,7 @@ public static class MapControlEx
                 view.OptionsPrint.ShowPrintExportProgress = false;
                 bool exportSigTime = false;
                 Dictionary<string, string> cellFormats = new Dictionary<string, string>();//单元格的format
-                var props = innerData._dataCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
+                var props = innerData._flightCache.Keys.GetType().GetGenericArguments().First().GetProperties(BindingFlags.Public | BindingFlags.Instance);
                 foreach (var prop in props)
                 {
                     ExportCellAttribute attrExport = prop.GetCustomAttribute<ExportCellAttribute>();
@@ -1188,9 +1223,9 @@ public static class MapControlEx
                     dialog.FileName = $"Pos{DateTime.Now:yyyyMMddHHmmss}.xlsx";
                     if (dialog.ShowDialog() == DialogResult.OK)
                     {
-                        var list = innerData._dataCache.Keys.ToList();
-                        if (exportSigTime)
-                            list = list.OrderByDescending(p => p.SigTime).ToList();//如果导出了SigTime,则自动按照SigTime降序排列后导出
+                        var list = innerData._flightCache.Keys.ToList();
+                        //if (exportSigTime)
+                        //list = list.OrderByDescending(p => p.SigTime).ToList();//如果导出了SigTime,则自动按照SigTime降序排列后导出
 
                         gc.DataSource = list;
                         gc.Visible = true;

+ 5 - 0
DataSimulation.Repostory/PosData.cs

@@ -213,5 +213,10 @@ namespace DataSimulation.Repostory
         {
             return FlightLon >= startLon && FlightLon <= endLon && FlightLat >= startLat && FlightLat <= endLat;
         }
+
+        public bool EqualFlight(FlightInfo flight)
+        {
+            return FlightName == flight.FlightName && Speed <= flight.Speed && FlightLon >= flight.FlightLon && FlightLat <= flight.FlightLat;
+        }
     }
 }