Browse Source

添加框选定位点绘制目标航迹

wyq 6 months ago
parent
commit
c1d06f87c9
2 changed files with 86 additions and 51 deletions
  1. 60 50
      XdCxRhDW.App/ExtensionsDev/MapControlEx.cs
  2. 26 1
      XdCxRhDW.App/UserControl/CtrlHome.cs

+ 60 - 50
XdCxRhDW.App/ExtensionsDev/MapControlEx.cs

@@ -1603,6 +1603,65 @@ public static class MapControlEx
         return ctrl;
     }
 
+
+
+
+    public static void DrawTrack<T>(this MapControl ctrl, IEnumerable<T> items) where T : PosData, new()
+    {
+        if (items == null || !items.Any()) return;
+        var innerData = ctrl.Tag as InnerData;
+        innerData.trackStorge.Items.Clear();
+        var posData = items.OrderBy(p => p.SigTime);
+        var itemList = posData.GroupBy(t => t.ColorKey);
+        List<MapPolyline> listLine = new List<MapPolyline>();
+        int w = 12;
+        int h = 20;
+        if (ctrl.ZoomLevel < 4)
+        {
+            w = 2;
+            h = 4;
+        }
+        else if (ctrl.ZoomLevel < 6)
+        {
+            w = 6;
+            h = 12;
+        }
+        else
+        {
+            w = 10;
+            h = 20;
+        }
+        foreach (var groupItems in itemList)
+        {
+            var targets = groupItems.ToList();
+            var colorKey = targets.First().ColorKey;
+            for (int i = 0; i < targets.Count - 1; i++)
+            {
+                var line = new MapPolyline();
+                line.CanEdit = false;
+                line.CanMove = false;
+                line.CanResize = false;
+                line.CanRotate = false;
+                line.EnableSelection = DefaultBoolean.False;
+                line.EnableHighlighting = DefaultBoolean.False;
+                line.IsGeodesic = true;
+                line.Stroke = ColorHelper.IsHtmlColor(colorKey) ? ColorTranslator.FromHtml(colorKey) : ColorHelper.GetColor(colorKey);
+                line.EndLineCap.Width = w;
+                line.EndLineCap.Length = h;
+                line.EndLineCap.Visible = true;
+                line.EndLineCap.IsFilled = false;
+                line.StrokeWidth = 2;
+                //line.EndLineCap.Length = 100;
+                var p1 = new GeoPoint(targets[i].PosLat, targets[i].PosLon);
+                var p2 = new GeoPoint(targets[i + 1].PosLat, targets[i + 1].PosLon);
+                line.Points.Add(p1);
+                line.Points.Add(p2);
+                listLine.Add(line);
+            }
+        }
+        innerData.trackStorge.Items.AddRange(listLine);
+
+    }
     /// <summary>
     /// 绘制矩形
     /// </summary>
@@ -2377,57 +2436,8 @@ public static class MapControlEx
     {
         var ctrl = e.Item.Tag as MapControl;
         var innerData = ctrl.Tag as InnerData;
-        innerData.trackStorge.Items.Clear();
         var posData = innerData._dataCache.Keys.OrderBy(p => p.SigTime);
-        var itemList = posData.GroupBy(t => t.ColorKey);
-        List<MapPolyline> listLine = new List<MapPolyline>();
-        int w = 12;
-        int h = 20;
-        if (ctrl.ZoomLevel < 4)
-        {
-            w = 2;
-            h = 4;
-        }
-        else if (ctrl.ZoomLevel < 6)
-        {
-            w = 6;
-            h = 12;
-        }
-        else
-        {
-            w = 10;
-            h = 20;
-        }
-        foreach (var groupItems in itemList)
-        {
-            var targets = groupItems.ToList();
-            var colorKey = targets.First().ColorKey;
-            for (int i = 0; i < targets.Count - 1; i++)
-            {
-                var line = new MapPolyline();
-                line.CanEdit = false;
-                line.CanMove = false;
-                line.CanResize = false;
-                line.CanRotate = false;
-                line.EnableSelection = DefaultBoolean.False;
-                line.EnableHighlighting = DefaultBoolean.False;
-                line.IsGeodesic = true;
-                line.Stroke = ColorHelper.IsHtmlColor(colorKey) ? ColorTranslator.FromHtml(colorKey) : ColorHelper.GetColor(colorKey);
-                line.EndLineCap.Width = w;
-                line.EndLineCap.Length = h;
-                line.EndLineCap.Visible = true;
-                line.EndLineCap.IsFilled = false;
-                line.StrokeWidth = 2;
-                //line.EndLineCap.Length = 100;
-                var p1 = new GeoPoint(targets[i].PosLat, targets[i].PosLon);
-                var p2 = new GeoPoint(targets[i + 1].PosLat, targets[i + 1].PosLon);
-                line.Points.Add(p1);
-                line.Points.Add(p2);
-                listLine.Add(line);
-            }
-        }
-        innerData.trackStorge.Items.AddRange(listLine);
-
+        ctrl.DrawTrack(posData.ToList());
     }
     private static void MarkDot_ItemClick(object sender, ItemClickEventArgs e)
     {

+ 26 - 1
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -157,7 +157,8 @@ namespace XdCxRhDW.App.UserControl
                 .AddRectMenu<ModelPosRes>("使用镜像点", SvgHelper.CreateUseMirr(), async items => await UseMirr(items.ToList()))
                 .AddRectMenu<ModelPosRes>("编辑目标", SvgHelper.CreateEdit(), async items => await EditTarget(items.ToList()))
                 .AddRectMenu<ModelPosRes>("转到列表", SvgHelper.CreateGoto(),
-                items => ToPosList(items.ToList()));
+                items => ToPosList(items.ToList()))
+                .AddRectMenu<ModelPosRes>("目标轨迹", SvgHelper.CreateTrack(), items => DrawTrack(items.ToList()));
 
             }
             catch (Exception ex)
@@ -1375,6 +1376,30 @@ namespace XdCxRhDW.App.UserControl
         #endregion
 
         #region 地图区域右键菜单
+
+        public void DrawTrack(List<ModelPosRes> items)
+        {
+            try
+            {
+                if (items.Count == 0)
+                {
+                    DxHelper.MsgBoxHelper.ShowWarning($"请选择需要绘制目标航迹的定位数据信息!");
+                    return;
+                }
+                if (items.Count == 1)
+                {
+                    DxHelper.MsgBoxHelper.ShowWarning($"一条定位数据信息不能绘制目标航迹!");
+                    return;
+                }
+                mapControl1.DrawTrack(items);
+
+            }
+            catch (Exception ex)
+            {
+                XdCxRhDW.Framework.LogHelper.Error("绘制目标轨迹异常", ex);
+                DxHelper.MsgBoxHelper.ShowError("绘制目标轨迹异常");
+            }
+        }
         //编辑目标
         private async Task EditTarget(List<ModelPosRes> items)
         {