forked from powerfun/udpservice
104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
|
|
using Newtonsoft.Json;
|
|||
|
|
using OnlineUserPool.Unility;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace OnlineUserPool.Model
|
|||
|
|
{
|
|||
|
|
public class MapDataModel
|
|||
|
|
{
|
|||
|
|
public string Type => "LineString";
|
|||
|
|
/// <summary>
|
|||
|
|
/// 总距离(km)
|
|||
|
|
/// </summary>
|
|||
|
|
public double TotalDistance { get; set; }
|
|||
|
|
|
|||
|
|
private List<Item> _List;
|
|||
|
|
public List<Item> List
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _List;
|
|||
|
|
}
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_List = value;
|
|||
|
|
if (_List == null) return;
|
|||
|
|
this.CalcDistance();
|
|||
|
|
this.CalcGrade();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public void CalcDistance()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < _List.Count - 1; i++)
|
|||
|
|
{
|
|||
|
|
var value = CommonHelper.GetDistances(_List[i].Point[1], _List[i].Point[0], _List[i + 1].Point[1], _List[i + 1].Point[0]);
|
|||
|
|
//var value = Turf.Distance(pt1, pt2, "kilometers") * 1000;
|
|||
|
|
_List[i].Distance = Math.Round(value, 2);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 计算坡度数据
|
|||
|
|
/// </summary>
|
|||
|
|
private void CalcGrade()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < this._List.Count - 1; i++)
|
|||
|
|
{
|
|||
|
|
var a = _List[i + 1].Elevation - _List[i].Elevation;
|
|||
|
|
if (a == 0)
|
|||
|
|
{
|
|||
|
|
//grade.Add(0);
|
|||
|
|
_List[i].Grade = 0;
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
//勾股定理
|
|||
|
|
var c = _List[i].Distance;//如果车停了下来,c为0
|
|||
|
|
if (c == 0 && i > 0)
|
|||
|
|
{
|
|||
|
|
_List[i].Grade = _List[i - 1].Grade;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
var b = Math.Sqrt(c * c - a * a);
|
|||
|
|
if (b == 0)//如果b等于,这就是垂直的墙壁
|
|||
|
|
{
|
|||
|
|
_List[i].Grade = _List[i - 1].Grade;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
_List[i].Grade = Math.Round(a / b * 100, 4);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public MapDataModel()
|
|||
|
|
{
|
|||
|
|
//_List = new List<Item>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class Item
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 坐标(lat,lon)
|
|||
|
|
/// </summary>
|
|||
|
|
public double[] Point { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 距离(单位米)
|
|||
|
|
/// </summary>
|
|||
|
|
[JsonIgnore]
|
|||
|
|
public double Distance { get; set; }
|
|||
|
|
/// <summary>
|
|||
|
|
/// 海拔m
|
|||
|
|
/// </summary>
|
|||
|
|
public double Elevation { get; set; }
|
|||
|
|
|
|||
|
|
[JsonIgnore]
|
|||
|
|
public double Grade { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|