wyq 1 rok temu
rodzic
commit
7a365fc1d9
1 zmienionych plików z 83 dodań i 14 usunięć
  1. 83 14
      DataSimulation.Forms/ExtensionsDev/MapControlEx.cs

+ 83 - 14
DataSimulation.Forms/ExtensionsDev/MapControlEx.cs

@@ -1,15 +1,11 @@
 using DataSimulation.Repostory;
-using DataSimulation.Repostory.EFContext;
 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;
 using DevExpress.XtraEditors;
-using DevExpress.XtraEditors.Popup;
 using DevExpress.XtraGrid;
 using DevExpress.XtraGrid.Columns;
 using DevExpress.XtraGrid.Views.Grid;
@@ -18,7 +14,6 @@ using DevExpress.XtraMap.ItemEditor;
 using DevExpress.XtraPrinting;
 using DxHelper;
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Data.Common;
@@ -91,6 +86,7 @@ public static class MapControlEx
         internal MapDot dotItem = new MapDot() { Tag = "DrawRect" };
         internal bool drawingRect = false;
         internal bool mouseLeftDown = false;
+        internal bool mouseRightDown = false;
         internal (double starLon, double startLat, double centerLon, double centerLat,
            double endLon, double endLat, double lonRange, double latRange)
            CurrentRect;
@@ -218,6 +214,7 @@ public static class MapControlEx
                 }
                 else if (hitInfo.InMapDot && hitInfo.MapDot.Tag is FlightInfo)
                 {
+                    innerData.mouseRightDown = true;
                     var selectPos = (FlightInfo)hitInfo.MapDot.Tag;
                     if (!selectPos.Selected)
                     {
@@ -256,6 +253,38 @@ public static class MapControlEx
         ctrl.MouseUp += (sender, e) =>
         {
             innerData.mouseLeftDown = false;
+            innerData.mouseRightDown = false;
+        };
+        ctrl.MouseMove += (sender, e) =>
+        {
+            if (e.Button == MouseButtons.Right && innerData.mouseRightDown)
+            {
+                var hitInfo = ctrl.CalcHitInfo(e.Location);
+                if (hitInfo.InMapDot && hitInfo.MapDot.Tag is FlightInfo)
+                {
+                    var dragStartPoint = (FlightInfo)hitInfo.MapDot.Tag;
+                    if (dragStartPoint != null)
+                    {
+                        var location = ctrl.ScreenPointToCoordPoint(e.Location);
+                        var locpoint = new GeoPoint(Math.Round(location.GetY(), 3), Math.Round(location.GetX(), 3));
+
+                        var oldlocation = new GeoPoint(dragStartPoint.FlightLat, dragStartPoint.FlightLon);
+                        var mapspline = innerData.flightStorge.Items.First(s => s.Tag.ToString() == dragStartPoint.GetFilghtName() && s is MapSpline);
+                        //更改线中的点
+                        (mapspline as MapSpline).Points.AddOrReplace(m => m == oldlocation, locpoint);
+
+                        // 计算移动的偏移量
+                        dragStartPoint.FlightLon = locpoint.GetX();
+                        dragStartPoint.FlightLat = locpoint.GetY();
+
+                        dragStartPoint.Selected = true;
+                        ctrl.UpdateItem(dragStartPoint);
+
+
+                    }
+
+                }
+            }
         };
         //中心点、缩放级别
         ctrl.MinZoomLevel = 3;
@@ -584,7 +613,7 @@ public static class MapControlEx
                 {
                     return;
                 }
-               var flight= new FlightInfo();
+                var flight = new FlightInfo();
                 flight.FlightName = fligthName;
                 flight.Speed = speed;
 
@@ -604,7 +633,7 @@ public static class MapControlEx
                 };
                 innerData.flightStorge.Items.Add(innerData.flightpath);
                 innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = flight, Size = 8 };
-                innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
+                innerData.hoverPoint.Fill = ColorHelper.GetColor(flight.GetFilghtName());
                 innerData.flightStorge.Items.Add(innerData.hoverPoint);
                 //提示框
                 SuperToolTip superToolTip = new SuperToolTip();
@@ -636,6 +665,46 @@ public static class MapControlEx
         innerData.barM.EndInit();
         return ctrl;
     }
+
+    public static MapControl AddFlightPoint(this MapControl ctrl, string fligthName, double speed)
+    {
+        var innerData = ctrl.Tag as InnerData;
+
+        var flight = new FlightInfo();
+        flight.FlightName = fligthName;
+        flight.Speed = speed;
+
+        var mapspline = innerData.flightStorge.Items.FirstOrDefault(s => s.Tag.ToString() == flight.GetFilghtName() && s is MapSpline);
+        if (mapspline == null) return ctrl;
+
+        ctrl.MapEditor.SetEditMode();
+        innerData.flightpath = mapspline as MapSpline;
+
+        innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = flight, Size = 8 };
+        innerData.hoverPoint.Fill = ColorHelper.GetColor(flight.GetFilghtName());
+
+        //提示框
+        SuperToolTip superToolTip = new SuperToolTip();
+        ToolTipItem textItem = new ToolTipItem() { Text = "单击添加航迹点,双击结束绘制航迹" };
+        superToolTip.Items.Add(textItem);
+        ToolTipControllerShowEventArgs arg = new ToolTipControllerShowEventArgs();
+        arg.ShowBeak = true;
+        arg.SuperTip = superToolTip;
+        innerData.hoverTip = arg;
+        ctrl.MouseClick += AddFlightPoint;
+        ctrl.MouseLeave += MapControl_MouseLeave;
+        ctrl.MouseEnter += MapControl_MouseEnter;
+        ctrl.MouseMove += MovingDistinct;
+        ctrl.DoubleClick += (sender1, e1) =>
+        {
+            ctrl.MouseClick -= AddFlightPoint;
+            ctrl.MouseLeave -= MapControl_MouseLeave;
+            ctrl.MouseEnter -= MapControl_MouseEnter;
+            ctrl.MouseMove -= MovingDistinct;
+        };
+
+        return ctrl;
+    }
     /// <summary>
     /// 
     /// </summary>
@@ -677,7 +746,7 @@ public static class MapControlEx
         };
         innerData.flightStorge.Items.Add(innerData.flightpath);
         innerData.hoverPoint = new MapDot() { CanResize = false, CanMove = false, Tag = flight, Size = 8 };
-        innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
+        innerData.hoverPoint.Fill = ColorHelper.GetColor(flight.GetFilghtName());
         innerData.flightStorge.Items.Add(innerData.hoverPoint);
         //提示框
         SuperToolTip superToolTip = new SuperToolTip();
@@ -734,7 +803,7 @@ public static class MapControlEx
             Size = 8
         };
         innerData.hoverPoint.Location = location;
-        innerData.hoverPoint.Fill = ColorHelper.GetColor(innerData.hoverPoint.Tag.ToString());
+        innerData.hoverPoint.Fill = ColorHelper.GetColor(flight.GetFilghtName());
 
         if (!innerData._flightCache.Keys.Any(m => m.Equals(flight)))
         {
@@ -757,7 +826,7 @@ public static class MapControlEx
             {
                 mapDot.Size = item.Selected ? _selectedDotSize : _dotSize;
                 mapDot.StrokeWidth = item.Selected ? 0 : 1;
-               
+
                 if (mapDot.ClusteredItems.Any())
                     (mapDot.ClusteredItems[0] as MapDot).Size = _selectedDotSize;
                 if (item.Selected)
@@ -800,8 +869,8 @@ public static class MapControlEx
             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 mapspline = innerData.flightStorge.Items.First(s => s.Tag.ToString() == item.GetFilghtName() && s is MapSpline);
             var spline = (mapspline as MapSpline);
             spline.Points.Remove(geoPoint);
             if (spline.Points.Count == 0)
@@ -873,7 +942,7 @@ public static class MapControlEx
 
                     var hoverPointj = new MapDot()
                     {
-                      
+
                         CanResize = false,
                         CanMove = true,
                         ToolTipPattern = finfo.ToString(),
@@ -881,7 +950,7 @@ public static class MapControlEx
                         Size = 8
                     };
                     hoverPointj.Location = location;
-                    hoverPointj.Fill = ColorHelper.GetColor(hoverPointj.Tag.ToString());
+                    hoverPointj.Fill = ColorHelper.GetColor(finfo.GetFilghtName());
                     innerData.flightStorge.Items.Add(hoverPointj);
                     flightpath.Points.Add(hoverPointj.Location);
                     innerData._flightCache.Add(finfo, hoverPointj);