This commit is contained in:
runette committed 2024-04-22 15:52:51 +01:00
commit e0afef912e
1285 files changed
+83219

No files matched your search

@@ -0,0 +1,244 @@
//-----------------------------------------------------------------------
// <copyright file="DirectionResource.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System;
using System.Collections.Generic;
using Mapbox.Utils;
using Platform;
/// <summary> A directions request. </summary>
public class DirectionResource : Resource
{
private string apiEndpoint = "directions/v5/";
// Required
private RoutingProfile profile;
// Optional
private Vector2d[] coordinates;
// Optional
private bool? alternatives;
// Optional
private BearingFilter[] bearings;
// Optional
private bool? continueStraight;
// Optional
private Overview overview;
// Optional
private double[] radiuses;
// Optional
private bool? steps;
/// <summary> Initializes a new instance of the <see cref="DirectionResource" /> class.</summary>
/// <param name="coordinates">
/// Array of LatLng points along route, between 2 and 25 elements in length.
/// </param>
/// <param name="profile">
/// A routing profile, <see cref="RoutingProfile"/> for all profile options.
/// </param>
public DirectionResource(Vector2d[] coordinates, RoutingProfile profile)
{
this.Coordinates = coordinates;
this.RoutingProfile = profile;
}
/// <summary> Gets the API endpoint as a partial URL path. </summary>
public override string ApiEndpoint {
get {
return this.apiEndpoint;
}
}
/// <summary>
/// Gets or sets the coordinates. Array of LatLng points along route,
/// between 2 and 25 elements in length.
/// </summary>
public Vector2d[] Coordinates {
get {
return this.coordinates;
}
set {
if (value.Length < 2 || value.Length > 25)
{
throw new Exception("Must be between 2 and 25 elements in coordinates array.");
}
this.coordinates = value;
}
}
/// <summary>
/// Gets or sets the routing profile, <see cref="RoutingProfile"/> for all profile options.
/// </summary>
public RoutingProfile RoutingProfile {
get {
return this.profile;
}
set {
this.profile = value;
}
}
/// <summary>
/// Gets or sets the alternative option. Controls whether direction request should
/// return alternative routes.
/// </summary>
public bool? Alternatives {
get {
return this.alternatives;
}
set {
this.alternatives = value;
}
}
/// <summary>
/// Gets or sets the bearing option. An array of bearing filters. Each filter is composed of
/// a bearing as decimal degrees clockwise between 0 and 360, and a range of variation from
/// the bearing as decimal degrees between 0 and 180.
/// </summary>
public BearingFilter[] Bearings {
get {
return this.bearings;
}
set {
if (value != null && value.Length != this.coordinates.Length)
{
throw new Exception("There must be as many bearings as there are coordinates in the request.");
}
this.bearings = value;
}
}
/// <summary>
/// Gets or sets the continue_straight option. Controls whether to route will
/// continue in same direction of travel or if route may continue in opposite
/// direction of travel at intermediate waypoints.
/// </summary>
public bool? ContinueStraight {
get {
return this.continueStraight;
}
set {
this.continueStraight = value;
}
}
/// <summary>
/// Gets or sets the overview option. See <see cref="Overview"/> for all overview options.
/// </summary>
public Overview Overview {
get {
return this.overview;
}
set {
this.overview = value;
}
}
/// <summary>
/// Gets or sets the radiuses option. Controls maximum distance in meters that
/// each coordinate is allowed to move when snapped to a nearby road segment.
/// </summary>
public double[] Radiuses {
get {
return this.radiuses;
}
set {
if (value != null)
{
if (value.Length != this.coordinates.Length)
{
throw new Exception("There must be as many radiuses as there are coordinates in the request.");
}
for (int i = 0; i < value.Length; i++)
{
if (value[i] <= 0)
{
throw new Exception("Radius must be greater than 0");
}
}
}
this.radiuses = value;
}
}
/// <summary> Gets or sets the steps option. Controls whether to return steps and turn-by-turn instructions.</summary>
public bool? Steps {
get {
return this.steps;
}
set {
this.steps = value;
}
}
/// <summary>
/// Gets the URL string.
/// </summary>
/// <returns>The URL string.</returns>
public override string GetUrl()
{
Dictionary<string, string> opts = new Dictionary<string, string>();
if (this.Alternatives != null)
{
opts.Add("alternatives", this.Alternatives.ToString().ToLower());
}
if (this.Bearings != null)
{
opts.Add("bearings", GetUrlQueryFromArray(this.Bearings, ";"));
}
if (this.ContinueStraight != null)
{
opts.Add("continue_straight", this.ContinueStraight.ToString().ToLower());
}
if (this.Overview != null)
{
opts.Add("overview", this.Overview.ToString());
}
if (this.Radiuses != null)
{
opts.Add("radiuses", GetUrlQueryFromArray(this.Radiuses));
}
if (this.Steps != null)
{
opts.Add("steps", this.Steps.ToString().ToLower());
}
return Constants.BaseAPI +
this.ApiEndpoint +
this.RoutingProfile +
GetUrlQueryFromArray<Vector2d>(this.Coordinates, ";") +
".json" +
EncodeQueryString(opts);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 78ecfcb30aefc4289b8d2a83619a2d89
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
// <copyright file="Directions.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System;
using System.Text;
using Mapbox.Json;
using Mapbox.Platform;
using Mapbox.Utils.JsonConverters;
/// <summary>
/// Wrapper around the <see href="https://www.mapbox.com/api-documentation/navigation/#directions">
/// Mapbox Directions API</see>. The Mapbox Directions API will show you how to get where
/// you're going.
/// </summary>
public sealed class Directions
{
private readonly IFileSource fileSource;
/// <summary> Initializes a new instance of the <see cref="Directions" /> class. </summary>
/// <param name="fileSource"> Network access abstraction. </param>
public Directions(IFileSource fileSource)
{
this.fileSource = fileSource;
}
/// <summary> Performs asynchronously a directions lookup. </summary>
/// <param name="direction"> Direction resource. </param>
/// <param name="callback"> Callback to be called after the request is completed. </param>
/// <returns>
/// Returns a <see cref="IAsyncRequest" /> that can be used for canceling a pending
/// request. This handle can be completely ignored if there is no intention of ever
/// canceling the request.
/// </returns>
public IAsyncRequest Query(DirectionResource direction, Action<DirectionsResponse> callback)
{
return this.fileSource.Request(
direction.GetUrl(),
(Response response) =>
{
var str = Encoding.UTF8.GetString(response.Data);
var data = Deserialize(str);
callback(data);
});
}
/// <summary>
/// Deserialize the geocode response string into a <see cref="DirectionsResponse"/>.
/// </summary>
/// <param name="str">JSON String.</param>
/// <returns>A <see cref="DirectionsResponse"/>.</returns>
public DirectionsResponse Deserialize(string str)
{
return JsonConvert.DeserializeObject<DirectionsResponse>(str, JsonConverters.Converters);
}
public string Serialize(DirectionsResponse response)
{
return JsonConvert.SerializeObject(response, JsonConverters.Converters);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a4fc862e3db034a0b8591a58cd15afdc
timeCreated: 1491243034
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+38
View File
@@ -0,0 +1,38 @@
//-----------------------------------------------------------------------
// <copyright file="Overview.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
/// <summary>
/// Type of returned overview geometry. Can be full (the most detailed geometry available),
/// simplified (a simplified version of the full geometry), or false (no overview geometry).
/// </summary>
public sealed class Overview
{
/// <summary> Use the most detailed geometry available. </summary>
public static readonly Overview Full = new Overview("full");
/// <summary> Use simplified geometry. This is the default value. </summary>
public static readonly Overview Simplified = new Overview("simplified");
/// <summary> Use no overview geometry. </summary>
public static readonly Overview False = new Overview("false");
private readonly string overview;
private Overview(string overview)
{
this.overview = overview;
}
/// <summary> Converts the overview type to a string. </summary>
/// <returns> A string to use as an optional value in the direction query URL. </returns>
public override string ToString()
{
return this.overview;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 794258e75ed8d4cee96d4b5ba225cfc8
timeCreated: 1491243034
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 41da431a6ab1548a29eecc30eebabe26
folderAsset: yes
timeCreated: 1491243031
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
//-----------------------------------------------------------------------
// <copyright file="Leg.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System.Collections.Generic;
using Mapbox.Json;
/// <summary>
/// <para>An annotations object contains additional details about each line segment along the route geometry.</para>
/// <para></para>Each entry in an annotations field corresponds to a coordinate along the route geometry.
/// </summary>
public class Annotation
{
[JsonProperty("distance")]
public double[] Distance { get; set; }
[JsonProperty("duration")]
public double[] Duration { get; set; }
[JsonProperty("speed")]
public string[] Speed { get; set; }
[JsonProperty("congestion")]
public string[] Congestion { get; set; }
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 204896b65f98440449415ca9b9c1d643
timeCreated: 1508343130
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------
// <copyright file="DirectionsResponse.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions {
using System;
using System.Collections.Generic;
using Mapbox.Json;
/// <summary>
/// Directions response.
/// </summary>
#if !WINDOWS_UWP
// http://stackoverflow.com/a/12903628
[Serializable]
#endif
public class DirectionsResponse {
/// <summary>
/// Gets or sets the routes.
/// </summary>
/// <value>The routes.</value>
[JsonProperty("routes")]
public List<Route> Routes { get; set; }
/// <summary>
/// Gets or sets the waypoints.
/// </summary>
/// <value>The waypoints.</value>
[JsonProperty("waypoints")]
public List<Waypoint> Waypoints { get; set; }
/// <summary>
/// Gets or sets the code.
/// </summary>
/// <value>The code.</value>
[JsonProperty("code")]
public string Code { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f69de6bfcf63e4d2ab766574bca2caf6
timeCreated: 1491243035
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
//-----------------------------------------------------------------------
// <copyright file="Intersection.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System.Collections.Generic;
using Mapbox.Json;
using Mapbox.Utils;
using Mapbox.Utils.JsonConverters;
/// <summary>
/// An Intersection from a Directions API call.
/// </summary>
public class Intersection
{
/// <summary>
/// Gets or sets the out.
/// </summary>
/// <value>The out.</value>
[JsonProperty("out", Order = 0)]
public int Out { get; set; }
/// <summary>
/// Gets or sets the entry.
/// </summary>
/// <value>The entry.</value>
[JsonProperty("entry", Order = 1)]
public List<bool> Entry { get; set; }
/// <summary>
/// Gets or sets the bearings.
/// </summary>
/// <value>The bearings.</value>
[JsonProperty("bearings", Order = 2)]
public List<int> Bearings { get; set; }
/// <summary>
/// Gets or sets the location.
/// </summary>
/// <value>The location.</value>
[JsonProperty("location", Order = 3)]
[JsonConverter(typeof(LonLatToVector2dConverter))]
public Vector2d Location { get; set; }
/// <summary>
/// Gets or sets the in.
/// </summary>
/// <value>The in.</value>
[JsonProperty("in", Order = 4, NullValueHandling = NullValueHandling.Ignore)]
public int? In { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 38b89d19d5fc44375966036ad1331f3d
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
//-----------------------------------------------------------------------
// <copyright file="Leg.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System.Collections.Generic;
using Mapbox.Json;
/// <summary>
/// A Leg from a Directions API call.
/// </summary>
public class Leg
{
/// <summary>
/// Depending on the steps parameter, either an Array of RouteStep objects (true, default) or an empty array (false)
/// </summary>
/// <value>The steps.</value>
[JsonProperty("steps")]
public List<Step> Steps { get; set; }
/// <summary>
/// Depending on the summary parameter, either a String summarizing the route (true, default) or an empty String (false).
/// </summary>
/// <value>The summary.</value>
[JsonProperty("summary")]
public string Summary { get; set; }
/// <summary>
/// Number indicating the estimated travel time in seconds.
/// </summary>
[JsonProperty("duration")]
public double Duration { get; set; }
/// <summary>
/// Number indicating the distance traveled in meters.
/// </summary>
[JsonProperty("distance")]
public double Distance { get; set; }
/// <summary>
/// An annotations object that contains additional details about each line segment along the route geometry. Each entry in an annotations field corresponds to a coordinate along the route geometry.
/// </summary>
[JsonProperty("annotation")]
public Annotation Annotation { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7847e2706c04347a19461bd848b5e1bd
timeCreated: 1491243034
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,59 @@
//-----------------------------------------------------------------------
// <copyright file="Maneuver.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using Mapbox.Json;
using Mapbox.Utils;
/// <summary>
/// A Maneuver from a directions API call.
/// </summary>
public class Maneuver
{
/// <summary>
/// Gets or sets the bearing after.
/// </summary>
/// <value>The bearing after.</value>
[JsonProperty("bearing_after")]
public int BearingAfter { get; set; }
/// <summary>
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
[JsonProperty("type")]
public string Type { get; set; }
/// <summary>
/// Gets or sets the modifier.
/// </summary>
/// <value>The modifier.</value>
[JsonProperty("modifier")]
public string Modifier { get; set; }
/// <summary>
/// Gets or sets the bearing before.
/// </summary>
/// <value>The bearing before.</value>
[JsonProperty("bearing_before")]
public int BearingBefore { get; set; }
/// <summary>
/// Gets or sets the location.
/// </summary>
/// <value>The location.</value>
[JsonProperty("Location")]
public Vector2d Location { get; set; }
/// <summary>
/// Gets or sets the instruction.
/// </summary>
/// <value>The instruction.</value>
[JsonProperty("instruction")]
public string Instruction { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 41f778a9c28ef4b17ace4d80f89dbc7a
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------
// <copyright file="Route.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System.Collections.Generic;
using Mapbox.Json;
using Mapbox.Utils;
using Mapbox.Utils.JsonConverters;
/// <summary>
/// A Route from a Directions API call.
/// </summary>
public class Route
{
/// <summary>
/// Gets or sets the legs.
/// </summary>
/// <value>The legs.</value>
[JsonProperty("legs")]
public List<Leg> Legs { get; set; }
/// <summary>
/// Gets or sets the geometry. Polyline is an array of LatLng's.
/// </summary>
/// <value>The geometry.</value>
[JsonProperty("geometry")]
[JsonConverter(typeof(PolylineToVector2dListConverter))]
public List<Vector2d> Geometry { get; set; }
/// <summary>
/// Gets or sets the duration.
/// </summary>
/// <value>The duration.</value>
[JsonProperty("duration")]
public double Duration { get; set; }
/// <summary>
/// Gets or sets the distance.
/// </summary>
/// <value>The distance.</value>
[JsonProperty("distance")]
public double Distance { get; set; }
/// <summary>
/// Float indicating the weight in units described by 'weight_name'.
/// </summary>
[JsonProperty("weight")]
public float Weight { get; set; }
/// <summary>
/// String indicating which weight was used. The default is routability which is duration based, with additional penalties for less desirable maneuvers.
/// </summary>
[JsonProperty("weight_name")]
public string WeightName { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 67e17dbf44b85417d90ee1b71d9749f3
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
//-----------------------------------------------------------------------
// <copyright file="Step.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using System.Collections.Generic;
using Mapbox.Json;
using Mapbox.Utils;
using Mapbox.Utils.JsonConverters;
/// <summary>
/// A step from a Directions API call.
/// </summary>
public class Step
{
/// <summary>
/// Gets or sets the intersections.
/// </summary>
/// <value>The intersections.</value>
[JsonProperty("intersections")]
public List<Intersection> Intersections { get; set; }
/// <summary>
/// Gets or sets the geometry.
/// </summary>
/// <value>The geometry.</value>
[JsonProperty("geometry")]
[JsonConverter(typeof(PolylineToVector2dListConverter))]
public List<Vector2d> Geometry { get; set; }
/// <summary>
/// Gets or sets the maneuver.
/// </summary>
/// <value>The maneuver.</value>
[JsonProperty("maneuver")]
public Maneuver Maneuver { get; set; }
/// <summary>
/// Gets or sets the duration.
/// </summary>
/// <value>The duration.</value>
[JsonProperty("duration")]
public double Duration { get; set; }
/// <summary>
/// Gets or sets the distance.
/// </summary>
/// <value>The distance.</value>
[JsonProperty("distance")]
public double Distance { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the mode.
/// </summary>
/// <value>The mode.</value>
[JsonProperty("mode")]
public string Mode { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cb67b81b6de1f41fca077297633b5a7d
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
//-----------------------------------------------------------------------
// <copyright file="Waypoint.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
using Mapbox.Json;
using Mapbox.Utils;
using Mapbox.Utils.JsonConverters;
/// <summary>
/// A Waypoint from a Directions API call.
/// </summary>
public class Waypoint
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the location.
/// </summary>
/// <value>The location.</value>
[JsonProperty("location")]
[JsonConverter(typeof(LonLatToVector2dConverter))]
public Vector2d Location { get; set; }
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 813ff4647909949fdbd67f232221cab3
timeCreated: 1493218361
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,38 @@
//-----------------------------------------------------------------------
// <copyright file="RoutingProfile.cs" company="Mapbox">
// Copyright (c) 2016 Mapbox. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Mapbox.Directions
{
/// <summary>
/// Routing profile, affects how the route is calculated, prioritizing routes that fit
/// the profile the best.
/// </summary>
public sealed class RoutingProfile
{
/// <summary> The driving profile. </summary>
public static readonly RoutingProfile Driving = new RoutingProfile("mapbox/driving/");
/// <summary> The walking profile. </summary>
public static readonly RoutingProfile Walking = new RoutingProfile("mapbox/walking/");
/// <summary> The cycling profile. </summary>
public static readonly RoutingProfile Cycling = new RoutingProfile("mapbox/cycling/");
private readonly string profile;
private RoutingProfile(string profile)
{
this.profile = profile;
}
/// <summary> Converts the profile to a URL snippet. </summary>
/// <returns> A string to be appened to the direction query URL. </returns>
public override string ToString()
{
return this.profile;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 02efec76b920540358fd490e1c105268
timeCreated: 1491243033
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: