2021-06-04 13:22:59 +08:00

151 lines
5.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Assets.Scenes.Ride.Scripts.Model;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Apis
{
public class MapApi :ApiBase
{
public string GetMapToken(string name)
{
return Get($"Map/GetMapToken?name={name}");
}
/// <summary>
/// 获取路线数据
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public MapDataModel GetData(int id)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<MapDataModel>(Get("Map/GetData?routeId="+id));
}
/// <summary>
/// 从服务端获取记录信息
/// </summary>
/// <returns></returns>
public List<MapRecordRanking> GetRecordFileFromServer(List<string> id)
{
return Post<JsonResult<List<MapRecordRanking>>>("Map/GetCyclingRecordsById", id).data;
}
/// <summary>
/// 通过Id获取路书
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public JsonResult<MapRoute> GetById(int id)
{
return Get<JsonResult<MapRoute>>($"Map/GetMapRouteById?id={id}");
}
/// <summary>
///
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="name">名称,地址,编号</param>
/// <param name="distance">距离格式0-10</param>
/// <param name="is3D"></param>
/// <param name="sort">hot, distance</param>
/// <param name="sortDire">asc</param>
/// <returns></returns>
public Task<JsonResult<List<MapRoute>>> GetList(int pageIndex, int pageSize, string name, string distance="", string hands="", bool is3D=false, string sort="", string sortDire = "", bool isFav = false)
{
var url = $"Map/GetRoute?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&distance={ distance }&hands={ hands }&is3D={ is3D }&sort={ sort }&sortDire={ sortDire }&isFav={isFav}";
return GetAsync<JsonResult<List<MapRoute>>>(url);
}
/// <summary>
/// 从服务端获取Key
/// </summary>
/// <returns></returns>
public Dictionary<string, string> GetServiceKeyFromServer()
{
return Get<JsonResult<Dictionary<string, string>>>($"Map/GetServiceKey").data;
}
/// <summary>
/// 获取在线用户的数据
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public JsonResult<List<OnlineUser>> GetOnlineUserInfo(IEnumerable<int> ids)
{
//var result = PostAsync<JsonResult<List<OnlineUser>>>("Map/GetUserInfoByIds", ids).ConfigureAwait(false).GetAwaiter().GetResult();
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonResult<List<OnlineUser>>>(Post("Map/GetUserInfoByIds", ids));
if (result.result)
{
return result;
}
return null;
}
public async Task<JsonResult<List<NearRouteModel>>> GetNearRouteAsync(float lat, float lng, float zoom, string bounds)
{
var res = await GetAsync<JsonResult<List<NearRouteModel>>>($"/Map/GetNearRoute?lat={ lat }&lng={ lng }&zoom={zoom}&bounds={ bounds }");
//var result = System.Text.Encoding.UTF8.GetString(res);
return res;
}
public async Task<string> GetDetailsAsync(int[] ids)
{
var res = await GetAsync("/Map/GetDetails?ids=" + string.Join(",", ids));
return Encoding.UTF8.GetString(res);
}
/// <summary>
/// 添加收藏
/// </summary>
/// <returns></returns>
public async Task<JsonResult<object>> AddFav(string routeId)
{
return await PostAsync<JsonResult<object>>("/MemberFavoriteMap/Add",new { routeId });
}
/// <summary>
/// 取消收藏
/// </summary>
/// <returns></returns>
public async Task<JsonResult<object>> CancelFav(string routeId)
{
return await PostAsync<JsonResult<object>>("/MemberFavoriteMap/Cancel", new { routeId });
}
public async Task<JsonResult<object>> DeleteRecord(string id)
{
return await PostAsync<JsonResult<object>>("/MapRecord/Delete", new { id });
}
public JsonResult<MapRouteRankingList> GetRouteRanking(int id,string type, int pageIndex,int pageSize,string name)
{
var url = $"Map/v1/GetRouteRanking?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&id={ id }&type={ type }&filterSelf={ false }";
return Get<JsonResult<MapRouteRankingList>>(url);
}
public JsonResult<MapRouteRankingList> GetShadowList(int id, string name, int pageIndex, int pageSize)
{
var url = $"Map/GetShadowList?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&id={ id }";
return Get<JsonResult<MapRouteRankingList>>(url);
}
public async Task<JsonResult<object>> GetEarthData(double lat, double lon)
{
//CultureInfo.InvariantCulture
var result = await GetAsync<JsonResult<object>>($"Map/GetEarthData?lat={ lat }&lon={ lon }");
return result;
}
}
}