diff --git a/Plane.FormationCreator.sln b/Plane.FormationCreator.sln
index adcb603..5013cb2 100644
--- a/Plane.FormationCreator.sln
+++ b/Plane.FormationCreator.sln
@@ -33,40 +33,74 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
+ v4.0-Debug|Any CPU = v4.0-Debug|Any CPU
+ v4.0-Release|Any CPU = v4.0-Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{61E2F31E-220A-4E3F-A64D-F7CDC2135008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61E2F31E-220A-4E3F-A64D-F7CDC2135008}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61E2F31E-220A-4E3F-A64D-F7CDC2135008}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61E2F31E-220A-4E3F-A64D-F7CDC2135008}.Release|Any CPU.Build.0 = Release|Any CPU
+ {61E2F31E-220A-4E3F-A64D-F7CDC2135008}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {61E2F31E-220A-4E3F-A64D-F7CDC2135008}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {61E2F31E-220A-4E3F-A64D-F7CDC2135008}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {61E2F31E-220A-4E3F-A64D-F7CDC2135008}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{06848293-9B17-4068-9B35-44D0ED713CD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06848293-9B17-4068-9B35-44D0ED713CD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06848293-9B17-4068-9B35-44D0ED713CD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06848293-9B17-4068-9B35-44D0ED713CD4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {06848293-9B17-4068-9B35-44D0ED713CD4}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {06848293-9B17-4068-9B35-44D0ED713CD4}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {06848293-9B17-4068-9B35-44D0ED713CD4}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {06848293-9B17-4068-9B35-44D0ED713CD4}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{98755514-C2E9-4ABE-8A25-007804577558}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98755514-C2E9-4ABE-8A25-007804577558}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98755514-C2E9-4ABE-8A25-007804577558}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98755514-C2E9-4ABE-8A25-007804577558}.Release|Any CPU.Build.0 = Release|Any CPU
+ {98755514-C2E9-4ABE-8A25-007804577558}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {98755514-C2E9-4ABE-8A25-007804577558}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {98755514-C2E9-4ABE-8A25-007804577558}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {98755514-C2E9-4ABE-8A25-007804577558}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{413C18E2-235F-4E15-B5C1-633657DE5D7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{413C18E2-235F-4E15-B5C1-633657DE5D7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{413C18E2-235F-4E15-B5C1-633657DE5D7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{413C18E2-235F-4E15-B5C1-633657DE5D7A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {413C18E2-235F-4E15-B5C1-633657DE5D7A}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {413C18E2-235F-4E15-B5C1-633657DE5D7A}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {413C18E2-235F-4E15-B5C1-633657DE5D7A}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {413C18E2-235F-4E15-B5C1-633657DE5D7A}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{9C2CAFDA-CF1D-4565-B797-398376FCD346}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C2CAFDA-CF1D-4565-B797-398376FCD346}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C2CAFDA-CF1D-4565-B797-398376FCD346}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C2CAFDA-CF1D-4565-B797-398376FCD346}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9C2CAFDA-CF1D-4565-B797-398376FCD346}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9C2CAFDA-CF1D-4565-B797-398376FCD346}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9C2CAFDA-CF1D-4565-B797-398376FCD346}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9C2CAFDA-CF1D-4565-B797-398376FCD346}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6CCE2AEB-3B38-4C00-B32D-433A990AE2AD}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0111EB6E-72E3-499C-A3BA-022F5BBC4CAF}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
{47141894-ECE3-48CA-8DCF-CA751BDA231E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47141894-ECE3-48CA-8DCF-CA751BDA231E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47141894-ECE3-48CA-8DCF-CA751BDA231E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47141894-ECE3-48CA-8DCF-CA751BDA231E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {47141894-ECE3-48CA-8DCF-CA751BDA231E}.v4.0-Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {47141894-ECE3-48CA-8DCF-CA751BDA231E}.v4.0-Debug|Any CPU.Build.0 = Debug|Any CPU
+ {47141894-ECE3-48CA-8DCF-CA751BDA231E}.v4.0-Release|Any CPU.ActiveCfg = Release|Any CPU
+ {47141894-ECE3-48CA-8DCF-CA751BDA231E}.v4.0-Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Plane.FormationCreator/App.config b/Plane.FormationCreator/App.config
index f5162f7..f138028 100644
--- a/Plane.FormationCreator/App.config
+++ b/Plane.FormationCreator/App.config
@@ -1,18 +1,28 @@
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
@@ -23,4 +33,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Plane.FormationCreator/AppConfig.cs b/Plane.FormationCreator/AppConfig.cs
index bea7877..31b4e58 100644
--- a/Plane.FormationCreator/AppConfig.cs
+++ b/Plane.FormationCreator/AppConfig.cs
@@ -40,7 +40,7 @@ namespace Plane.FormationCreator
App.Current.Exit += (sender, e) =>
{
this.Center = _mapManager.Center;
- this.ZoomLevel = _mapManager.MapView.map.ZoomLevel;
+ this.ZoomLevel = _mapManager.MapView.gmap.Zoom;
this.Save();
};
}
diff --git a/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs b/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs
index e7f59ba..8de9c51 100644
--- a/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs
+++ b/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs
@@ -14,9 +14,9 @@ namespace Plane.FormationCreator.Converters
{
public class FlightTaskStatusToFillConverter : IValueConverter
{
- static SolidColorBrush _normalFill = new SolidColorBrush(Colors.LightGray);
- static SolidColorBrush _runningFill = new SolidColorBrush(Colors.OrangeRed);
- static SolidColorBrush _PausedFill = new SolidColorBrush(Colors.Yellow);
+ static SolidColorBrush _normalFill = new SolidColorBrush(Color.FromRgb(45, 45, 45));
+ static SolidColorBrush _runningFill = new SolidColorBrush(Colors.Green);
+ static SolidColorBrush _PausedFill = new SolidColorBrush(Colors.Red);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var status = (FlightTaskStatus)value;
diff --git a/Plane.FormationCreator/Formation/FlightTask.cs b/Plane.FormationCreator/Formation/FlightTask.cs
index 171288c..d879702 100644
--- a/Plane.FormationCreator/Formation/FlightTask.cs
+++ b/Plane.FormationCreator/Formation/FlightTask.cs
@@ -40,6 +40,7 @@ namespace Plane.FormationCreator.Formation
//if (_TaskType != value)
{
RaisePropertyChanged(nameof(TaskTypeIndex));
+ RaisePropertyChanged(nameof(TaskCnName));
}
}
}
@@ -60,6 +61,21 @@ namespace Plane.FormationCreator.Formation
}
*/
+ public string TaskCnName
+ {
+ get
+ {
+ string CnName = "";
+ switch (TaskType)
+ {
+ case FlightTaskType.TakeOff: CnName = (TaskIndex + 1).ToString() + ".起飞"; break;
+ case FlightTaskType.FlyTo: CnName = (TaskIndex + 1).ToString() + ".航点"; break;
+ case FlightTaskType.Land: CnName = (TaskIndex + 1).ToString() + ".降落"; break;
+ }
+ return CnName;
+ }
+ }
+
public int TaskTypeIndex
{
get {
@@ -83,6 +99,15 @@ namespace Plane.FormationCreator.Formation
}
}
+ //task在所以任务中的index
+ public int TaskIndex
+ {
+ get
+ {
+ return _flightTaskManager.Tasks.IndexOf(this);
+ }
+ }
+
private bool _IsSelected;
public bool IsSelected
{
diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs
index ec83dcb..40e0b37 100644
--- a/Plane.FormationCreator/Formation/FlightTaskManager.cs
+++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs
@@ -18,8 +18,9 @@ namespace Plane.FormationCreator.Formation
{
public FlightTaskManager(CopterManager copterManager)
{
- _copterManager = copterManager;
-
+ LoadIni();
+ _copterManager = copterManager;
+
//AddTakeOffTask(_copterManager.Copters);
_copterManager.Copters.CollectionChanged += (sender, e) =>
@@ -87,6 +88,7 @@ namespace Plane.FormationCreator.Formation
}
private CopterManager _copterManager;
+
private int _TakeOffNumAttr = 1;
public int TakeOffNumAttr
@@ -191,6 +193,35 @@ namespace Plane.FormationCreator.Formation
private set { Set(nameof(CurrentRunningTaskIndex), ref _CurrentRunningTaskIndex, value); }
}
+ private int _ColumnCount = 5;
+ public int ColumnCount
+ {
+ get { return _ColumnCount; }
+ set { Set(nameof(ColumnCount), ref _ColumnCount, value); }
+ }
+
+
+ private float _ColumnDistance = 4.0f;
+ public float ColumnDistance
+ {
+ get { return _ColumnDistance; }
+ set { Set(nameof(ColumnDistance), ref _ColumnDistance, value); }
+ }
+
+ private float _RowDistance = 4.0f;
+ public float RowDistance
+ {
+ get { return _RowDistance; }
+ set { Set(nameof(RowDistance), ref _RowDistance, value); }
+ }
+
+ private int _Orientation = 0;
+ public int Orientation
+ {
+ get { return _Orientation; }
+ set { Set(nameof(Orientation), ref _Orientation, value); }
+ }
+
private TasksStatus _TaskState = TasksStatus.Stop;
public TasksStatus TaskState
@@ -227,12 +258,11 @@ namespace Plane.FormationCreator.Formation
var newTask = new FlightTask(FlightTaskType.FlyTo);
int coptindex = 0;
- int colnum = 20; //自动生成列数=4
- float coldis = 2.5f;//列相距5米
- float rowdis = 5f;//行相距5米
+ int colnum = ColumnCount; //自动生成列数=4
+ float coldis = ColumnDistance;//列相距5米
+ float rowdis = RowDistance;//行相距5米
float matrixdis = 20; //生成方阵距离30米
-
int currcol = 0; //当前列号
int currrow = 0; //当前行
Tuple colLatLng = new Tuple(0, 0);
@@ -1040,9 +1070,9 @@ namespace Plane.FormationCreator.Formation
var pointjson= points[i];
System.Windows.Point point = new System.Windows.Point((int)pointjson.x, (int)pointjson.y);
- Microsoft.Maps.MapControl.WPF.Location loc = _mapManager.MapView.map.ViewportPointToLocation(point);
- SelectedTask.SingleCopterInfos[i].TargetLat = loc.Latitude;
- SelectedTask.SingleCopterInfos[i].TargetLng = loc.Longitude;
+ var loc = _mapManager.MapView.gmap.FromLocalToLatLng((int)point.X , (int)point.Y);
+ SelectedTask.SingleCopterInfos[i].TargetLat = loc.Lat;
+ SelectedTask.SingleCopterInfos[i].TargetLng = loc.Lng;
}
}
@@ -1314,6 +1344,40 @@ namespace Plane.FormationCreator.Formation
}
}
}
+
+ private void LoadIni()
+ {
+ Windows.IniHelper.IniFiles inifilse = new Windows.IniHelper.IniFiles();
+ string readvalue = "";
+ int intTemp;
+ float floatTemp;
+ readvalue = inifilse.IniReadvalue("Default", "ColumnCount");
+ if (readvalue!= "" && int.TryParse(readvalue,out intTemp))
+ ColumnCount = int.Parse(readvalue);
+
+ readvalue = inifilse.IniReadvalue("Default", "ColumnDistance");
+ if (readvalue != "" && float.TryParse(readvalue, out floatTemp))
+ ColumnDistance = float.Parse(readvalue);
+
+ readvalue = inifilse.IniReadvalue("Default", "RowDistance");
+ if (readvalue != "" && float.TryParse(readvalue, out floatTemp))
+ RowDistance = float.Parse(readvalue);
+
+ readvalue = inifilse.IniReadvalue("Default", "Orientation");
+ if (readvalue != "" && int.TryParse(readvalue, out intTemp))
+ Orientation = int.Parse(readvalue);
+
+
+ }
+
+ public void SaveIni()
+ {
+ Windows.IniHelper.IniFiles inifilse = new Windows.IniHelper.IniFiles();
+ inifilse.IniWritevalue("Default", "ColumnCount", ColumnCount.ToString());
+ inifilse.IniWritevalue("Default", "ColumnDistance", ColumnDistance.ToString());
+ inifilse.IniWritevalue("Default", "RowDistance", RowDistance.ToString());
+ inifilse.IniWritevalue("Default", "Orientation", Orientation.ToString());
+ }
}
public class FlightTaskAddedEventArgs : EventArgs
diff --git a/Plane.FormationCreator/Formation/LatLng.cs b/Plane.FormationCreator/Formation/LatLng.cs
index 34a8dfa..e38bcd7 100644
--- a/Plane.FormationCreator/Formation/LatLng.cs
+++ b/Plane.FormationCreator/Formation/LatLng.cs
@@ -1,4 +1,6 @@
-using System;
+using GMap.NET;
+using Plane.FormationCreator.Maps;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
diff --git a/Plane.FormationCreator/GMap.cs b/Plane.FormationCreator/GMap.cs
new file mode 100644
index 0000000..8d184b3
--- /dev/null
+++ b/Plane.FormationCreator/GMap.cs
@@ -0,0 +1,14 @@
+using System.Windows.Controls;
+using System.Windows.Media;
+using GMap.NET.WindowsPresentation;
+using System.Globalization;
+using System.Windows;
+using System;
+
+namespace Plane.GoogleMap
+{
+ class GMap : GMapControl
+ {
+
+ }
+}
diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml
index ac51b35..2cc359b 100644
--- a/Plane.FormationCreator/MainWindow.xaml
+++ b/Plane.FormationCreator/MainWindow.xaml
@@ -42,6 +42,7 @@
+
+ />
+
@@ -115,7 +119,7 @@
-
+
@@ -123,14 +127,29 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+ /// WGS-84、GCJ-02(火星坐标系)、BD-09(百度坐标系)之间的坐标转换器
+ ///
+ public static class MapConverter
+ {
+ ///
+ /// Gmap的PointLatLng转换为WGS84
+ ///
+ ///
+ ///
+ public static LatLng ToWGS84(this PointLatLng LatLng_GCJ02)
+ {
+// double WGS84_lat;
+// double WGS84_lng;
+// GCJ02ToWGS84Exact(LatLng_GCJ02.Lat, LatLng_GCJ02.Lng, out WGS84_lat, out WGS84_lng);
+// return new LatLng(WGS84_lat, WGS84_lng);
+ return new LatLng(LatLng_GCJ02.Lat, LatLng_GCJ02.Lng);
+ }
+
+ ///
+ /// LatLng转换为ToGCJ02
+ ///
+ ///
+ ///
+ public static PointLatLng ToGCJ02(this LatLng LatLng_WGS84)
+ {
+
+ // double GCJ02_lat;
+ // double GCJ02_lng;
+ // WGS84ToGCJ02(LatLng_WGS84.Lat, LatLng_WGS84.Lng, out GCJ02_lat, out GCJ02_lng);
+ // return new PointLatLng(GCJ02_lat, GCJ02_lng);
+ return new PointLatLng(LatLng_WGS84.Lat, LatLng_WGS84.Lng);
+ }
+
+ ///
+ /// 圆周率
+ ///
+ private const double PI = 3.1415926535897932384626;
+ private const double X_PI = PI * 3000.0 / 180.0;
+
+ ///
+ /// 地理位置是否位于中国以外
+ ///
+ /// WGS-84坐标纬度
+ /// WGS-84坐标经度
+ ///
+ /// true:国外
+ /// false:国内
+ ///
+ public static bool OutOfChina(double wgLat, double wgLon)
+ {
+ if (wgLon < 72.004 || wgLon > 137.8347) return true;
+ if (wgLat < 0.8293 || wgLat > 55.8271) return true;
+
+ return false;
+ }
+
+ ///
+ /// WGS-84坐标系转火星坐标系 (GCJ-02)
+ ///
+ /// WGS-84坐标纬度
+ /// WGS-84坐标经度
+ /// 输出:GCJ-02坐标纬度
+ /// 输出:GCJ-02坐标经度
+ public static void WGS84ToGCJ02(double wgLat, double wgLon, out double mgLat, out double mgLon)
+ {
+ if (OutOfChina(wgLat, wgLon))
+ {
+ mgLat = wgLat;
+ mgLon = wgLon;
+ }
+ else
+ {
+ double dLat;
+ double dLon;
+ Delta(wgLat, wgLon, out dLat, out dLon);
+ mgLat = wgLat + dLat;
+ mgLon = wgLon + dLon;
+ }
+ }
+
+ ///
+ /// 火星坐标系 (GCJ-02)转WGS-84坐标系
+ ///
+ /// GCJ-02坐标纬度
+ /// GCJ-02坐标经度
+ /// 输出:WGS-84坐标纬度
+ /// 输出:WGS-84坐标经度
+ public static void GCJ02ToWGS84(double mgLat, double mgLon, out double wgLat, out double wgLon)
+ {
+ if (OutOfChina(mgLat, mgLon))
+ {
+ wgLat = mgLat;
+ wgLon = mgLon;
+ }
+ else
+ {
+ double dLat;
+ double dLon;
+ Delta(mgLat, mgLon, out dLat, out dLon);
+ wgLat = mgLat - dLat;
+ wgLon = mgLon - dLon;
+ }
+ }
+
+ ///
+ /// 火星坐标系 (GCJ-02)转WGS-84坐标系
+ ///
+ /// GCJ-02坐标纬度
+ /// GCJ-02坐标经度
+ /// 输出:WGS-84坐标纬度
+ /// 输出:WGS-84坐标经度
+ public static void GCJ02ToWGS84Exact(double mgLat, double mgLon, out double wgLat, out double wgLon)
+ {
+ const double InitDelta = 0.01;
+ const double Threshold = 0.000001;
+
+ double dLat = InitDelta;
+ double dLon = InitDelta;
+ double mLat = mgLat - dLat;
+ double mLon = mgLon - dLon;
+ double pLat = mgLat + dLat;
+ double pLon = mgLon + dLon;
+
+ double nLat;
+ double nLon;
+
+ int i = 0;
+ do
+ {
+ wgLat = (mLat + pLat) / 2;
+ wgLon = (mLon + pLon) / 2;
+
+ WGS84ToGCJ02(wgLat, wgLon, out nLat, out nLon);
+
+ dLat = nLat - mgLat;
+ dLon = nLon - mgLon;
+ if ((Math.Abs(dLat) < Threshold) && (Math.Abs(dLon) < Threshold)) break;
+
+ if (dLat > 0) pLat = wgLat; else mLat = wgLat;
+ if (dLon > 0) pLon = wgLon; else mLon = wgLon;
+ System.Diagnostics.Debug.WriteLine($"times:{i}");
+ } while (++i <= 30);
+ }
+
+ ///
+ /// 百度坐标系 (BD-09)转火星坐标系 (GCJ-02)
+ ///
+ /// 百度坐标系纬度
+ /// 百度坐标系经度
+ /// 输出:GCJ-02坐标纬度
+ /// 输出:GCJ-02坐标经度
+ public static void BD09ToGCJ02(double bdLat, double bdLon, out double mgLat, out double mgLon)
+ {
+ double x = bdLon - 0.0065;
+ double y = bdLat - 0.006;
+ double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * X_PI);
+ double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * X_PI);
+ mgLat = z * Math.Sin(theta);
+ mgLon = z * Math.Cos(theta);
+ }
+
+ ///
+ /// 火星坐标系 (GCJ-02)转百度坐标系 (BD-09)
+ ///
+ /// GCJ-02坐标纬度
+ /// GCJ-02坐标经度
+ /// 输出:百度坐标系纬度
+ /// 输出:百度坐标系经度
+ public static void GCJ02ToBD09(double mgLat, double mgLon, out double bdLat, out double bdLon)
+ {
+ double x = mgLon;
+ double y = mgLat;
+ double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * X_PI);
+ double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * X_PI);
+ bdLat = z * Math.Sin(theta) + 0.006;
+ bdLon = z * Math.Cos(theta) + 0.0065;
+ }
+
+ ///
+ /// WGS-84坐标系转百度坐标系 (BD-09)
+ ///
+ /// WGS-84坐标纬度
+ /// WGS-84坐标经度
+ /// 输出:百度坐标系纬度
+ /// 输出:百度坐标系经度
+ public static void WGS84ToBD09(double wgLat, double wgLon, out double bdLat, out double bdLon)
+ {
+ double mgLat;
+ double mgLon;
+
+ WGS84ToGCJ02(wgLat, wgLon, out mgLat, out mgLon);
+ GCJ02ToBD09(mgLat, mgLon, out bdLat, out bdLon);
+ }
+
+ ///
+ /// 百度坐标系 (BD-09)转WGS-84坐标系
+ ///
+ /// 百度坐标系纬度
+ /// 百度坐标系经度
+ /// 输出:WGS-84坐标纬度
+ /// 输出:WGS-84坐标经度
+ public static void BD09ToWGS84(double bdLat, double bdLon, out double wgLat, out double wgLon)
+ {
+ double mgLat;
+ double mgLon;
+
+ BD09ToGCJ02(bdLat, bdLon, out mgLat, out mgLon);
+ GCJ02ToWGS84(mgLat, mgLon, out wgLat, out wgLon);
+ }
+
+ public static double Distance(double LatA, double LonA, double LatB, double LonB)
+ {
+ const double EarthR = 6371000.0;
+
+ double x = Math.Cos(LatA * PI / 180.0) * Math.Cos(LatB * PI / 180.0) * Math.Cos((LonA - LonB) * PI / 180);
+ double y = Math.Sin(LatA * PI / 180.0) * Math.Sin(LatB * PI / 180.0);
+ double s = x + y;
+ if (s > 1) s = 1;
+ if (s < -1) s = -1;
+
+ return Math.Acos(s) * EarthR;
+ }
+
+ private static void Delta(double Lat, double Lon, out double dLat, out double dLon)
+ {
+ const double AXIS = 6378245.0;
+ const double EE = 0.00669342162296594323;
+
+ dLat = TransformLat(Lon - 105.0, Lat - 35.0);
+ dLon = TransformLon(Lon - 105.0, Lat - 35.0);
+ double radLat = Lat / 180.0 * PI;
+ double magic = Math.Sin(radLat);
+ magic = 1 - EE * magic * magic;
+ double sqrtMagic = Math.Sqrt(magic);
+ dLat = (dLat * 180.0) / ((AXIS * (1 - EE)) / (magic * sqrtMagic) * PI);
+ dLon = (dLon * 180.0) / (AXIS / sqrtMagic * Math.Cos(radLat) * PI);
+ }
+
+ private static double TransformLat(double x, double y)
+ {
+ double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));
+ ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.Sin(y * PI) + 40.0 * Math.Sin(y / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (160.0 * Math.Sin(y / 12.0 * PI) + 320 * Math.Sin(y * PI / 30.0)) * 2.0 / 3.0;
+ return ret;
+ }
+
+ private static double TransformLon(double x, double y)
+ {
+ double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));
+ ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.Sin(x * PI) + 40.0 * Math.Sin(x / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (150.0 * Math.Sin(x / 12.0 * PI) + 300.0 * Math.Sin(x / 30.0 * PI)) * 2.0 / 3.0;
+ return ret;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Plane.FormationCreator/Plane.FormationCreator.csproj b/Plane.FormationCreator/Plane.FormationCreator.csproj
index 4546f32..47206c1 100644
--- a/Plane.FormationCreator/Plane.FormationCreator.csproj
+++ b/Plane.FormationCreator/Plane.FormationCreator.csproj
@@ -14,6 +14,8 @@
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
4
+
+
AnyCPU
@@ -25,6 +27,8 @@
prompt
4
true
+ true
+ false
AnyCPU
@@ -39,6 +43,14 @@
gcs.ico
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
+ True
+
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
+ True
+
..\packages\MvvmLightLibs.5.2.0.0\lib\net45\GalaSoft.MvvmLight.dll
True
@@ -51,6 +63,22 @@
..\packages\MvvmLightLibs.5.2.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll
True
+
+ ..\packages\GMap.NET.Windows.1.8.5\lib\net40\GMap.NET.Core.dll
+ True
+
+
+ ..\packages\GMap.NET.Windows.1.8.5\lib\net40\GMap.NET.WindowsPresentation.dll
+ True
+
+
+ ..\packages\HelixToolkit.2.4.0\lib\netstandard1.1\HelixToolkit.dll
+ True
+
+
+ ..\packages\HelixToolkit.Wpf.2.4.0\lib\net45\HelixToolkit.Wpf.dll
+ True
+
..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll
True
@@ -71,13 +99,26 @@
..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll
-
- ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
+
+ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
True
+
+
+ ..\packages\System.Data.SQLite.Core.1.0.109.1\lib\net46\System.Data.SQLite.dll
+ True
+
+
+ ..\packages\System.Data.SQLite.EF6.1.0.109.0\lib\net46\System.Data.SQLite.EF6.dll
+ True
+
+
+ ..\packages\System.Data.SQLite.Linq.1.0.109.0\lib\net46\System.Data.SQLite.Linq.dll
+ True
+
..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll
True
@@ -140,8 +181,8 @@
-
-
+
+
ModifyParam.xaml
@@ -157,6 +198,7 @@
+
ControlPanelView.xaml
@@ -179,9 +221,15 @@
ModifyTaskView.xaml
+
+ SetCoptersPutView.xaml
+
TaskBarView.xaml
+
+ View3D.xaml
+
@@ -291,10 +339,18 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
@@ -336,6 +392,13 @@
+
+
+
+ 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
+
+
+
diff --git a/Plane.FormationCreator/Util/ParamFile.cs b/Plane.FormationCreator/Util/ParamFile.cs
new file mode 100644
index 0000000..bc7feba
--- /dev/null
+++ b/Plane.FormationCreator/Util/ParamFile.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+
+namespace Plane.Util
+{
+ public class ParamFile
+ {
+ //private static readonly ILog log =
+ // LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+
+ public static string FileMask = "Parameter File|*.param;*.parm|All Files|*.*";
+
+ public static Dictionary loadParamFile(string Filename)
+ {
+ Dictionary param = new Dictionary();
+
+ using (StreamReader sr = new StreamReader(Filename))
+ {
+ while (!sr.EndOfStream)
+ {
+ string line = sr.ReadLine();
+
+ if (line.Contains("NOTE:"))
+ {
+ // CustomMessageBox.Show(line, "Saved Note");
+ continue;
+ }
+
+ if (line.StartsWith("#"))
+ continue;
+
+ string[] items = line.Split(new char[] {' ', ',', '\t'}, StringSplitOptions.RemoveEmptyEntries);
+
+ if (items.Length != 2)
+ continue;
+
+ string name = items[0];
+ double value = 0;
+ try
+ {
+ value = double.Parse(items[1], System.Globalization.CultureInfo.InvariantCulture);
+ // new System.Globalization.CultureInfo("en-US"));
+ }
+ catch (Exception ex)
+ {
+ //log.Error(ex);
+ throw new FormatException("Invalid number on param " + name + " : " + items[1].ToString());
+ }
+
+ if (name == "SYSID_SW_MREV")
+ continue;
+ if (name == "WP_TOTAL")
+ continue;
+ if (name == "CMD_TOTAL")
+ continue;
+ if (name == "FENCE_TOTAL")
+ continue;
+ if (name == "SYS_NUM_RESETS")
+ continue;
+ if (name == "ARSPD_OFFSET")
+ continue;
+ if (name == "GND_ABS_PRESS")
+ continue;
+ if (name == "GND_TEMP")
+ continue;
+ if (name == "CMD_INDEX")
+ continue;
+ if (name == "LOG_LASTFILE")
+ continue;
+ if (name == "FORMAT_VERSION")
+ continue;
+
+ param[name] = value;
+ }
+ }
+
+ return param;
+ }
+
+ public static void SaveParamFile(string fn, Hashtable paramlist)
+ {
+ using (StreamWriter sw = new StreamWriter(File.Open(fn, FileMode.Create)))
+ {
+ string input = DateTime.Now + " Frame : ";
+ //if (MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.ArduPlane)
+ // {
+ // input = DateTime.Now + " Plane: Skywalker";
+ // }
+ // InputBox.Show("Custom Note", "Enter your Notes/Frame Type etc", ref input);
+ if (input != "")
+ sw.WriteLine("#NOTE: " + input.Replace(',', '|'));
+
+ var list = new SortedList(paramlist);
+
+ foreach (var item in list.Keys)
+ {
+ double value = double.Parse(paramlist[item].ToString());
+
+ string valueasstring = value.ToString(new System.Globalization.CultureInfo("en-US"));
+
+ if (valueasstring.Contains("."))
+ {
+ sw.WriteLine(item + "," +
+ ((float) value).ToString(new System.Globalization.CultureInfo("en-US")));
+ }
+ else
+ {
+ sw.WriteLine(item + "," + valueasstring);
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs
index 1b2dd0d..487b71f 100644
--- a/Plane.FormationCreator/ViewModels/ConnectViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ConnectViewModel.cs
@@ -195,6 +195,18 @@ namespace Plane.FormationCreator.ViewModels
}
}
+ private ICommand _UpdateAllCopterCommand;
+ public ICommand UpdateAllCopterCommand
+ {
+ get
+ {
+ return _UpdateAllCopterCommand ?? (_UpdateAllCopterCommand = new RelayCommand(async () =>
+ {
+ await commModule.UpdateCommModule();
+ }));
+ }
+ }
+
private ICommand _CommDataAsync;
public ICommand CommDataAsync
{
diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
index ae894e8..e323a3b 100644
--- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
@@ -940,7 +940,7 @@ namespace Plane.FormationCreator.ViewModels
int utcsecond = DateTime.UtcNow.AddSeconds(5).Second;
//循环3次 发送起飞命令 避免通信问题
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 5; i++)
{
await _commModuleManager.DoMissionStartAsync(utchour,
utcminute,
@@ -949,7 +949,7 @@ namespace Plane.FormationCreator.ViewModels
_flightTaskManager.OriginLat
);
-
+ /*
foreach (var vcopter in _copterManager.Copters)
{
await vcopter.MissionStartAsync(utchour,
@@ -959,6 +959,7 @@ namespace Plane.FormationCreator.ViewModels
_flightTaskManager.OriginLat
);
}
+ */
await Task.Delay(10).ConfigureAwait(false);
}
@@ -1185,7 +1186,7 @@ namespace Plane.FormationCreator.ViewModels
foreach (LEDInfo ledInfo in LEDInfos)
{
Color color = (Color)ColorConverter.ConvertFromString("#" + ledInfo.LEDRGB);
- if (ledInfo.LEDMode == 5) ledInfo.LEDMode = 6;
+ //if (ledInfo.LEDMode == 5) ledInfo.LEDMode = 6;
IMission LEDMission = Mission.CreateLEDControlMission(
(int)(ledInfo.Delay * 10),
ledInfo.LEDMode,
diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
index fb88f2a..8262439 100644
--- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs
@@ -25,13 +25,12 @@ namespace Plane.FormationCreator.ViewModels
_copterManager = copterManager;
_mapManager = mapManager;
_flightTaskManager = flightTaskManager;
+ /*
System.Timers.Timer t = new System.Timers.Timer(5000); //实例化Timer类,设置间隔时间为1秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件;
t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
- t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
-
-
-
+ t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
+ */
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
@@ -46,16 +45,12 @@ namespace Plane.FormationCreator.ViewModels
allrec += copterrec;
allsend += coptersend;
copter.ResetCommunicationNumber();
-
-
}
allrec /= 5;
allsend /= 5;
if (_copterManager.Copters.Count>0)
Communinfo = "接收:" + allrec + "/s;发送:"+ allsend+"/s 单机:"+ allrec/ _copterManager.Copters.Count+"/s;"+
allsend / _copterManager.Copters.Count+"/s";
-
-
}
private CopterManager _copterManager;
@@ -74,7 +69,7 @@ namespace Plane.FormationCreator.ViewModels
private int _virtualCopterId = 1;
private LatLng? _lastVirtualCopterLocation;
- private string _Communinfo = "0字节/秒";
+ private string _Communinfo = "";
public string Communinfo
{
get { return _Communinfo; }
@@ -95,6 +90,8 @@ namespace Plane.FormationCreator.ViewModels
set { Set(nameof(ContinuousNum), ref _ContinuousNum, value); }
}
+
+
private ICommand _IntervalSelectCoptersCommand;
public ICommand IntervalSelectCoptersCommand
{
@@ -134,9 +131,9 @@ namespace Plane.FormationCreator.ViewModels
var center = _mapManager.Center;
string id;
- int colnum = 5; //自动生成列数=4
- float coldis = 3.5f;//列相距5米
- float rowdis = 3f;//行相距5米
+ int colnum = _flightTaskManager.ColumnCount; //自动生成列数=4
+ float coldis = _flightTaskManager.ColumnDistance;//列相距5米
+ float rowdis = _flightTaskManager.RowDistance;//行相距5米
int currcol = 0; //当前列号
int currrow = 0; //当前行
Tuple colheadLatLng = new Tuple(0, 0);
@@ -147,8 +144,6 @@ namespace Plane.FormationCreator.ViewModels
for (int i = 0; i < addcount; ++i, ++_virtualCopterId)
{
id = _virtualCopterId.ToString();
-
-
if (i == 0)
{
@@ -196,13 +191,39 @@ namespace Plane.FormationCreator.ViewModels
);
await copter.ConnectAsync();
await copter.GetCopterDataAsync();
- _copterManager.Copters.Add(copter);
+ _copterManager.Copters.AddCopter(copter);
_copterManager.CopterStatus.Add(false);
}
}));
}
}
+ private ICommand _SetCoptersPutCommand;
+ public ICommand SetCoptersPutCommand
+ {
+ get
+ {
+ return _SetCoptersPutCommand ?? (_SetCoptersPutCommand = new RelayCommand(async () =>
+ {
+ var SetCoptersPutView = new Views.SetCoptersPutView(
+ _flightTaskManager.ColumnCount,
+ _flightTaskManager.ColumnDistance,
+ _flightTaskManager.RowDistance,
+ _flightTaskManager.Orientation
+ );
+ if (SetCoptersPutView.ShowDialog() == true)
+ {
+ _flightTaskManager.ColumnCount = int.Parse(SetCoptersPutView.textboxColNum.Text);
+ _flightTaskManager.ColumnDistance = float.Parse(SetCoptersPutView.textboxColDis.Text);
+ _flightTaskManager.RowDistance = float.Parse(SetCoptersPutView.textboxRowDis.Text);
+ _flightTaskManager.Orientation = int.Parse(SetCoptersPutView.textboxOrientation.Text);
+ _flightTaskManager.SaveIni();
+ }
+ await Task.Delay(100);
+ }));
+ }
+ }
+
private ICommand _ClearCoptersCommand;
public ICommand ClearCoptersCommand
{
diff --git a/Plane.FormationCreator/ViewModels/MainViewModel.cs b/Plane.FormationCreator/ViewModels/MainViewModel.cs
index e0d7f52..8bb738f 100644
--- a/Plane.FormationCreator/ViewModels/MainViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/MainViewModel.cs
@@ -22,6 +22,7 @@ namespace Plane.FormationCreator.ViewModels
_copterListViewModel = copterListViewModel;
Plane.Windows.Messages.Message.Configure(showAction: msg => this.Message = msg);
+ Plane.Windows.Messages.Message.Configure(connectAction: connected => this.CommunicationModuleConnected = connected);
this.SwitchVelocityModeButtonContent = GetSwitchVelocityModeButtonContent();
@@ -63,6 +64,16 @@ namespace Plane.FormationCreator.ViewModels
}
}
+ private bool _CommunicationModuleConnected;
+ public bool CommunicationModuleConnected
+ {
+ get { return _CommunicationModuleConnected; }
+ set
+ {
+ Set(nameof(CommunicationModuleConnected), ref _CommunicationModuleConnected, value);
+ }
+ }
+
private List _MessageList = new List();
public string Messages
@@ -137,6 +148,30 @@ namespace Plane.FormationCreator.ViewModels
}
}
+ private int _MapMode=0;
+ public int MapMode
+ {
+ get { return _MapMode; }
+ set { Set(nameof(MapMode), ref _MapMode, value); }
+ }
+
+ private ICommand _ChangeMapModeCommand;
+ public ICommand ChangeMapModeCommand
+ {
+ get
+ {
+ return _ChangeMapModeCommand ?? (_ChangeMapModeCommand = new RelayCommand(() =>
+ {
+ if (MapMode == 0)
+ MapMode = 1;
+ else
+ MapMode = 0;
+ }));
+ }
+ }
+
+
+
private ICommand _ExportTasksCommand;
public ICommand ExportTasksCommand
diff --git a/Plane.FormationCreator/ViewModels/ModiLEDModel.cs b/Plane.FormationCreator/ViewModels/ModiLEDModel.cs
new file mode 100644
index 0000000..54d9841
--- /dev/null
+++ b/Plane.FormationCreator/ViewModels/ModiLEDModel.cs
@@ -0,0 +1,13 @@
+using GalaSoft.MvvmLight;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Plane.FormationCreator.ViewModels
+{
+ class ModiLEDModel : ViewModelBase
+ {
+ }
+}
diff --git a/Plane.FormationCreator/ViewModels/ModiLEDViewModel.cs b/Plane.FormationCreator/ViewModels/ModiLEDViewModel.cs
new file mode 100644
index 0000000..84d9cbf
--- /dev/null
+++ b/Plane.FormationCreator/ViewModels/ModiLEDViewModel.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Plane.FormationCreator.ViewModels
+{
+ class ModiLEDViewModel :ViewModelBase
+ {
+ }
+}
diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
index 19f270c..1ef85a5 100644
--- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
@@ -278,6 +278,28 @@ namespace Plane.FormationCreator.ViewModels
double tlng = 0;
double avgl = 0;
+ if (_copterManager.SelectedCopters.Count() > 2)
+ {
+ List selectTaskInfos = new List();
+ for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
+ {
+
+ if (_copterManager.SelectedCopters.Contains(_flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter))
+ selectTaskInfos.Add(_flightTaskManager.SelectedTask.SingleCopterInfos[i]);
+ }
+ selectTaskInfos.Sort((x, y) => x.TargetLng.CompareTo(y.TargetLng));
+ minlng = selectTaskInfos[0].TargetLng;
+ maxlng = selectTaskInfos[selectTaskInfos.Count - 1].TargetLng;
+ tlng = (maxlng - minlng) / (selectTaskInfos.Count - 1);
+
+ for (int i = 0; i < selectTaskInfos.Count; i++)
+ {
+ selectTaskInfos[i].TargetLng = minlng + i * tlng;
+ }
+ }
+
+
+ /*
if (Alert.Show("本操作将导致飞机位置重新排列,编号最小的飞机在最左边,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.OK)
{
@@ -334,7 +356,7 @@ namespace Plane.FormationCreator.ViewModels
}
-
+ */
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
@@ -359,6 +381,27 @@ namespace Plane.FormationCreator.ViewModels
double avgl = 0;
+ if (_copterManager.SelectedCopters.Count() > 2)
+ {
+ List selectTaskInfos = new List();
+ for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
+ {
+
+ if (_copterManager.SelectedCopters.Contains(_flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter))
+ selectTaskInfos.Add(_flightTaskManager.SelectedTask.SingleCopterInfos[i]);
+ }
+ selectTaskInfos.Sort((x, y) => x.TargetLat.CompareTo(y.TargetLat));
+ minlat = selectTaskInfos[0].TargetLat;
+ maxlat = selectTaskInfos[selectTaskInfos.Count - 1].TargetLat;
+ tlat = (maxlat - minlat) / (selectTaskInfos.Count - 1);
+
+ for (int i = 0; i < selectTaskInfos.Count; i++)
+ {
+ selectTaskInfos[i].TargetLat = minlat + i * tlat;
+ }
+ }
+
+ /*
if (Alert.Show("本操作将导致飞机位置重新排列,编号最小的飞机在最上边,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.OK)
{
@@ -414,12 +457,12 @@ namespace Plane.FormationCreator.ViewModels
}
}
-
+
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
- }
+ }*/
}));
}
}
@@ -1183,6 +1226,8 @@ public ICommand VerticlAlignmentCommand
{
return _calDistinceCommand ?? (_calDistinceCommand = new RelayCommand(async =>
{
+ if (_copterManager.AcceptingControlCopters.Count() < 2)
+ return;
double minDistance = double.MaxValue;
@@ -1222,6 +1267,34 @@ public ICommand VerticlAlignmentCommand
}
}
+ private ICommand _WayPointDistinceCommand;
+ public ICommand WayPointDistinceCommand
+ {
+ get
+ {
+ return _WayPointDistinceCommand ?? (_WayPointDistinceCommand = new RelayCommand(async =>
+ {
+ if (_copterManager.AcceptingControlCopters.Count() != 1)
+ return;
+
+ int taskIndex = _flightTaskManager.SelectedTaskIndex;
+ if (taskIndex != 0 || _flightTaskManager.SelectedTask.TaskType == FlightTaskType.FlyTo)
+ {
+ var curCopter = _copterManager.AcceptingControlCopters.First();
+
+ var prevWaypoint = _flightTaskManager.Tasks[taskIndex - 1].SingleCopterInfos.FirstOrDefault(c => c.Copter == curCopter);
+ var curWaypoint = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(c => c.Copter == curCopter);
+
+ double distance = GeographyUtils.CalcDistance(
+ prevWaypoint.TargetLat, prevWaypoint.TargetLng, prevWaypoint.TargetAlt,
+ curWaypoint.TargetLat, curWaypoint.TargetLng, curWaypoint.TargetAlt);
+
+ Message.Show($"航点间距 = {distance}");
+ }
+ }));
+ }
+ }
+
diff --git a/Plane.FormationCreator/ViewModels/View3DViewModel.cs b/Plane.FormationCreator/ViewModels/View3DViewModel.cs
new file mode 100644
index 0000000..7730890
--- /dev/null
+++ b/Plane.FormationCreator/ViewModels/View3DViewModel.cs
@@ -0,0 +1,86 @@
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Command;
+using HelixToolkit.Wpf;
+using Plane.FormationCreator.Formation;
+using Plane.Geography;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Media3D;
+
+namespace Plane.FormationCreator.ViewModels
+{
+ public class View3DViewModel : ViewModelBase
+ {
+ private FlightTaskManager _flightTaskManager;
+
+ public View3DViewModel(FlightTaskManager flightTaskManager)
+ {
+ modelGroup = new Model3DGroup();
+ planeGroup = new Model3DGroup();
+ waypointGroup = new Model3DGroup();
+ modelGroup.Children.Add(planeGroup);
+ modelGroup.Children.Add(waypointGroup);
+ this.Model = modelGroup;
+ _flightTaskManager = flightTaskManager;
+ _flightTaskManager.PropertyChanged += new PropertyChangedEventHandler(flightTaskPropertyChanged);
+ }
+
+ private void flightTaskPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(FlightTaskManager.SelectedTaskIndex):
+ SelectTask();
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void SelectTask()
+ {
+ if (_flightTaskManager.SelectedTaskIndex > 0)
+ {
+ //modelGroup.Children.Clear();
+ if (waypointGroup == null) waypointGroup = new Model3DGroup();
+ waypointGroup.Children.Clear();
+
+
+ var meshBuilderwaypoint = new MeshBuilder(false, false);
+ meshBuilderwaypoint.AddSphere(new Point3D(0, 0, 0), 0.3);
+ var meshwaypoint = meshBuilderwaypoint.ToMesh(true);
+ var greenMaterial = MaterialHelper.CreateMaterial(Color.FromRgb(0,255,0));
+
+ foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.Tasks[_flightTaskManager.SelectedTaskIndex].SingleCopterInfos)
+ {
+
+ double x = GeographyUtils.CalcDistance(_flightTaskManager.OriginLng, 0, 0, info.TargetLng, 0, 0);
+ if (_flightTaskManager.OriginLng > info.TargetLng) x = -x;
+ double y = GeographyUtils.CalcDistance(0, _flightTaskManager.OriginLat, 0, 0, info.TargetLat, 0);
+ if (_flightTaskManager.OriginLat > info.TargetLat) y = -y;
+
+ waypointGroup.Children.Add(new GeometryModel3D
+ {
+ Geometry = meshwaypoint,
+ Transform = new TranslateTransform3D(x, y, info.TargetAlt),
+ Material = greenMaterial,
+ BackMaterial = greenMaterial
+ });
+ }
+ }
+ }
+
+ public Model3D Model { get; set; }
+ public Model3DGroup modelGroup { get; set; }
+
+ public Model3DGroup planeGroup { get; set; }
+ public Model3DGroup waypointGroup { get; set; }
+
+ }
+}
diff --git a/Plane.FormationCreator/Views/ConnectWindow.xaml b/Plane.FormationCreator/Views/ConnectWindow.xaml
index 1e892e4..151b849 100644
--- a/Plane.FormationCreator/Views/ConnectWindow.xaml
+++ b/Plane.FormationCreator/Views/ConnectWindow.xaml
@@ -10,7 +10,7 @@
Title="连接"
Width="429.175"
Height="570.371"
- Style="{StaticResource VSWindowStyleKey}"
+
WindowStartupLocation="CenterScreen"
FontFamily="Microsoft YaHei"
ResizeMode="NoResize">
@@ -67,6 +67,7 @@
+
@@ -143,5 +144,12 @@
+
+
+
+
diff --git a/Plane.FormationCreator/Views/CopterListView.xaml b/Plane.FormationCreator/Views/CopterListView.xaml
index e9672d4..ae32b26 100644
--- a/Plane.FormationCreator/Views/CopterListView.xaml
+++ b/Plane.FormationCreator/Views/CopterListView.xaml
@@ -20,6 +20,7 @@
+
{
_copterManager.RaiseSelectedCoptersChanged(e.AddedItems.Cast(), e.RemovedItems.Cast());
+ lvwDrones.ScrollIntoView(lvwDrones.SelectedItem);
};
}
@@ -65,5 +66,31 @@ namespace Plane.FormationCreator.Views
{
lvwDrones.SelectedItems.Clear();
}
+
+ private void _listBoxCopters_PreviewKeyDown(object sender, KeyEventArgs e)
+ {
+ if (!this.lvwDrones.HasItems)
+ {
+ return;
+ }
+
+ bool prev = e.Key == Key.Up;
+ bool next = e.Key == Key.Down;
+ if (prev | next)
+ {
+ int afterIndex;
+ if (prev)
+ {
+ afterIndex = lvwDrones.SelectedIndex - 1;
+ lvwDrones.SelectedIndex = afterIndex < 0 ? 0 : afterIndex;
+ }
+ else
+ {
+ afterIndex = lvwDrones.SelectedIndex + 1;
+ lvwDrones.SelectedIndex = afterIndex > lvwDrones.Items.Count - 1 ? lvwDrones.Items.Count - 1 : afterIndex;
+ }
+ e.Handled = true;
+ }
+ }
}
}
diff --git a/Plane.FormationCreator/Views/LogUserControl.xaml b/Plane.FormationCreator/Views/LogUserControl.xaml
new file mode 100644
index 0000000..37f4a18
--- /dev/null
+++ b/Plane.FormationCreator/Views/LogUserControl.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/Plane.FormationCreator/Views/LogUserControl.xaml.cs b/Plane.FormationCreator/Views/LogUserControl.xaml.cs
new file mode 100644
index 0000000..1d4d9a5
--- /dev/null
+++ b/Plane.FormationCreator/Views/LogUserControl.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Plane.FormationCreator.Views
+{
+ ///
+ /// LogUserControl.xaml 的交互逻辑
+ ///
+ public partial class LogUserControl : UserControl
+ {
+ public LogUserControl()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Plane.FormationCreator/Views/LogWindow.xaml b/Plane.FormationCreator/Views/LogWindow.xaml
index a10cb6f..f43bbc7 100644
--- a/Plane.FormationCreator/Views/LogWindow.xaml
+++ b/Plane.FormationCreator/Views/LogWindow.xaml
@@ -6,12 +6,14 @@
xmlns:local="clr-namespace:Plane.FormationCreator.Views"
xmlns:c="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:ec="clr-namespace:Plane.Windows.Controls;assembly=Plane.Windows"
+ xmlns:src="clr-namespace:Plane.GoogleMap"
mc:Ignorable="d"
- Style="{StaticResource VSWindowStyleKey}"
+
Title="日志" Height="776.219" Width="1195.283">
-
+
+
+ ScrollViewer.VerticalScrollBarVisibility="Visible"
+ />
-
-
+
+
+
+
+
+
+
+
+
+
+
+ -->
();
+ gmap.MapProvider = GMapProviders.BingHybridMap; //google china 地图
+ gmap.MinZoom = 2; //最小缩放
+ gmap.MaxZoom = 30; //最大缩放
+ gmap.Zoom = 19; //当前缩放
+ gmap.ShowCenter = false; //不显示中心十字点
+ gmap.DragButton = MouseButton.Left; //左键拖拽地图
+ gmap.Position = new LatLng(40.07734857737275, 116.34323845862502).ToGCJ02();
_mapManager.MapView = this;
- _mapManager.SetCenterGetter(() => new LatLng { Lat = map.Center.Latitude, Lng = map.Center.Longitude });
+ _mapManager.SetCenterGetter(() => new LatLng { Lat = gmap.Position.ToWGS84().Lat, Lng = gmap.Position.ToWGS84().Lng });
_flightTaskManager.TaskAdded += FlightTaskManager_TaskAdded;
_flightTaskManager.OnOriginalSet += FlightTaskManager_SetOriginal;
@@ -100,7 +108,7 @@ namespace Plane.FormationCreator.Views
}
};
- map.MouseLeftButtonDown += (sender, e) =>
+ gmap.MouseLeftButtonDown += (sender, e) =>
{
if (IsMouseOnCopterOrWaypoint(e.OriginalSource))
{
@@ -113,7 +121,7 @@ namespace Plane.FormationCreator.Views
//_copterManager.Copters.ForEach(copter => AddOrMoveCopterForModifyingTask(copter));
//_copterManager.Copters.CollectionChanged += CoptersForModifyingTask_CollectionChanged;
- map.MouseDoubleClick += async (sender, e) =>
+ gmap.MouseDoubleClick += async (sender, e) =>
{
e.Handled = true;
@@ -129,42 +137,48 @@ namespace Plane.FormationCreator.Views
if (!copters.Any()) return;
- var pos = map.ViewportPointToLocation(e.GetPosition(map));
+ Point clickPoint = e.GetPosition(gmap);
+ var pos = gmap.FromLocalToLatLng((int)clickPoint.X, (int)clickPoint.Y);
var centerLat = copters.Average(c => c.Latitude);
var centerLng = copters.Average(c => c.Longitude);
- var latDelta = pos.Latitude - centerLat;
- var lngDelta = pos.Longitude - centerLng;
+ var latDelta = pos.Lat - centerLat;
+ var lngDelta = pos.Lng - centerLng;
await Task.WhenAll(copters.Select(copter => copter.FlyToAsync(copter.Latitude + latDelta, copter.Longitude + lngDelta, copter.Altitude)));
};
var center = _appConfig.Center;
- map.Center = new Location(center.Lat, center.Lng);
- map.ZoomLevel = _appConfig.ZoomLevel;
+ gmap.Position = new LatLng(center.Lat, center.Lng).ToGCJ02();
+ gmap.Zoom = _appConfig.ZoomLevel;
-
- map.ViewChangeOnFrame += (object sender, MapEventArgs e) =>
+
+ gmap.OnMapZoomChanged += () =>
{
- if ( map.Mode.GetType().ToString() == "Microsoft.Maps.MapControl.WPF.AerialMode")
- if (map.ZoomLevel >19)
- map.ZoomLevel = 19;
- if (original!= null && map.Children.Contains(original))
+// if ( gmap.Mode.GetType().ToString() == "Microsoft.Maps.MapControl.WPF.AerialMode")
+// if (map.ZoomLevel >19)
+// map.ZoomLevel = 19;
+ if (originalMarker != null && gmap.Markers.Contains(originalMarker))
{
- Location location = new Location(_flightTaskManager.OriginLat, _flightTaskManager.OriginLng);
- Point wpPos = map.LocationToViewportPoint(location);
- wpPos.X -= ORIGIN_RADIUS;
- wpPos.Y -= ORIGIN_RADIUS;
- MapLayer.SetPosition(original, map.ViewportPointToLocation(wpPos));
+ PointLatLng location = new LatLng(_flightTaskManager.OriginLat, _flightTaskManager.OriginLng).ToGCJ02();
+ GPoint wpPos = gmap.FromLatLngToLocal(location);
+ //Point wpPos = gmap.LocationToViewportPoint(location);
+ wpPos.X -= (long)ORIGIN_RADIUS;
+ wpPos.Y -= (long)ORIGIN_RADIUS;
+ originalMarker.Position = gmap.FromLocalToLatLng((int)wpPos.X, (int)wpPos.Y);
+ //MapLayer.SetPosition(original, gmap.ViewportPointToLocation(wpPos));
}
};
+ GMapMarker rectangleMarker = null;
Rectangle rectangle = new Rectangle();
bool drawRectangle = false;
Point startPosition = new Point();
Point leftTopPoint = new Point();
- map.MouseRightButtonDown += (sender, e) =>
+ gmap.MouseRightButtonDown += (sender, e) =>
{
+ startPosition = e.GetPosition(this);
+ rectangleMarker = new GMapMarker(gmap.FromLocalToLatLng((int)startPosition.X, (int)startPosition.Y));
rectangle = new Rectangle();
rectangle.Width = 0;
rectangle.Height = 0;
@@ -173,31 +187,33 @@ namespace Plane.FormationCreator.Views
rectangle.Fill = new SolidColorBrush(Color.FromArgb(80, 0, 120, 215));
rectangle.Tag = "Rectangle";
+ rectangleMarker.Shape = rectangle;
+ rectangleMarker.Tag = "Rectangle";
+ gmap.Markers.Add(rectangleMarker);
- map.Children.Add(rectangle);
- startPosition = e.GetPosition(this);
- MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(startPosition));
+ //MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(startPosition));
drawRectangle = true;
};
- map.MouseMove += (sender, e) =>
+ gmap.MouseMove += (sender, e) =>
{
if (drawRectangle)
{
- Point mousePosition = e.GetPosition(this);
+ Point mousePosition = e.GetPosition(gmap);
rectangle.Width = Math.Abs(mousePosition.X - startPosition.X);
rectangle.Height = Math.Abs(mousePosition.Y - startPosition.Y);
leftTopPoint = new Point(Math.Min(mousePosition.X, startPosition.X), Math.Min(mousePosition.Y, startPosition.Y));
- MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(leftTopPoint));
+ rectangleMarker.Position = gmap.FromLocalToLatLng((int)leftTopPoint.X, (int)leftTopPoint.Y);
+ //MapLayer.SetPosition(rectangle, map.ViewportPointToLocation(leftTopPoint));
}
};
int selectedCount = 0;
- map.MouseRightButtonUp += (sender, e) =>
+ gmap.MouseRightButtonUp += (sender, e) =>
{
selectedCount = 0;
- if (rectangle != null && map.Children.Contains(rectangle))
+ if (rectangleMarker != null && gmap.Markers.Contains(rectangleMarker))
{
- map.Children.Remove(rectangle);
+ gmap.Markers.Remove(rectangleMarker);
_copterManager.Select(null);
if (_flightTaskManager.SelectedTask != null && _flightTaskManager.SelectedTask.TaskType != FlightTaskType.TakeOff)
{
@@ -205,8 +221,8 @@ namespace Plane.FormationCreator.Views
foreach (FlightTaskSingleCopterInfo taskCopterInfo in _flightTaskManager.SelectedTask.SingleCopterInfos)
{
- Location seekLocation = new Location(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng);
- Point seekPoint = map.LocationToViewportPoint(seekLocation);
+ PointLatLng seekLocation = new LatLng(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng).ToGCJ02();
+ GPoint seekPoint = gmap.FromLatLngToLocal(seekLocation);
if ((seekPoint.X > leftTopPoint.X && seekPoint.X < leftTopPoint.X + rectangle.Width) &&
seekPoint.Y > leftTopPoint.Y && seekPoint.Y < leftTopPoint.Y + rectangle.Height)
{
@@ -218,22 +234,23 @@ namespace Plane.FormationCreator.Views
}
}
rectangle = null;
+ rectangleMarker = null;
drawRectangle = false;
};
- map.MouseLeave += (sender, e) =>
+ gmap.MouseLeave += (sender, e) =>
{
- if (map.Children.Contains(rectangle))
+ if (gmap.Markers.Contains(rectangleMarker))
{
- map.Children.Remove(rectangle);
+ gmap.Markers.Remove(rectangleMarker);
}
rectangle = null;
drawRectangle = false;
};
- map.MouseMove += new MouseEventHandler(OriginalMove);
- map.MouseLeftButtonUp += new MouseButtonEventHandler(OriginalMouseUp);
+ gmap.MouseMove += new MouseEventHandler(OriginalMove);
+ gmap.MouseLeftButtonUp += new MouseButtonEventHandler(OriginalMouseUp);
}
private CopterManager _copterManager = ServiceLocator.Current.GetInstance();
@@ -255,6 +272,7 @@ namespace Plane.FormationCreator.Views
public bool RemoveLoadingErrorMessage()
{
+ /*
var errorElement = map.Children.OfType().FirstOrDefault();
if (errorElement != null)
{
@@ -265,13 +283,16 @@ namespace Plane.FormationCreator.Views
{
return false;
}
+ */
+ return true;
}
public void GoHome()
{
- map.ZoomLevel = 19;
+ gmap.Zoom = 19;
//map.Center = new Location(40.0559055, 116.322233);
- map.Center = new Location(40.6801557090282, 114.670060030638);
+ //gmap.Position = new LatLng(40.6801557090282, 114.670060030638).ToGCJ02();
+ gmap.Position = new PointLatLng(40.1484605429763, 116.293929666281);
}
@@ -305,7 +326,7 @@ namespace Plane.FormationCreator.Views
{
var drawing = _copterDrawings.ContainsKey(copter) ?
_copterDrawings[copter] :
- (_copterDrawings[copter] = new CopterDrawing(copter, map));
+ (_copterDrawings[copter] = new CopterDrawing(copter, gmap));
drawing.AddOrMoveCopter();
}
@@ -321,6 +342,7 @@ namespace Plane.FormationCreator.Views
public void ClearCopters()
{
+ /*
for (int i = map.Children.Count - 1; i >= 0; i--)
{
if (!(map.Children[i] is MapTileLayer))
@@ -332,6 +354,9 @@ namespace Plane.FormationCreator.Views
{
item.Value.RemoveMap_ViewChanged();
}
+ */
+
+ gmap.Markers.Clear();
_copterDrawings.Clear();
}
@@ -339,7 +364,7 @@ namespace Plane.FormationCreator.Views
{
var elem = originalSource as FrameworkElement;
string tag;
- while (elem != map && elem != null)
+ while (elem != gmap && elem != null)
{
tag = elem.Tag?.ToString();
if (tag == COPTER_TAG || tag == WAYPOINT_TAG || tag == ORIGINALPOINT_TAG)
@@ -356,28 +381,29 @@ namespace Plane.FormationCreator.Views
foreach (var info in e.AddedTask.SingleCopterInfos)
{
var drawingInfo = _copterDrawings[info.Copter];
- var location = new Location(info.TargetLat, info.TargetLng, info.TargetAlt);
+ var location = new Microsoft.Maps.MapControl.WPF.Location(info.TargetLat, info.TargetLng, info.TargetAlt);
drawingInfo.AddWaypoint(location, e.AddedTask.TaskType);
}
}
+ GMapMarker originalMarker = null;
Microsoft.Expression.Shapes.RegularPolygon original = null;
const double ORIGIN_RADIUS = 12;
private void FlightTaskManager_SetOriginal(object sender, FlightTaskAddedOriginalEventArgs e)
{
if (_copterManager.Copters.Count == 0) return;
- if (map.Children.Contains(original))
- map.Children.Remove(original);
- Location location = new Location(_copterManager.Copters[0].Latitude, _copterManager.Copters[0].Longitude);
- Point point = map.LocationToViewportPoint(location);
- point.X -= ORIGIN_RADIUS;
- point.Y -= ORIGIN_RADIUS;
- Location mapLocation = map.ViewportPointToLocation(point);
+ if (gmap.Markers.Contains(originalMarker))
+ gmap.Markers.Remove(originalMarker);
+ PointLatLng location = new LatLng(_copterManager.Copters[0].Latitude, _copterManager.Copters[0].Longitude).ToGCJ02();
+ GPoint point = gmap.FromLatLngToLocal(location);
+ point.X -= (long)ORIGIN_RADIUS;
+ point.Y -= (long)ORIGIN_RADIUS;
+ PointLatLng mapLocation = gmap.FromLocalToLatLng((int)point.X , (int)point.Y);
original = new Microsoft.Expression.Shapes.RegularPolygon
{
Tag = ORIGINALPOINT_TAG,
- Fill = new SolidColorBrush(Color.FromArgb(200,237, 155, 3)),
+ Fill = new SolidColorBrush(Color.FromArgb(200, 237, 155, 3)),
Stroke = new SolidColorBrush(Color.FromArgb(200, 238, 80, 238)),
StrokeThickness = 1,
Width = ORIGIN_RADIUS * 2,
@@ -385,16 +411,17 @@ namespace Plane.FormationCreator.Views
InnerRadius = 0.5,
PointCount = 5,
};
+ originalMarker = new GMapMarker(mapLocation);
+ originalMarker.ZIndex = 200;
+ originalMarker.Shape = original;
-
-
- map.Children.Add(original);
- MapLayer.SetPosition(original, mapLocation);
- MapLayer.SetZIndex(original, 200);
+ gmap.Markers.Add(originalMarker);
+ //MapLayer.SetPosition(original, mapLocation);
+ //MapLayer.SetZIndex(original, 200);
original.ToolTip = location.ToString();
originaDrag = false;
- _flightTaskManager.OriginLat = location.Latitude;
- _flightTaskManager.OriginLng = location.Longitude;
+ _flightTaskManager.OriginLat = location.Lat;
+ _flightTaskManager.OriginLng = location.Lng;
original.MouseLeftButtonDown += new MouseButtonEventHandler(OriginalMouseDown);
}
@@ -408,8 +435,8 @@ namespace Plane.FormationCreator.Views
{
originaDrag = true;
-
- var originPoint = e.GetPosition(map);
+ gmap.CanDragMap = false;
+ var originPoint = e.GetPosition(gmap);
originX = originPoint.X;
originY = originPoint.Y;
@@ -422,9 +449,10 @@ namespace Plane.FormationCreator.Views
{
if (originaDrag)
{
- Point eventPos = e.GetPosition(map);
+ Point eventPos = e.GetPosition(gmap);
var leftTopPos = new Point(eventPos.X - wpOffsetX, eventPos.Y - wpOffsetY);
- MapLayer.SetPosition(original, map.ViewportPointToLocation(leftTopPos));
+ originalMarker.Position = gmap.FromLocalToLatLng((int)leftTopPos.X, (int)leftTopPos.Y);
+ //MapLayer.SetPosition(original, map.ViewportPointToLocation(leftTopPos));
}
}
@@ -433,23 +461,22 @@ namespace Plane.FormationCreator.Views
{
if (originaDrag)
{
-
-
-
- Point eventPos = e.GetPosition(map);
+ Point eventPos = e.GetPosition(gmap);
var centrePos = new Point(eventPos.X - wpOffsetX + ORIGIN_RADIUS, eventPos.Y - wpOffsetY + ORIGIN_RADIUS);
- Location location = map.ViewportPointToLocation(centrePos);
- _flightTaskManager.OriginLat = location.Latitude;
- _flightTaskManager.OriginLng = location.Longitude;
+ PointLatLng location = gmap.FromLocalToLatLng((int)centrePos.X, (int)centrePos.Y);
+ _flightTaskManager.OriginLat = location.Lat;
+ _flightTaskManager.OriginLng = location.Lng;
original.ToolTip = location.ToString();
- Clipboard.SetDataObject(string.Format("{0},{1}", location.Latitude, location.Longitude), true);
+ //Clipboard.SetDataObject(string.Format("{0},{1}", location.Lat, location.Lng), true);
originaDrag = false;
+ gmap.CanDragMap = true;
}
}
private void MapSelectionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
+ /*
switch ((e.AddedItems[0] as FrameworkElement).Tag.ToString())
{
case "卫星地图":
@@ -472,6 +499,7 @@ namespace Plane.FormationCreator.Views
}
break;
}
+ */
}
private void showallpoint_Checked(object sender, RoutedEventArgs e)
@@ -488,11 +516,7 @@ namespace Plane.FormationCreator.Views
_flightTaskManager.RightSelect(taskitme);
// TaskbarControl.setRightSelect(taskitme, ischecked);
}
-
}
-
-
-
}
@@ -521,6 +545,7 @@ namespace Plane.FormationCreator.Views
private void RemoveTileLayers()
{
+ /*
for (int i = map.Children.Count - 1; i >= 0; i--)
{
if (map.Children[i] is MapTileLayer)
@@ -528,12 +553,45 @@ namespace Plane.FormationCreator.Views
map.Children.RemoveAt(i);
}
}
+ */
+ }
+
+ private void Map_Opacity(object sender, RoutedEventArgs e)
+ {
+ if (gmap.Opacity == 1)
+ {
+ gmap.Opacity = 0.5;
+ }
+ else
+ {
+ gmap.Opacity = 1;
+ }
+ }
+
+ private void Load_Background(object sender, RoutedEventArgs e)
+ {
+ var dialog = new OpenFileDialog
+ {
+ Filter = "图片 |*.jpg;*.bmp;*.png"
+ };
+ if (dialog.ShowDialog() == true)
+ {
+ ImageBrush ib = new ImageBrush();
+ ib.AlignmentX = AlignmentX.Left;
+ ib.AlignmentY = AlignmentY.Top;
+ ib.Stretch = Stretch.None;
+ ib.ImageSource = new BitmapImage(new Uri(dialog.FileName, UriKind.RelativeOrAbsolute));
+ grid_bg.Background = ib;
+ gmap.Opacity = 0.5;
+ }
+
+
}
}
static class LocationExtensions
{
- public static double CalcDistance(this Location loc1, Location loc2)
+ public static double CalcDistance(this Microsoft.Maps.MapControl.WPF.Location loc1, Microsoft.Maps.MapControl.WPF.Location loc2)
{
if (loc1 == null)
{
diff --git a/Plane.FormationCreator/Views/MapView_CopterDrawing.cs b/Plane.FormationCreator/Views/MapView_CopterDrawing.cs
index dd3520f..ea34ee3 100644
--- a/Plane.FormationCreator/Views/MapView_CopterDrawing.cs
+++ b/Plane.FormationCreator/Views/MapView_CopterDrawing.cs
@@ -2,7 +2,6 @@
using Plane.Copters;
using Plane.FormationCreator.Formation;
using Plane.Logging;
-using Microsoft.Maps.MapControl.WPF;
using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
@@ -14,6 +13,11 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shapes;
+using GMap.NET.WindowsPresentation;
+using GMap.NET;
+using Plane.FormationCreator.Maps;
+using Microsoft.Maps.MapControl.WPF;
+using Plane.FormationCreator.ViewModels;
namespace Plane.FormationCreator.Views
{
@@ -21,7 +25,7 @@ namespace Plane.FormationCreator.Views
{
private class CopterDrawing
{
- public CopterDrawing(ICopter copter, Map map)
+ public CopterDrawing(ICopter copter, GoogleMap.GMap map)
{
this.Copter = copter;
_map = map;
@@ -38,13 +42,14 @@ namespace Plane.FormationCreator.Views
_flightTaskManager.TasksCleared += (sender, e) =>
{
- for (int i = this.Route.Locations.Count - 1; i >= 1; i--)
- {
- this.Route.Locations.RemoveAt(i);
- }
+ Route.Points.Clear();
+// for (int i = this.Route.Locations.Count - 1; i >= 1; i--)
+// {
+// this.Route.Locations.RemoveAt(i);
+// }
foreach (var wp in this.Waypoints)
{
- _map.Children.Remove(wp);
+ _map.Markers.Remove(wp);
}
this.Waypoints.Clear();
};
@@ -83,6 +88,7 @@ namespace Plane.FormationCreator.Views
public ICopter Copter { get; set; }
+ public GMapMarker DotMarker { get; set; }
public Grid DotContainer { get; set; }
public Polygon Dot { get; set; }
@@ -91,20 +97,22 @@ namespace Plane.FormationCreator.Views
public MapPolyline Track { get; set; }
public Location LastLocation { get; set; }
- public MapPolyline Route { get; set; }
- public List Waypoints { get; set; } = new List();
+ public GMapRoute Route { get; set; }
+ public List Waypoints { get; set; } = new List();
- Map _map;
+ GoogleMap.GMap _map;
Color _color;
Brush _brush;
ILogger _logger = ServiceLocator.Current.GetInstance();
CopterManager _copterManager = ServiceLocator.Current.GetInstance();
FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance();
+ View3DViewModel _view3DViewModel = ServiceLocator.Current.GetInstance();
private void Map_ViewChanged(object sender, MapEventArgs e)
{
+ /*
for (int index = 1; index < _flightTaskManager.Tasks.Count; index++)
{
var info = _flightTaskManager.Tasks[index].SingleCopterInfos.Find(i => i.Copter == this.Copter); ;
@@ -115,6 +123,7 @@ namespace Plane.FormationCreator.Views
wpPos.Y -= WAYPOINT_RADIUS;
MapLayer.SetPosition(wpContainer, _map.ViewportPointToLocation(wpPos));
}
+ */
}
@@ -122,7 +131,7 @@ namespace Plane.FormationCreator.Views
{
try
{
- var location = new Location(Copter.Latitude, Copter.Longitude, Copter.Altitude);
+ var location = new Microsoft.Maps.MapControl.WPF.Location(Copter.Latitude, Copter.Longitude, Copter.Altitude);
if (this.Dot != null )
{
@@ -132,9 +141,8 @@ namespace Plane.FormationCreator.Views
this.Dot.Fill = _brush;
}
-
-
- Point center = _map.LocationToViewportPoint(location);
+ PointLatLng gmapLatLng = new LatLng(location.Latitude, location.Longitude).ToGCJ02();
+ GPoint center = _map.FromLatLngToLocal(gmapLatLng);
bool locationUpdated = true;
SolidColorBrush blackBrush = new SolidColorBrush();
if (this.Dot == null)
@@ -166,8 +174,6 @@ namespace Plane.FormationCreator.Views
DotContainer.Children.Add(Dot);
//飞机里面的编号
-
-
CopterText = new TextBlock
{
Text = Copter.Name,
@@ -177,29 +183,29 @@ namespace Plane.FormationCreator.Views
VerticalAlignment = VerticalAlignment.Center
};
-
+ DotMarker = new GMapMarker(new PointLatLng(0, 0));
DotContainer.Children.Add(CopterText);
+ DotMarker.Shape = DotContainer;
+ _map.Markers.Add(DotMarker);
+ //MapLayer.SetZIndex(DotContainer, 100);
- _map.Children.Add(DotContainer);
- MapLayer.SetZIndex(DotContainer, 100);
+ this.Route = new GMapRoute(new List() { gmapLatLng, gmapLatLng });
+ Path path = new Path()
+ {
+ Stroke = _brush,
+ StrokeThickness = 2.0
+ };
- this.Route = new MapPolyline { Locations = new LocationCollection { location } };
- this.Route.Stroke = _brush;
- this.Route.StrokeThickness = 2.0;
+ this.Route.Shape = path;
//显示计划航线
-
- // _map.Children.Add(this.Route);
-
-
+ //_map.Markers.Add(Route);
this.LastLocation = location;
- RegisterEventHandlersForDraggingCopter(DotContainer);
+ RegisterEventHandlersForDraggingCopter(DotMarker);
}
else
{
-
-
if ((bool)_copterManager.CopterStatus[_copterManager.Copters.IndexOf(Copter)])
{
CopterText.Foreground = new SolidColorBrush(Colors.Red);
@@ -209,8 +215,6 @@ namespace Plane.FormationCreator.Views
CopterText.Foreground = new SolidColorBrush(Colors.White);
}
-
-
if (LastLocation != null && location.CalcDistance(LastLocation) < 0.1)
{
locationUpdated = false;
@@ -244,7 +248,8 @@ namespace Plane.FormationCreator.Views
if (locationUpdated)
{
Track.Locations.Add(location);
- MapLayer.SetPosition(Dot.Parent, location);
+ DotMarker.Position = new LatLng(location.Latitude, location.Longitude).ToGCJ02();
+ //MapLayer.SetPosition(Dot.Parent, location);
this.LastLocation = location;
}
}
@@ -257,30 +262,34 @@ namespace Plane.FormationCreator.Views
public void AddWaypoint(Location location, FlightTaskType type)
{
// Add waypoint.
-
-
+ LatLng gmapLatLng = new LatLng(location.Latitude, location.Longitude);
+ GMapMarker marker = new GMapMarker(gmapLatLng.ToGCJ02());
ShapesContainer shapesContainer = new ShapesContainer(_brush);
shapesContainer.Tag = WAYPOINT_TAG;
+ marker.Tag = WAYPOINT_TAG;
+ marker.Shape = shapesContainer;
- Waypoints.Add(shapesContainer);
- _map.Children.Add(shapesContainer);
- MapLayer.SetZIndex(shapesContainer, 100);
- var wpPos = _map.LocationToViewportPoint(location);
+ Waypoints.Add(marker);
+ _map.Markers.Add(marker);
+ marker.ZIndex = 100;
+ //MapLayer.SetZIndex(shapesContainer, 100);
+ //var wpPos = _map.LocationToViewportPoint(location);
//wpPos.X -= WAYPOINT_RADIUS;
//wpPos.Y -= WAYPOINT_RADIUS;
- MapLayer.SetPosition(shapesContainer, _map.ViewportPointToLocation(wpPos));
+ //MapLayer.SetPosition(shapesContainer, _map.ViewportPointToLocation(wpPos));
SetEffect(_copterManager.SelectedCopters.Contains(Copter));
// Register event handlers.
- RegisterEventHandlersForDraggingWaypoint(shapesContainer, taskIndex: Waypoints.Count);
+ RegisterEventHandlersForDraggingWaypoint(marker, taskIndex: Waypoints.Count);
// Register event handlers for task info.
- RegisterEventHandlersForTaskInfo(shapesContainer, taskIndex: Waypoints.Count);
+ RegisterEventHandlersForTaskInfo(marker, taskIndex: Waypoints.Count);
}
- private void RegisterEventHandlersForDraggingCopter(Grid copterElement)
+ private void RegisterEventHandlersForDraggingCopter(GMapMarker copterMarker)
{
+ Grid copterElement = copterMarker.Shape as Grid;
var dragMoving = false;
double offsetX = 0;
double offsetY = 0;
@@ -294,6 +303,7 @@ namespace Plane.FormationCreator.Views
offsetY = posInObject.Y;
dragMoving = true;
+ _map.CanDragMap = false;
}
};
_map.MouseMove += (sender, e) =>
@@ -303,9 +313,10 @@ namespace Plane.FormationCreator.Views
var pos = e.GetPosition(_map);
pos.X -= offsetX;
pos.Y -= offsetY;
- MapLayer.SetPosition(copterElement, _map.ViewportPointToLocation(pos));
+ copterMarker.Position = _map.FromLocalToLatLng((int)pos.X, (int)pos.Y);
+ //MapLayer.SetPosition(copterElement, _map.ViewportPointToLocation(pos));
- var center = _map.ViewportPointToLocation(pos);
+ //var center = _map.ViewportPointToLocation(pos);
// var routePoint = this.Route.Locations[0];
// routePoint.Latitude = center.Latitude;
@@ -313,21 +324,23 @@ namespace Plane.FormationCreator.Views
var fc = Copter as FakeCopter;
fc.SetProperties(
- latitude: center.Latitude,
- longitude: center.Longitude
+ latitude: copterMarker.Position.ToWGS84().Lat,
+ longitude: copterMarker.Position.ToWGS84().Lng
);
}
};
_map.MouseLeftButtonUp += (sender, e) =>
{
+ _map.CanDragMap = true;
if (dragMoving) dragMoving = false;
};
}
- private Dictionary selectWayOriginPoint = new Dictionary();
+ private Dictionary selectWayOriginPoint = new Dictionary();
private Dictionary
@@ -338,7 +340,7 @@
-
-
-
+
+
-
+
+
+
@@ -362,8 +366,8 @@
-
-
+