Browse Source

添加测向线

wyq 1 year ago
parent
commit
f973a82b4c
2 changed files with 99 additions and 7 deletions
  1. 90 6
      XdCxRhDW.App/ExtensionsDev/MapControlEx.cs
  2. 9 1
      XdCxRhDW.App/UserControl/CtrlHome.cs

+ 90 - 6
XdCxRhDW.App/ExtensionsDev/MapControlEx.cs

@@ -1376,9 +1376,10 @@ public static class MapControlEx
     }
     }
     public static void DrawDtoPonit(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines)
     public static void DrawDtoPonit(this MapControl ctrl, string title, IEnumerable<(double lon, double lat)> lines)
     {
     {
+        string identify = "DrawPoint_";
         if (lines == null || !lines.Any()) return;
         if (lines == null || !lines.Any()) return;
         var innerData = ctrl.Tag as InnerData;
         var innerData = ctrl.Tag as InnerData;
-
+       
         List<MapDot> list = new List<MapDot>();
         List<MapDot> list = new List<MapDot>();
         var color = ColorHelper.GetColor(title);
         var color = ColorHelper.GetColor(title);
         for (int i = 0; i < lines.Count(); i++)
         for (int i = 0; i < lines.Count(); i++)
@@ -1395,7 +1396,7 @@ public static class MapControlEx
                 IsHitTestVisible = true,
                 IsHitTestVisible = true,
                 Fill = color,
                 Fill = color,
                 Size = 4,
                 Size = 4,
-                Tag = $"DrawPoint_{title}{lines.ElementAt(i).lon}",
+                Tag = $"{identify}{title}{lines.ElementAt(i).lon}",
                 Location = new GeoPoint(p.lat, p.lon),
                 Location = new GeoPoint(p.lat, p.lon),
                 ToolTipPattern = $"{title}",
                 ToolTipPattern = $"{title}",
 
 
@@ -1432,6 +1433,44 @@ public static class MapControlEx
         if (!polyLine.Points.Any()) return;
         if (!polyLine.Points.Any()) return;
         innerData.mMapStorage.Items.Add(polyLine);
         innerData.mMapStorage.Items.Add(polyLine);
     }
     }
+    /// <summary>
+    /// 绘制线
+    /// </summary>
+    /// <param name="ctrl"></param>
+    /// <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)
+    {
+        string identify = "DrawLine_";
+        if (lines == null || !lines.Any()) return;
+        var innerData = ctrl.Tag as InnerData;
+        if (isClear)
+        {
+            var mapItem = innerData.mMapStorage.Items.Find(m => m.Tag.ToString().StartsWith(identify));
+            if (mapItem != null)
+            {
+                innerData.mMapStorage.Items.Remove(mapItem);
+            }
+        }
+        var polyLine = new MapPolyline()
+        {
+            Stroke = Color.Red,
+            StrokeWidth = 2,
+            CanMove = false,
+            Visible = true,
+            IsHitTestVisible = true,
+            Tag = $"{identify}{title}",
+        };
+        polyLine.TitleOptions.Pattern = title;
+        foreach (var item in lines)
+        {
+            if (double.IsNaN(item.lat) || double.IsNaN(item.lon)) continue;
+            polyLine.Points.Add(new GeoPoint(item.lat, item.lon));
+        }
+        if (!polyLine.Points.Any()) return;
+        innerData.mMapStorage.Items.Add(polyLine);
+    }
     public static void DrawErrEllipse(this MapControl ctrl, double r1, double r2, IEnumerable<(double lon, double lat)> lines)
     public static void DrawErrEllipse(this MapControl ctrl, double r1, double r2, IEnumerable<(double lon, double lat)> lines)
     {
     {
         if (lines == null || !lines.Any()) return;
         if (lines == null || !lines.Any()) return;
@@ -1474,11 +1513,19 @@ public static class MapControlEx
     /// <param name="wcKm"></param>
     /// <param name="wcKm"></param>
     /// <param name="dots"></param>
     /// <param name="dots"></param>
     /// <param name="patterncount"></param>
     /// <param name="patterncount"></param>
-    public static void DrawGdopLineTwo(this MapControl ctrl, string wcKm, IEnumerable<(double lon, double lat)> dots, int patterncount)
+    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;
         if (dots == null || !dots.Any()) return;
+        string identify = "DrawGdopLine_";
         var innerData = ctrl.Tag as InnerData;
         var innerData = ctrl.Tag as InnerData;
-
+        if (isClear)
+        {
+            var mapItem = innerData.mMapStorage.Items.Find(m => m.Tag.ToString().StartsWith(identify));
+            if (mapItem != null)
+            {
+                innerData.mMapStorage.Items.Remove(mapItem);
+            }
+        }
         //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
         //多条线 两个点绘制一个线段 1和2一个线段 3和4一个线段
         List<MapPolyline> polylines = new List<MapPolyline>();
         List<MapPolyline> polylines = new List<MapPolyline>();
         int index = 0;
         int index = 0;
@@ -1503,7 +1550,7 @@ public static class MapControlEx
                     CanRotate = false,
                     CanRotate = false,
                     IsHitTestVisible = true,
                     IsHitTestVisible = true,
                     CanMove = false,
                     CanMove = false,
-                    Tag = $"DrawGdopLine_{wcKm}",
+                    Tag = $"{identify}{wcKm}",
                 };
                 };
 
 
             }
             }
@@ -1570,7 +1617,7 @@ public static class MapControlEx
             //Dialog.Error(ex);
             //Dialog.Error(ex);
         }
         }
     }
     }
-    
+
     /// <summary>
     /// <summary>
     /// 度 转换成 弧度
     /// 度 转换成 弧度
     /// </summary>
     /// </summary>
@@ -1582,6 +1629,42 @@ public static class MapControlEx
         return degrees * degToRadFactor;
         return degrees * degToRadFactor;
     }
     }
 
 
+    /// <summary>
+    /// 计算两个点之间的距离
+    /// </summary>
+    /// <param name="startlon">开始经度</param>
+    /// <param name="startlat">开始纬度</param>
+    /// <param name="endlon">结束经度</param>
+    /// <param name="endlat">结束纬度</param>
+    /// <returns></returns>
+    public static double CalcLineKm(double startlon, double startlat, double endlon, double endlat)
+    {
+        GeoPoint startPoint = new GeoPoint() { Longitude = startlon, Latitude = startlat };
+        GeoPoint endPoint = new GeoPoint() { Longitude = endlon, Latitude = endlat };
+        double result = 0;
+        MapSize sizeInKm = new SphericalMercatorProjection().GeoToKilometersSize(startPoint, new MapSize(Math.Abs(startPoint.Longitude - endPoint.Longitude), Math.Abs(startPoint.Latitude - endPoint.Latitude)));
+        result = Math.Sqrt(sizeInKm.Width * sizeInKm.Width + sizeInKm.Height * sizeInKm.Height);
+        return result;
+    }
+
+    /// <summary>
+    /// 计算方向线坐标
+    /// </summary>
+    /// <param name="lon">经度</param>
+    /// <param name="lat">纬度</param>
+    /// <param name="deg"> 艏向角 角度制</param>
+    /// <param name="dis">长度 m</param>
+    /// <returns></returns>
+    public static (double, double) CalcSituation(double lon, double lat, double deg, double dis)
+    {
+        double arc = 6371.393 * 1000;       //地球平均半径
+        double rad = deg * (Math.PI / 180); //角度转弧度
+        double c_lng = lon + dis * Math.Sin(rad) / (arc * Math.Cos(lat) * 2 * Math.PI / 360);
+
+        double c_lat = lat + dis * Math.Cos(rad) / (arc * 2 * Math.PI / 360);
+
+        return (c_lng, c_lat);  //方向上的另一点坐标
+    }
     /**
     /**
     * 求B点经纬度
     * 求B点经纬度
     * @param A 已知点的经纬度,
     * @param A 已知点的经纬度,
@@ -1926,6 +2009,7 @@ public static class MapControlEx
 
 
         return result;
         return result;
     }
     }
+
     public static void ClearMap(this MapControl ctrl)
     public static void ClearMap(this MapControl ctrl)
     {
     {
         var innerData = ctrl.Tag as InnerData;
         var innerData = ctrl.Tag as InnerData;

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

@@ -986,7 +986,15 @@ namespace XdCxRhDW.App.UserControl
                     return;
                     return;
                 }
                 }
 
 
-                //mapControl1.DrawDtoPonit($"星地[{listSat.FirstOrDefault(m => m.ID == satTx.ID)?.Sat},{listSat.FirstOrDefault(m => m.ID == cdbTx.ID)?.Sat}]时差线", xdDtoLine);
+                double startdeg = 90;
+                double deg = cx.Fx - startdeg;//向东方向
+                //计算接收站到定位点之间的距离
+                var km = MapControlEx.CalcLineKm(satTx.Lon, satTx.Lat, item.PosLon, item.PosLat);
+                var endpoint = MapControlEx.CalcSituation(satTx.Lon, satTx.Lat, deg, km * 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);
 
 
 
 
             }
             }