动态海拔图,全路线小地图,骑行记录上传增加截图

This commit is contained in:
lishuo 2021-04-07 17:22:45 +08:00
parent 65fc5b5c50
commit 725b510748
11 changed files with 4294 additions and 4675 deletions

File diff suppressed because it is too large Load Diff

View File

@ -21,11 +21,13 @@ namespace Assets.Scenes.Ride.Scripts
GameObject character;
[SerializeField]
Animator characterAnimator;
[SerializeField]
AbstractMap map;
//AbstractMap map;
#region
Vector3 nextPos;
Vector3 prePos;
Vector3 prePos = Vector3.zero;
float timer = 1.0f;//计时器
#endregion
@ -104,11 +106,11 @@ namespace Assets.Scenes.Ride.Scripts
void Update()
{
Excute();
}
private void FixedUpdate()
{
Excute();
}
#region
//初始化骑行数据
@ -118,7 +120,7 @@ namespace Assets.Scenes.Ride.Scripts
{
characterAnimator = GetComponentInChildren<Animator>();
mainController = transform.parent.GetComponent<CyclingController>();
map = FindObjectOfType<AbstractMap>();
//map = FindObjectOfType<AbstractMap>();
mapData = mainController.GetMapData();//获取路书信息
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
cyclingExcutor = mainController.cyclingController;
@ -126,6 +128,7 @@ namespace Assets.Scenes.Ride.Scripts
protected virtual void Excute()
{
//CamControl();
timer -= Time.deltaTime;
if (timer <= 0)//定时器 一秒执行一次
{
@ -147,7 +150,7 @@ namespace Assets.Scenes.Ride.Scripts
//数据处理
nextlatlong = Along(totalDistance);//下一个坐标
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
nextPos.y += 0.3f;//提高y轴让人物站在地图上面
nextPos.y += 0.5f;//提高y轴让人物站在地图上面
prePos = transform.localPosition;//当前点
thisRotation = transform.localRotation;
//动画控制
@ -181,11 +184,42 @@ namespace Assets.Scenes.Ride.Scripts
//当前用户调用来上传骑行记录
protected virtual void Upload()
{
}
#endregion
#region
protected string CaptureCamera(Camera camera, Rect rect)
{
// 创建一个RenderTexture对象
RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);
// 临时设置相关相机的targetTexture为rt, 并手动渲染相关相机
camera.targetTexture = rt;
camera.Render();
//ps: --- 如果这样加上第二个相机,可以实现只截图某几个指定的相机一起看到的图像。
//ps: camera2.targetTexture = rt;
//ps: camera2.Render();
//ps: -------------------------------------------------------------------
// 激活这个rt, 并从中中读取像素。
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(rect, 0, 0);// 注这个时候它是从RenderTexture.active中读取像素
screenShot.Apply();
// 重置相关参数以使用camera继续在屏幕上显示
camera.targetTexture = null;
//ps: camera2.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
GameObject.Destroy(rt);
// 最后将这些纹理数据,成一个图片文件
byte[] bytes = screenShot.EncodeToJPG();
string filename = Application.dataPath + "/"+Guid.NewGuid().ToString() +".jpg";
System.IO.File.WriteAllBytes(filename, bytes);
//Debug.Log(string.Format("截屏了一张照片: {0}", filename));
return filename;
}
public int CurrentIndex;
//当前距离所在的海拔/坡度/距离 下一个点的坡度以及剩余距离
void ComputeNextSlope()
@ -244,7 +278,15 @@ namespace Assets.Scenes.Ride.Scripts
yield return null;
}
}
Vector3 deltaPos = Vector3.zero;
Vector3 previousPos = Vector3.zero;
void CamControl()
{
deltaPos = transform.position - previousPos;
deltaPos.y = 0;
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, Camera.main.transform.position + deltaPos, Time.time);
previousPos = transform.position;
}
//人物移动控制
IEnumerator MoveTo()
{
@ -255,8 +297,13 @@ namespace Assets.Scenes.Ride.Scripts
{
t += Time.deltaTime;
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
Vector3 nextPosition = new Vector3((float)Math.Round(v.x, 2), (float)Math.Round(v.y, 2), (float)Math.Round(v.z, 2));
if (!nextPosition.Equals(transform.localPosition))
{
transform.localPosition = nextPosition;
//Camera.main.transform.localPosition = nextPosition;
}
transform.localPosition = new Vector3((float)Math.Round(v.x,4), (float)Math.Round(v.y, 4), (float)Math.Round(v.z, 4));
//控制海拔图的位置
yield return null;
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,149 @@
using Mapbox.Unity.Map;
using Mapbox.Unity.MeshGeneration.Data;
using Mapbox.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scenes.Ride.Scripts
{
public class InitMiniMapProvider : MonoBehaviour
{
[SerializeField]
AbstractMap _map;
[SerializeField]
Camera _minicamera;
[SerializeField]
GameObject _player;
CyclingController cyclingCotroller;
PlayerController playerController;
GameObject _mipMapRoute;
void Start()
{
cyclingCotroller = FindObjectOfType<CyclingController>();
playerController = FindObjectOfType<PlayerController>();
if (cyclingCotroller != null)
{
var mapdata = cyclingCotroller.GetMapData();
//初始化map
var point = cyclingCotroller.GetCenterCoordinate();
if (_map != null)
{
_map.OnInitialized += _map_OnInitialized;
_map.OnUpdated += _map_OnUpdated;
_map.Initialize(new Vector2d(mapdata.Center[0], mapdata.Center[1]), 12);
var bbox = mapdata.Bbox;
var targetbounds = new Vector2dBounds(new Vector2d(bbox[0], bbox[1]), new Vector2d(bbox[2], bbox[3]));
var screenBounds = GetScreenBounds();
SetZoomToFitBounds(targetbounds, screenBounds);
}
}
}
private void Update()
{
_player.transform.localPosition = _map.GeoToWorldPosition(playerController.Nextlatlong);
}
private bool init = false;
private void _map_OnInitialized()
{
init = true;
}
#region Camera
/// <summary>
/// https://github.com/mapbox/mapbox-unity-sdk/issues/1580
/// </summary>
/// <param name="targetBounds">路线的边界</param>
/// <param name="screenBounds">小地图边界</param>
private void SetZoomToFitBounds(Vector2dBounds targetBounds, Vector2dBounds screenBounds)
{
var targetLonDelta = targetBounds.East - targetBounds.West;
var targetLatDelta = targetBounds.North - targetBounds.South;
var screenLonDelta = screenBounds.East - screenBounds.West;
var screenLatDelta = screenBounds.North - screenBounds.South;
var zoomLatMultiplier = screenLatDelta / targetLatDelta;
var zoomLonMultiplier = screenLonDelta / targetLonDelta;
var latZoom = Math.Log(zoomLatMultiplier, 2);
var lonZoom = Math.Log(zoomLonMultiplier, 2);
var zoom = (float)(_map.Zoom + Math.Min(latZoom, lonZoom));
_map.SetZoom((float)Math.Floor(zoom));
_map.UpdateMap();
}
private Vector2dBounds GetScreenBounds()
{
var screenWidth = UnityEngine.Screen.width;
var screenHeight = UnityEngine.Screen.height;
var sw_world = _minicamera.ViewportToWorldPoint(new Vector3(0, 0, 180));
var sw = _map.WorldToGeoPosition(sw_world);
var ne_world = _minicamera.ViewportToWorldPoint(new Vector3(0.6f, 0.6f, 180));
var ne = _map.WorldToGeoPosition(ne_world);
return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y));
}
#endregion
#region 线
private void _map_OnUpdated()
{
CreateMiniRoute();
}
void CreateMiniRoute()
{
var meshData = new MeshData();
var dat = new List<Vector3>();
var mapData = cyclingCotroller.GetMapData();
if (mapData != null)
{
var count = mapData.List.Count;
var interval = Math.Max(Math.Ceiling(count / 500D),1f);
for (int i = 0; i < mapData.List.Count; i++)
{
if(i% interval == 0)
{
var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
item.y += 1f;
dat.Add(item);
}
}
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
CreateLineRender(feat);//创建小地图路线
}
}
//创建小地图路线
void CreateLineRender(VectorFeatureUnity feat)
{
if (_mipMapRoute != null)
{
_mipMapRoute.Destroy();
}
_mipMapRoute = new GameObject("MiniMapRoute");
_mipMapRoute.transform.parent = transform;
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
lineRender.material = new Material(Shader.Find("Sprites/Default"));
var dat = feat.Points[0];
lineRender.endColor = Color.blue;
lineRender.startColor = Color.blue;
//设置宽度
lineRender.startWidth = 0.6f;
lineRender.endWidth = 0.6f;
lineRender.positionCount = dat.Count;
lineRender.SetPositions(feat.Points[0].ToArray());
lineRender.numCornerVertices = 90;
_mipMapRoute.layer = 9;
}
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e94e95c463c5914d99fb16ff1047af4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -71,7 +71,6 @@ namespace Assets.Scenes.Ride.Scripts
void Update()
{
var t = _curve.Evaluate(Time.time);
Debug.Log(t);
_text.color = Color.Lerp(Color.clear, Color.white, t);
}
}

View File

@ -109,7 +109,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
/// </summary>
/// <param name="base64Image"></param>
/// <returns></returns>
public JsonResult<AddMapRecordResultModel> SaveData(CyclingModel cyclingModel, SelectParamModel selectParam, string base64Image = "")
public JsonResult<AddMapRecordResultModel> SaveData(CyclingModel cyclingModel, SelectParamModel selectParam, string imageName = "")
{
if (RiderDatas.Count <= 0)
{
@ -196,19 +196,10 @@ namespace Assets.Scenes.Ride.Scripts.Model
stream.Close();
files.Add(fname);
}
#region TODO
if (!string.IsNullOrEmpty(base64Image))
#region
if (!string.IsNullOrEmpty(imageName))
{
//var imageName = path + "/" + Guid.NewGuid().ToString() + ".png";
//base64Image = base64Image.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""); ;
//byte[] image = Convert.FromBase64String(base64Image);
//using (MemoryStream ms = new MemoryStream(image))
//using (Image img = Image.FromStream(ms))
//{
// img.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
// //img.Dispose();
//}
//files.Add(imageName);
files.Add(imageName);
}
#endregion
var result = service.Add(interruptRecord, files);

View File

@ -35,9 +35,7 @@ namespace Assets.Scenes.Ride.Scripts
distance = mainController.UpdateDistance(speed);
totalDistance += distance;
//记录骑行数据
var recordText = string.Format($"{ ticks },{ power.ToString(CultureInfo.InvariantCulture) },{ speed.ToString(CultureInfo.InvariantCulture) },{ Math.Round(totalDistance, 6).ToString(CultureInfo.InvariantCulture) },{ cadance.ToString(CultureInfo.InvariantCulture) },{ heartRate.ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.x, 6).ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.y, 6).ToString(CultureInfo.InvariantCulture) }");
Debug.Log(recordText);
#if !UNITY_EDITOR
#if UNITY_EDITOR
var recorderData = cyclingExcutor.recorderData;
recorderData.RiderDatas.Add(new TargetData
{
@ -51,14 +49,15 @@ namespace Assets.Scenes.Ride.Scripts
_Lon = nextlatlong.y
});
#endif
}
//上传数据
protected override void Upload()
}
//上传数据
protected override void Upload()
{
#if !UNITY_EDITOR
#if UNITY_EDITOR
string imageFileName = base.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f));
cyclingExcutor.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
cyclingExcutor.recorderData.EndDistance = totalDistance;
cyclingExcutor.recorderData.SaveData(cyclingExcutor.Mode,null,string.Empty);
cyclingExcutor.recorderData.SaveData(cyclingExcutor.Mode,null, imageFileName);
#endif
}
#endregion

View File

@ -7,6 +7,7 @@ using System.Collections;
using Mapbox.Unity.MeshGeneration.Modifiers;
using Mapbox.Unity.MeshGeneration.Data;
using Mapbox.Unity.Utilities;
using System;
namespace Assets.Scenes.Ride.Scripts
{
@ -18,7 +19,6 @@ namespace Assets.Scenes.Ride.Scripts
MeshModifier SnapModifier;
[SerializeField]
Material _material;
[SerializeField]
[Range(1, 10)]
private float UpdateFrequency = 2;
@ -36,14 +36,14 @@ namespace Assets.Scenes.Ride.Scripts
{
_map = FindObjectOfType<AbstractMap>();
}
// _map.OnInitialized += _map_OnInitialized; ;
// _map.OnInitialized += _map_OnInitialized; ;
//_map.OnUpdated += _map_OnUpdated; ;
//_map.OnTileFinished += _map_OnTileFinished; ;
}
private void _map_OnUpdated()
private void _map_OnUpdated()
{
Debug.Log("_map_OnUpdated");
}
@ -59,7 +59,6 @@ namespace Assets.Scenes.Ride.Scripts
if (!initComplete)
{
Debug.Log(47);
CreateRoute(obj);
initComplete = true;
}
@ -71,6 +70,7 @@ namespace Assets.Scenes.Ride.Scripts
{
cyclingCotroller = transform.parent.GetComponent<CyclingController>();
playerController = FindObjectOfType<PlayerController>();
_map.OnTileFinished += _map_OnTileFinished;
StartCoroutine(QueryTimer());
//CreateRoute();
}
@ -85,9 +85,8 @@ namespace Assets.Scenes.Ride.Scripts
{
while (true)
{
Debug.Log(88);
yield return new WaitForSeconds(UpdateFrequency);
CreateRoute(null);
yield return new WaitForSeconds(UpdateFrequency);
}
}
@ -100,15 +99,18 @@ namespace Assets.Scenes.Ride.Scripts
var mapData = cyclingCotroller.GetMapData();
if (mapData != null)
{
foreach (var mapDataItem in mapData.List)
//foreach (var mapDataItem in mapData.List)
for (int i = 0; i < mapData.List.Count; i++)
{
var point = mapDataItem.Point;
var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
var distance = TurfCS.Turf.Distance(TurfCS.Turf.Point(new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y }), TurfCS.Turf.Point(new double[] { point[0], point[1]}));
if (distance<10)
item.y += 0.3f;
if (!posInScreen(item) && i > playerController.CurrentIndex)
{
break;
}
else if (posInScreen(item))
{
item.y += 0.3f;
dat.Add(item);
}
}
@ -117,7 +119,7 @@ namespace Assets.Scenes.Ride.Scripts
//处理海拔高度的问题
//SnapModifier.Run(feat, meshData, tile);
CreatMapRoute(feat);//创建路线
CreateMiniMapRoute(feat);//创建小地图路线
//CreateMiniMapRoute(feat);//创建小地图路线
}
}
}
@ -127,7 +129,7 @@ namespace Assets.Scenes.Ride.Scripts
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
Vector3 dir = (position - camreatra.position).normalized;
float dot = Vector3.Dot(camreatra.forward, dir);
if (dot > 0 && viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
if (dot > -1 && viewPos.x > -1 && viewPos.x < 2 && viewPos.y > -1 && viewPos.y < 2)
{
return true;
}
@ -155,9 +157,10 @@ namespace Assets.Scenes.Ride.Scripts
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
//处理海拔高度的问题
SnapModifier.Run(feat, meshData, tile);
CreatMapRoute(feat);//创建路线
CreateMiniMapRoute(feat);//创建小地图路线
//SnapModifier.Run(feat, meshData, tile);
//CreatMapRoute(feat);//创建路线
//CreateMiniMapRoute(feat);//创建小地图路线
}
}
}
@ -176,7 +179,7 @@ namespace Assets.Scenes.Ride.Scripts
lineRender.endColor = c;
lineRender.startColor = c;
//设置宽度
lineRender.SetWidth(0.5f, 0.5f);
lineRender.SetWidth(0.2f, 0.2f);
lineRender.SetVertexCount(dat.Count);
lineRender.SetPositions(feat.Points[0].ToArray());
//lineRender.numCapVertices = 90;
@ -190,33 +193,5 @@ namespace Assets.Scenes.Ride.Scripts
lineRender.numCornerVertices = 90;
}
void CreateMiniMapRoute(VectorFeatureUnity feat)
{
if (_mipMapRoute != null)
{
_mipMapRoute.Destroy();
}
_mipMapRoute = new GameObject("MiniMapRoute");
_mipMapRoute.transform.parent = transform;
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
lineRender.material = new Material(Shader.Find("Sprites/Default"));
var dat = feat.Points[0];
lineRender.endColor = Color.white;
lineRender.startColor = Color.white;
//设置宽度
lineRender.SetWidth(3f, 3f);
lineRender.SetVertexCount(dat.Count);
lineRender.SetPositions(feat.Points[0].ToArray());
//lineRender.numCapVertices = 90;
float alpha = 1.0f;
//Gradient gradient = new Gradient();
//gradient.SetKeys(
// new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
// new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
//);
//lineRender.colorGradient = gradient;
lineRender.numCornerVertices = 90;
_mipMapRoute.layer = 9;
}
}
}

View File

@ -9,6 +9,8 @@ using DG.Tweening;
using System;
using Assets.Scenes.Ride.Scripts.Model;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using Assets.Cyp.Common;
namespace Assets.Scenes.Ride.Scripts
{
@ -57,7 +59,7 @@ namespace Assets.Scenes.Ride.Scripts
[SerializeField]
Text mapName;//路书名称
[SerializeField] LineChart elevationChart;//海拔图
[SerializeField] Image img;//当前用户头像
[SerializeField] RawImage img;//当前用户头像
[SerializeField]
Button StartOrPauseButton;//暂停按钮
[SerializeField]
@ -66,6 +68,9 @@ namespace Assets.Scenes.Ride.Scripts
Button DeviceButton;//设备按钮
[SerializeField]
Button ExitButton;//退出按钮
[SerializeField]
GameObject target;//开始按钮
#endregion
#region
@ -86,8 +91,6 @@ namespace Assets.Scenes.Ride.Scripts
SettingButton.onClick.AddListener(ShowSettingPanel);
DeviceButton.onClick.AddListener(ShowDevicePanel);
ExitButton.onClick.AddListener(StopRide);
}
void Start()
{
@ -97,6 +100,7 @@ namespace Assets.Scenes.Ride.Scripts
mapName.text = route.RouteInstance.Name;
totalDistance.text = "/" + Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";
RenderChart();
startIndex = playerController.CurrentIndex;
}
// Update is called once per frame
float tt = 1f;
@ -139,15 +143,20 @@ namespace Assets.Scenes.Ride.Scripts
currentSlopeText.text = Math.Round(playerController.CurrentSlope, 1).ToString() + "%";
currentSlopeDistanceText.text = Math.Round(playerController.CurrentSlopeDistance, 0).ToString() + "M";
//移动海拔图头像 TODO移动所有人的头像
MoveChartMarkPoint();
UpdateRealTimeChart();
//MoveChartMarkPoint();
}
}
//根据不同的骑行模式渲染不同的UI界面
void InitUI(CyclingModel cyclingModel)
private void LateUpdate()
{
if (target != null)
{
target.transform.position = playerController.transform.position; //new Vector3((float)Math.Round(player.transform.position.x,1), 0, (float)Math.Round(player.transform.position.z,1));
target.transform.rotation = new Quaternion(playerController.transform.rotation.x, playerController.transform.rotation.y + 180, playerController.transform.rotation.z, playerController.transform.rotation.w);
}
}
private void StartRide()
{
//加个5秒钟倒计时
@ -188,25 +197,79 @@ namespace Assets.Scenes.Ride.Scripts
isSimple *= -1;
}
private int maxCacheDataNumber = 100;//海拔图最大点数
private int totalCount;//路线实际点数
private int startIndex;//选中玩家起始索引
private int interval = 50;//选中玩家移动索引个数
private float[] elevationList;
//初始化海拔图
void RenderChart()
{
elevationChart.ClearData();
var elevationArr = mainController.GetLineChartData();
foreach (var elevation in elevationArr)
elevationList = mainController.GetLineChartData();
totalCount = elevationList.Length;
maxCacheDataNumber = Math.Min(totalCount, maxCacheDataNumber);
elevationChart.SetMaxCache(maxCacheDataNumber);
//for (int i = 0; i < maxCacheDataNumber; i++)
//{
// elevationChart.AddData(0, elevationList[i]);
//}
//elevationChart.RefreshChart();
var endIndex = playerController.CurrentIndex;
var s = endIndex / maxCacheDataNumber;
var v = endIndex % maxCacheDataNumber;
maxCacheDataNumber = Math.Min(totalCount-s* maxCacheDataNumber, maxCacheDataNumber);
for (int i = 0; i < maxCacheDataNumber; i++)
{
elevationChart.AddData(0, elevation);
initCount++;
if (initCount > maxCacheDataNumber) break;
AddOneData(s * maxCacheDataNumber + v + i);
}
elevationChart.RefreshChart();
Utils.DisplayImage(StartCoroutine, img, App.CurrentUser.WxHeadImg);
}
//长路线动态更新chart
private int initCount;
private float updateTime;
private int lastIndex;
private int chartAddNum;
void UpdateRealTimeChart()
{
var endIndex = playerController.CurrentIndex;
updateTime += Time.deltaTime;
if (updateTime >= 1)
{
int delta = endIndex - lastIndex;
if (delta >0 && initCount < totalCount)
{
lastIndex = endIndex;
AddOneData(initCount);
initCount++;
updateTime = 0;
chartAddNum++;
}
var v = (endIndex - chartAddNum) % maxCacheDataNumber;
MoveChartMarkPoint(v);
}
}
void AddOneData(int index)
{
elevationChart.AddData(0, elevationList[index]);
//elevationChart.AddXAxisData(index.ToString(), index);
}
void MoveChartMarkPoint()
void MoveChartMarkPoint(int index)
{
var dataPoints = elevationChart.series.list[0].dataPoints.OrderBy(c=>c.x).ToList();
if (dataPoints.Count > 0)
{
var pinLoction = dataPoints[playerController.CurrentIndex];
pinLoction.y += 10;
var pinLoction = dataPoints[index];
pinLoction.y = img.transform.localPosition.y;
img.transform.localPosition = pinLoction;
}
}

View File

@ -1,4 +1,5 @@
using System;
using GeoJSON.Net.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -64,6 +65,8 @@ namespace Assets.Scripts.Apis.Models
if (_List == null) return;
this.CalcDistance();
this.CalcGrade();
this.CalcBbox();
this.CalcCenter();
}
}
@ -117,7 +120,22 @@ namespace Assets.Scripts.Apis.Models
}
}
private void CalcCenter()
{
var list = this.List.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p.Point[0], p.Point[1]));
LineString lineString = new LineString(list);
var ll = Turf.Centroid(lineString);
var p1 = ((Point)ll.Geometry).Coordinates;
Center = new double[] { ((GeographicPosition)p1).Latitude, ((GeographicPosition)p1).Longitude };
}
private void CalcBbox()
{
var list = this.List.Select(p => new GeoJSON.Net.Geometry.GeographicPosition(p.Point[0], p.Point[1]));
LineString lineString = new LineString(list);
Bbox = Turf.Bbox(lineString);
}
public Double[] Center { set; get; }
public List<Double> Bbox { set; get; }
public MapDataModel()
{
//List = new List<Item>();