Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web request encoding + option "annotations" #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Src/Osrm.Client/Models/Annotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Osrm.Client.Models
{
[DataContract]
public class Annotation
{
[DataMember(Name = "distance")]
public double[] Distance { get; set; }

[DataMember(Name = "duration")]
public double[] Duration { get; set; }

[DataMember(Name = "datasources")]
public int[] DataSources { get; set; }

[DataMember(Name = "nodes")]
public long[] Nodes { get; set; }

[DataMember(Name = "weight")]
public double[] Weight { get; set; }

[DataMember(Name = "speed")]
public double[] Speed { get; set; }
}
}
10 changes: 8 additions & 2 deletions Src/Osrm.Client/Models/Leg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ public class RouteLeg
[DataMember(Name = "duration")]
public double Duration { get; set; }

[DataMember(Name = "steps")]
public RouteStep[] Steps { get; set; }
[DataMember(Name = "weight")]
public double Weight { get; set; }

[DataMember(Name = "summary")]
public string Summary { get; set; }

[DataMember(Name = "steps")]
public RouteStep[] Steps { get; set; }

[DataMember(Name = "annotation")]
public Annotation Annotation { get; set; }
}
}
9 changes: 9 additions & 0 deletions Src/Osrm.Client/Models/Requests/MatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ namespace Osrm.Client.Models
public class MatchRequest : BaseRequest
{
protected const string DefaultGeometries = "polyline";
protected const string DefaultAnnotations = "false";
protected const string DefaultOverview = "simplified";

public MatchRequest()
{
Geometries = DefaultGeometries;
Annotations = DefaultAnnotations;
Overview = DefaultOverview;
Timestamps = new int[0];
}
Expand All @@ -30,6 +32,12 @@ public MatchRequest()
/// </summary>
public string Geometries { get; set; }

/// <summary>
/// Returns additional metadata for each coordinate along the route geometry.
/// true, false (default), nodes, distance, duration, datasources, weight, speed
/// </summary>
public string Annotations { get; set; }

/// <summary>
/// Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.
/// simplified (default), full, false
Expand All @@ -51,6 +59,7 @@ public override List<Tuple<string, string>> UrlParams
urlParams
.AddBoolParameter("steps", Steps, false)
.AddStringParameter("geometries", Geometries, () => Geometries != DefaultGeometries)
.AddStringParameter("annotations", Annotations, () => Annotations != DefaultAnnotations)
.AddStringParameter("overview", Overview, () => Overview != DefaultOverview)
.AddParams("timestamps", Timestamps.Select(x => x.ToString()).ToArray());

Expand Down
19 changes: 15 additions & 4 deletions Src/Osrm.Client/Models/Requests/RouteRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,39 @@ namespace Osrm.Client.Models
{
public class RouteRequest : BaseRequest
{
protected const string DefaultAlternatives = "false";
protected const string DefaultAnnotations = "false";
protected const string DefaultGeometries = "polyline";
protected const string DefaultOverview = "simplified";
protected const string DefaultContinueStraight = "default";

public RouteRequest()
{
Alternatives = DefaultAlternatives;
Annotations = DefaultAnnotations;
Geometries = DefaultGeometries;
Overview = DefaultOverview;
ContinueStraight = DefaultContinueStraight;
}

/// <summary>
/// Search for alternative routes and return as well.*
/// true, false (default)
/// Search for alternative routes. Passing a number alternatives=n searches for up to n alternative routes.
/// true, false (default), or Number
/// </summary>
public bool Alternative { get; set; }
public string Alternatives { get; set; }

/// <summary>
/// Return route steps for each route leg
/// true, false (default)
/// </summary>
public bool Steps { get; set; }

/// <summary>
/// Returns additional metadata for each coordinate along the route geometry.
/// true, false (default), nodes, distance, duration, datasources, weight, speed
/// </summary>
public string Annotations { get; set; }

/// <summary>
/// Returned route geometry format (influences overview and per step)
/// polyline (default), geojson
Expand All @@ -56,8 +66,9 @@ public override List<Tuple<string, string>> UrlParams
var urlParams = new List<Tuple<string, string>>(BaseUrlParams);

urlParams
.AddBoolParameter("alternatives", Alternative, false)
.AddStringParameter("alternatives", Alternatives, () => Alternatives != DefaultAlternatives)
.AddBoolParameter("steps", Steps, false)
.AddStringParameter("annotations", Annotations, () => Annotations != DefaultAnnotations)
.AddStringParameter("geometries", Geometries, () => Geometries != DefaultGeometries)
.AddStringParameter("overview", Overview, () => Overview != DefaultOverview)
.AddStringParameter("continue_straight", ContinueStraight, () => ContinueStraight != DefaultContinueStraight);
Expand Down
6 changes: 4 additions & 2 deletions Src/Osrm.Client/Models/Requests/TripRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Osrm.Client.Models
{
public class TripRequest : BaseRequest
{
protected const string DefaultAnnotations = "false";
protected const string DefaultGeometries = "polyline";
protected const string DefaultOverview = "simplified";

Expand All @@ -24,8 +25,9 @@ public TripRequest()

/// <summary>
/// Returns additional metadata for each coordinate along the route geometry.
/// true, false (default), nodes, distance, duration, datasources, weight, speed
/// </summary>
public bool Annotate { get; set; }
public string Annotations { get; set; }

/// <summary>
/// Returned route geometry format (influences overview and per step)
Expand All @@ -47,7 +49,7 @@ public override List<Tuple<string, string>> UrlParams

urlParams
.AddBoolParameter("steps", Steps, false)
.AddBoolParameter("annotate", Annotate, false)
.AddStringParameter("annotations", Annotations, () => Annotations != DefaultAnnotations)
.AddStringParameter("geometries", Geometries, () => Geometries != DefaultGeometries)
.AddStringParameter("overview", Overview, () => Overview != DefaultOverview);

Expand Down
3 changes: 3 additions & 0 deletions Src/Osrm.Client/Models/Route.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public Location[] Geometry
}
}

[DataMember(Name = "weight")]
public double Weight { get; set; }

[DataMember(Name = "legs")]
public RouteLeg[] Legs { get; set; }

Expand Down
1 change: 1 addition & 0 deletions Src/Osrm.Client/Osrm.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="4x\Models\RouteInstruction.cs" />
<Compile Include="4x\Models\RouteSummary.cs" />
<Compile Include="4x\Models\Trip.cs" />
<Compile Include="Models\Annotation.cs" />
<Compile Include="Models\Bearing.cs" />
<Compile Include="Models\Leg.cs" />
<Compile Include="Models\Requests\TripRequest.cs" />
Expand Down
6 changes: 6 additions & 0 deletions Src/Osrm.Client/Osrm5x.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class Osrm5x
/// </summary>
public int? Timeout { get; set; }

/// <summary>
/// Encoding for web request
/// </summary>
public Encoding Encoding { get; set; }

protected readonly string RouteServiceName = "route";
protected readonly string NearestServiceName = "nearest";
protected readonly string TableServiceName = "table";
Expand Down Expand Up @@ -127,6 +132,7 @@ protected T Send<T>(string service, BaseRequest request) //string coordinatesStr
string json = null;
using (var client = new OsrmWebClient(Timeout))
{
client.Encoding = Encoding ?? Encoding.Default;
json = client.DownloadString(new Uri(fullUrl));
}

Expand Down