graph chart引入&骑行结果弹窗
This commit is contained in:
1 parent
40d118cea3
commit
96f3644b5b
2374 files changed
+485161
-2410
No files matched your search
@@ -1,9 +1,16 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -167,5 +174,178 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
return value.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode google style polyline coordinates.
|
||||
/// </summary>
|
||||
/// <param name="encodedPoints"></param>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<CoordinateEntity> Decode(string encodedPoints)
|
||||
{
|
||||
if (string.IsNullOrEmpty(encodedPoints))
|
||||
throw new ArgumentNullException("encodedPoints");
|
||||
|
||||
char[] polylineChars = encodedPoints.ToCharArray();
|
||||
int index = 0;
|
||||
|
||||
int currentLat = 0;
|
||||
int currentLng = 0;
|
||||
int next5bits;
|
||||
int sum;
|
||||
int shifter;
|
||||
|
||||
while (index < polylineChars.Length)
|
||||
{
|
||||
// calculate next latitude
|
||||
sum = 0;
|
||||
shifter = 0;
|
||||
do
|
||||
{
|
||||
next5bits = (int)polylineChars[index++] - 63;
|
||||
sum |= (next5bits & 31) << shifter;
|
||||
shifter += 5;
|
||||
} while (next5bits >= 32 && index < polylineChars.Length);
|
||||
|
||||
if (index >= polylineChars.Length)
|
||||
break;
|
||||
|
||||
currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
|
||||
|
||||
//calculate next longitude
|
||||
sum = 0;
|
||||
shifter = 0;
|
||||
do
|
||||
{
|
||||
next5bits = (int)polylineChars[index++] - 63;
|
||||
sum |= (next5bits & 31) << shifter;
|
||||
shifter += 5;
|
||||
} while (next5bits >= 32 && index < polylineChars.Length);
|
||||
|
||||
if (index >= polylineChars.Length && next5bits >= 32)
|
||||
break;
|
||||
|
||||
currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
|
||||
|
||||
yield return new CoordinateEntity
|
||||
{
|
||||
Latitude = Convert.ToDouble(currentLat) / 1E5,
|
||||
Longitude = Convert.ToDouble(currentLng) / 1E5
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encode it
|
||||
/// </summary>
|
||||
/// <param name="points"></param>
|
||||
/// <returns></returns>
|
||||
private static string Encode(IEnumerable<CoordinateEntity> points)
|
||||
{
|
||||
var str = new StringBuilder();
|
||||
|
||||
var encodeDiff = (Action<int>)(diff =>
|
||||
{
|
||||
int shifted = diff << 1;
|
||||
if (diff < 0)
|
||||
shifted = ~shifted;
|
||||
|
||||
int rem = shifted;
|
||||
|
||||
while (rem >= 0x20)
|
||||
{
|
||||
str.Append((char)((0x20 | (rem & 0x1f)) + 63));
|
||||
|
||||
rem >>= 5;
|
||||
}
|
||||
|
||||
str.Append((char)(rem + 63));
|
||||
});
|
||||
|
||||
int lastLat = 0;
|
||||
int lastLng = 0;
|
||||
|
||||
foreach (var point in points)
|
||||
{
|
||||
int lat = (int)Math.Round(point.Latitude * 1E5);
|
||||
int lng = (int)Math.Round(point.Longitude * 1E5);
|
||||
|
||||
encodeDiff(lat - lastLat);
|
||||
encodeDiff(lng - lastLng);
|
||||
|
||||
lastLat = lat;
|
||||
lastLng = lng;
|
||||
}
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
public struct CoordinateEntity
|
||||
{
|
||||
public double Latitude;
|
||||
public double Longitude;
|
||||
public CoordinateEntity(double x, double y) { this.Latitude = x; this.Longitude = y; }
|
||||
}
|
||||
|
||||
public static async Task<byte[]> DownloadImgAsync(List<MapDataModel.Item> list)
|
||||
{
|
||||
var result = new List<CoordinateEntity>();
|
||||
var count = list.Count;
|
||||
int segement = (int)Math.Ceiling((double)(count / 1000D));
|
||||
|
||||
for (int i = 0; i <= count - 1; i++)
|
||||
{
|
||||
if (i % segement == 0)
|
||||
{
|
||||
result.Add(new CoordinateEntity
|
||||
{
|
||||
Latitude = Math.Round(list[i].Point[0], 6),
|
||||
Longitude = Math.Round(list[i].Point[1], 6),
|
||||
});
|
||||
}
|
||||
}
|
||||
return await DownloadImgAsync(result);
|
||||
}
|
||||
|
||||
public static async Task<byte[]> DownloadImgAsync(List<CoordinateEntity> list)
|
||||
{
|
||||
var polyline = Encode(list);
|
||||
var encodeline = UnityWebRequest.EscapeURL(polyline); //HttpUtility.UrlEncode(polyline);
|
||||
//获取封面图片
|
||||
var url = $"https://api.mapbox.com/styles/v1/mapbox/dark-v10/static/path-4+35ace1-1({encodeline})/auto/1280x1280?access_token={App.MapBoxAccessToken}";
|
||||
HttpClient c = new HttpClient();
|
||||
var response = await c.GetAsync(url);
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
byte[] content = await response.Content.ReadAsByteArrayAsync();
|
||||
return content;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetMapboxApiUrl(List<MapDataModel.Item> list)
|
||||
{
|
||||
var result = new List<CoordinateEntity>();
|
||||
var count = list.Count;
|
||||
int segement = (int)Math.Ceiling((double)(count / 1000D));
|
||||
|
||||
for (int i = 0; i <= count - 1; i++)
|
||||
{
|
||||
if (i % segement == 0)
|
||||
{
|
||||
result.Add(new CoordinateEntity
|
||||
{
|
||||
Latitude = Math.Round(list[i].Point[0], 6),
|
||||
Longitude = Math.Round(list[i].Point[1], 6),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var polyline = Encode(result);
|
||||
var encodeline = UnityWebRequest.EscapeURL(polyline); //HttpUtility.UrlEncode(polyline);
|
||||
//获取封面图片
|
||||
var url = $"https://api.mapbox.com/styles/v1/mapbox/dark-v10/static/path-4+35ace1-1({encodeline})/auto/1280x1280?access_token={App.MapBoxAccessToken}";
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user