Browse Source

修改测向线以及添加点击航迹

wyq 1 year ago
parent
commit
550769c07d
2 changed files with 88 additions and 14 deletions
  1. 75 8
      XdCxRhDW.App/ExtensionsDev/MapControlEx.cs
  2. 13 6
      XdCxRhDW.App/UserControl/CtrlHome.cs

+ 75 - 8
XdCxRhDW.App/ExtensionsDev/MapControlEx.cs

@@ -238,6 +238,7 @@ public static class MapControlEx
         internal PopupMenu rectMenu;
         internal Action<(double starLon, double startLat, double centerLon, double centerLat,
     double endLon, double endLat, double lonRange, double latRange)> mOnRectChanged;
+        internal Action<(double Lon, double Lat)> onClickChanged;
         internal MapItemStorage mMapStorage;
         internal MapItemStorage mMapStorageFixed;
         internal MapPolyline distinctPath;
@@ -955,6 +956,71 @@ public static class MapControlEx
         innerData.barM.EndInit();
         return ctrl;
     }
+    /// <summary>
+    /// 使用航迹
+    /// </summary>
+    /// <param name="ctrl"></param>
+    /// <param name="onClickChanged">点击事件返回当前经纬度</param>
+    /// <returns></returns>
+    public static MapControl UseHJ(this MapControl ctrl, Action<(double Lon, double Lat)> onClickChanged = null)
+    {
+        var btnHJ = new BarButtonItem() { Caption = "航迹" };
+        btnHJ.ImageOptions.SvgImage = SvgHelper.CreateMarkDot();
+        btnHJ.Tag = ctrl;
+       
+        var innerData = ctrl.Tag as InnerData;
+        innerData.onClickChanged = onClickChanged;
+        btnHJ.ItemClick += (sender, e) =>
+        {
+            ctrl.MapEditor.SetEditMode();
+            ctrl.MouseClick += AddHJPoint;
+            ctrl.DoubleClick += (sender1, e1) =>
+            {
+                ctrl.MouseClick -= AddHJPoint;
+            };
+        };
+        innerData.barM.BeginInit();
+        innerData.barM.Items.Add(btnHJ);
+        innerData.mapMenu.LinksPersistInfo.Add(new LinkPersistInfo(btnHJ));
+        innerData.barM.EndInit();
+        return ctrl;
+    }
+
+    /// <summary>
+    /// 添加航迹点
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <param name="ctrl"></param>
+    /// <param name="item"></param>
+    public static void AddHJPosItem<T>(this MapControl ctrl, T item) where T : PosData, new()
+    {
+        if (item.PosLon > 180) return;
+        var innerData = ctrl.Tag as InnerData;
+        var mapItem = new MapDot()
+        {
+            EnableHighlighting = DefaultBoolean.True,
+            EnableSelection = DefaultBoolean.False,
+            CanMove = false,
+            Visible = item.Visible,
+            IsHitTestVisible = true,
+            Fill = ColorHelper.IsHtmlColor(item.ColorKey) ? ColorTranslator.FromHtml(item.ColorKey) : ColorHelper.GetColor(item.ColorKey),
+            Size = _dotSize,
+            Tag = item,
+            Location = new GeoPoint(item.PosLat, item.PosLon),
+            ToolTipPattern="dd"
+        };
+        innerData.mMapStorage.Items.Add(mapItem);
+
+    }
+    private static void AddHJPoint(object sender, MouseEventArgs e)
+    {
+        var innerData = (sender as MapControl).Tag as InnerData;
+        var ctrl = sender as MapControl;
+        var geoPoint = ctrl.ScreenPointToCoordPoint(e.Location) as GeoPoint;
+        innerData.onClickChanged?.Invoke((geoPoint.Longitude, geoPoint.Latitude));
+
+    }
+
 
     /// <summary>
     /// 为地图添加右键标点功能
@@ -1379,7 +1445,7 @@ public static class MapControlEx
         string identify = "DrawPoint_";
         if (lines == null || !lines.Any()) return;
         var innerData = ctrl.Tag as InnerData;
-       
+
         List<MapDot> list = new List<MapDot>();
         var color = ColorHelper.GetColor(title);
         for (int i = 0; i < lines.Count(); i++)
@@ -1440,9 +1506,9 @@ public static class MapControlEx
     /// <param name="title"></param>
     /// <param name="lines"></param>
     /// <param name="isClear">是否清除上次绘制</param>
-    public static void DrawLine(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines, bool isClear = true)
+    public static void DrawCXLine(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines, bool isClear = true)
     {
-        string identify = "DrawLine_";
+        string identify = "DrawCXLine_";
         if (lines == null || !lines.Any()) return;
         var innerData = ctrl.Tag as InnerData;
         if (isClear)
@@ -1456,13 +1522,14 @@ public static class MapControlEx
         var polyLine = new MapPolyline()
         {
             Stroke = Color.Red,
-            StrokeWidth = 2,
+            StrokeWidth = 3,
             CanMove = false,
             Visible = true,
             IsHitTestVisible = true,
             Tag = $"{identify}{title}",
+            ToolTipPattern= title,
+
         };
-        polyLine.TitleOptions.Pattern = title;
         foreach (var item in lines)
         {
             if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
@@ -1513,7 +1580,7 @@ public static class MapControlEx
     /// <param name="wcKm"></param>
     /// <param name="dots"></param>
     /// <param name="patterncount"></param>
-    public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount,bool isClear=true)
+    public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount, bool isClear = true)
     {
         if (dots == null || !dots.Any()) return;
         string identify = "DrawGdopLine_";
@@ -1907,6 +1974,7 @@ public static class MapControlEx
         ctrl.MouseEnter += MapControl_MouseEnter;
         ctrl.DoubleClick += EndDistinct;
     }
+
     private static void MarkDot_ItemClick(object sender, ItemClickEventArgs e)
     {
         var ctrl = e.Item.Tag as MapControl;
@@ -2637,5 +2705,4 @@ public static class MapControlEx
         }
 
     }
-}
-
+}

+ 13 - 6
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -55,6 +55,15 @@ namespace XdCxRhDW.App.UserControl
             .UseExportCsv()
             .SetMapLayerType(mapService)
             //.SetMapLayerType("")
+             //.UseHJ(item =>
+             //{
+             //    (double Lon, double Lat) = item;
+             //    PosRes pos = new PosRes();
+             //    pos.PosLon = Lon;
+             //    pos.PosLat = Lat;
+             //    pos.SigTime = DateTime.Now;
+             //    mapControl1.AddHJPosItem(pos);
+             //})
             .UseDrawRect(rect =>
             {
                 (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
@@ -73,6 +82,7 @@ namespace XdCxRhDW.App.UserControl
                 var items = await db.PosRes.Where(p => p.TaskID == tsk.ID).OrderByDescending(p => p.SigTime).ToListAsync();
                 listPos.AddRange(items);
             }
+           
             this.gridHomePosRes.DataSource = listPos;
             mapControl1.SetPosDataSource(listPos.Where(p => p.PosLon <= 180), false);
         }
@@ -985,18 +995,15 @@ namespace XdCxRhDW.App.UserControl
                     DxHelper.MsgBoxHelper.ShowWarning($"测向站信息为空!");
                     return;
                 }
-
-                double startdeg = 90;
-                double deg = cx.Fx - startdeg;//向东方向
+                double startdeg =360;
+                double deg = startdeg- cx.Fx;//向北顺时针方向为夹角
                 //计算测向站到定位点之间的距离
                 var km = MapControlEx.CalcLineKm(satTx.Lon, satTx.Lat, item.PosLon, item.PosLat);
                 var endpoint = MapControlEx.CalcSituation(satTx.Lon, satTx.Lat, deg, (km+100) * 1000);
                 List<(double, double)> points = new List<(double, double)>();
                 points.Add((satTx.Lon, satTx.Lat));
                 points.Add((endpoint.Item1, endpoint.Item2));
-                mapControl1.DrawLine($"测向线角度:{cx.Fx}°", points);
-
-
+                mapControl1.DrawCXLine($"测向线角度:{cx.Fx}°\t\n", points);
             }
             catch (Exception ex)
             {