Skip to content
Draft
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
6 changes: 3 additions & 3 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ In addition to the [general options](#general-options) the following options are
|steps |`true`, `false` (default) |Returned route steps for each route leg |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, or not at all.|
|overview |`simplified` (default), `full`, `false`, `by_legs` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, not at all, or split by leg.|
|continue\_straight |`default` (default), `true`, `false` |Forces the route to keep going straight at waypoints constraining uturns there even if it would be faster. Default value depends on the profile. |
|waypoints | `{index};{index};{index}...` |Treats input coordinates indicated by given indices as waypoints in returned Match object. Default is to treat all input coordinates as waypoints. |

Expand Down Expand Up @@ -432,7 +432,7 @@ In addition to the [general options](#general-options) the following options are
|steps |`true`, `false` (default) |Returned route steps for each route |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, or not at all.|
|overview |`simplified` (default), `full`, `false`, `by_legs` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, not at all, or split by leg.|
|timestamps |`{timestamp};{timestamp}[;{timestamp} ...]` |Timestamps for the input locations in seconds since UNIX epoch. Timestamps need to be monotonically increasing. |
|radiuses |`{radius};{radius}[;{radius} ...]` |Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy.|
|gaps |`split` (default), `ignore` |Allows the input track splitting based on huge timestamp gaps between points. |
Expand Down Expand Up @@ -489,7 +489,7 @@ In addition to the [general options](#general-options) the following options are
|steps |`true`, `false` (default) |Returned route instructions for each trip |
|annotations |`true`, `false` (default), `nodes`, `distance`, `duration`, `datasources`, `weight`, `speed` |Returns additional metadata for each coordinate along the route geometry. |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, or not at all.|
|overview |`simplified` (default), `full`, `false`, `by_legs` |Add overview geometry either full, simplified according to highest zoom level it could be displayed on, not at all, or split by leg.|

**Fixing Start and End Points**

Expand Down
6 changes: 3 additions & 3 deletions docs/nodejs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Returns the fastest route between two or more coordinates while visiting the way
- `options.steps` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Return route steps for each route leg. (optional, default `false`)
- `options.annotations` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** An array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed` or boolean for enabling/disabling all. (optional, default `false`)
- `options.geometries` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returned route geometry format (influences overview and per step). Can also be `geojson`. (optional, default `polyline`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be displayed on, or not at all (`false`). (optional, default `simplified`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be displayed on, not at all (`false`), or split by leg (`by_legs`). (optional, default `simplified`)
- `options.continue_straight` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Forces the route to keep going straight at waypoints and don't do a uturn even if it would be faster. Default value depends on the profile.
- `options.approaches` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Restrict the direction on the road network at a waypoint, relative to the input coordinate. Can be `null` (unrestricted, default), `curb` or `opposite`.
`null`/`true`/`false`
Expand Down Expand Up @@ -224,7 +224,7 @@ if they cannot be matched successfully.
- `options.steps` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Return route steps for each route. (optional, default `false`)
- `options.annotations` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** An array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed` or boolean for enabling/disabling all. (optional, default `false`)
- `options.geometries` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returned route geometry format (influences overview and per step). Can also be `geojson`. (optional, default `polyline`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be displayed on, or not at all (`false`). (optional, default `simplified`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be displayed on, not at all (`false`), or split by leg (`by_legs`). (optional, default `simplified`)
- `options.timestamps` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Timestamp of the input location (integers, UNIX-like timestamp).
- `options.radiuses` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy. Can be `null` for default value `5` meters or `double >= 0`.
- `options.gaps` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Allows the input track splitting based on huge timestamp gaps between points. Either `split` or `ignore`. (optional, default `split`)
Expand Down Expand Up @@ -294,7 +294,7 @@ Right now, the following combinations are possible:
- `options.steps` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Return route steps for each route. (optional, default `false`)
- `options.annotations` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** An array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed` or boolean for enabling/disabling all. (optional, default `false`)
- `options.geometries` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Returned route geometry format (influences overview and per step). Can also be `geojson`. (optional, default `polyline`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` (optional, default `simplified`)
- `options.overview` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be displayed on, not at all (`false`), or split by leg (`by_legs`). (optional, default `simplified`)
- `options.roundtrip` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Return route is a roundtrip. (optional, default `true`)
- `options.source` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Return route starts at `any` or `first` coordinate. (optional, default `any`)
- `options.destination` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Return route ends at `any` or `last` coordinate. (optional, default `any`)
Expand Down
1 change: 1 addition & 0 deletions include/engine/api/json_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ util::json::Object makeWaypoint(const util::Coordinate &location,
util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps);

util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
std::vector<util::json::Value> leg_geometries,
std::vector<util::json::Value> step_geometries,
std::vector<util::json::Object> annotations);
} // namespace api::json
Expand Down
56 changes: 38 additions & 18 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,26 +186,34 @@ class RouteAPI : public BaseAPI
}

std::optional<util::json::Value>
MakeGeometry(std::optional<std::vector<Coordinate>> &&annotations) const
MakeGeometry(std::optional<std::vector<Coordinate>> &&geometry) const
{
std::optional<util::json::Value> json_geometry;
if (annotations)
if (geometry)
{
auto begin = annotations->begin();
auto end = annotations->end();
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
{
json_geometry = json::makePolyline<100000>(begin, end);
}
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
{
json_geometry = json::makePolyline<1000000>(begin, end);
}
else
{
BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
json_geometry = json::makeGeoJSONGeometry(begin, end);
}
json_geometry = MakeGeometry(*geometry);
}
return json_geometry;
}

util::json::Value
MakeGeometry(const std::vector<Coordinate> &geometry) const
{
util::json::Value json_geometry;
auto begin = geometry.begin();
auto end = geometry.end();
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
{
json_geometry = json::makePolyline<100000>(begin, end);
}
else if (parameters.geometries == RouteParameters::GeometriesType::Polyline6)
{
json_geometry = json::makePolyline<1000000>(begin, end);
}
else
{
BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
json_geometry = json::makeGeoJSONGeometry(begin, end);
}
return json_geometry;
}
Expand Down Expand Up @@ -723,6 +731,16 @@ class RouteAPI : public BaseAPI
auto route = guidance::assembleRoute(legs);
std::optional<util::json::Value> json_overview = MakeGeometry(MakeOverview(leg_geometries));

std::vector<util::json::Value> json_overview_by_legs;
if (parameters.overview == RouteParameters::OverviewType::ByLegs)
{
json_overview_by_legs.reserve(leg_geometries.size());
for (const auto idx : util::irange<std::size_t>(0UL, leg_geometries.size()))
{
json_overview_by_legs.emplace_back(MakeGeometry(leg_geometries[idx].locations));
}
}

std::vector<util::json::Value> step_geometries;
const auto total_step_count =
std::accumulate(legs.begin(),
Expand Down Expand Up @@ -871,6 +889,7 @@ class RouteAPI : public BaseAPI

auto result = json::makeRoute(route,
json::makeRouteLegs(std::move(legs),
std::move(json_overview_by_legs),
std::move(step_geometries),
std::move(annotations)),
std::move(json_overview),
Expand Down Expand Up @@ -1001,7 +1020,8 @@ class RouteAPI : public BaseAPI
MakeOverview(const std::vector<guidance::LegGeometry> &leg_geometries) const
{
std::optional<std::vector<Coordinate>> overview;
if (parameters.overview != RouteParameters::OverviewType::False)
if (parameters.overview != RouteParameters::OverviewType::False &&
parameters.overview != RouteParameters::OverviewType::ByLegs)
{
const auto use_simplification =
parameters.overview == RouteParameters::OverviewType::Simplified;
Expand Down
3 changes: 2 additions & 1 deletion include/engine/api/route_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ struct RouteParameters : public BaseParameters
{
Simplified,
Full,
False
False,
ByLegs
};
enum class AnnotationsType
{
Expand Down
8 changes: 6 additions & 2 deletions include/nodejs/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ inline bool parseCommonParameters(const Napi::Object &obj, ParamType &params)

if (!overview.IsString())
{
ThrowError(obj.Env(), "Overview must be a string: [simplified, full, false]");
ThrowError(obj.Env(), "Overview must be a string: [simplified, full, false, by_legs]");
return false;
}

Expand All @@ -1010,9 +1010,13 @@ inline bool parseCommonParameters(const Napi::Object &obj, ParamType &params)
{
params->overview = osrm::RouteParameters::OverviewType::False;
}
else if (overview_str == "by_legs")
{
params->overview = osrm::RouteParameters::OverviewType::ByLegs;
}
else
{
ThrowError(obj.Env(), "'overview' param must be one of [simplified, full, false]");
ThrowError(obj.Env(), "'overview' param must be one of [simplified, full, false, by_legs]");
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion include/server/api/route_parameters_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ struct RouteParametersGrammar : public BaseParametersGrammar<Iterator, Signature

overview_type.add("simplified", engine::api::RouteParameters::OverviewType::Simplified)(
"full", engine::api::RouteParameters::OverviewType::Full)(
"false", engine::api::RouteParameters::OverviewType::False);
"false", engine::api::RouteParameters::OverviewType::False)(
"by_legs", engine::api::RouteParameters::OverviewType::ByLegs);

annotations_type.add("duration", AnnotationsType::Duration)("nodes",
AnnotationsType::Nodes)(
Expand Down
35 changes: 21 additions & 14 deletions src/engine/api/json_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ util::json::Object makeWaypoint(const util::Coordinate &location,
return waypoint;
}

util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps)
util::json::Object makeRouteLeg(guidance::RouteLeg leg,
util::json::Array steps,
std::optional<util::json::Value> leg_geometry,
std::optional<util::json::Object> annotation)
{
util::json::Object route_leg;
route_leg.values.reserve(5);
Expand All @@ -267,18 +270,19 @@ util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps)
route_leg.values.emplace("weight", leg.weight);
route_leg.values.emplace("summary", std::move(leg.summary));
route_leg.values.emplace("steps", std::move(steps));
return route_leg;
}
util::json::Object
makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps, util::json::Object annotation)
{
util::json::Object route_leg = makeRouteLeg(std::move(leg), std::move(steps));
route_leg.values.reserve(1);
route_leg.values.emplace("annotation", std::move(annotation));
if (leg_geometry)
{
route_leg.values.emplace("geometry", std::move(*leg_geometry));
}
if (annotation)
{
route_leg.values.emplace("annotation", std::move(*annotation));
}
return route_leg;
}

util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
std::vector<util::json::Value> leg_geometries,
std::vector<util::json::Value> step_geometries,
std::vector<util::json::Object> annotations)
{
Expand All @@ -295,15 +299,18 @@ util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
[&step_geometry_iter](guidance::RouteStep step) {
return makeRouteStep(std::move(step), std::move(*step_geometry_iter++));
});
if (annotations.size() > 0)
std::optional<util::json::Object> annotation;
std::optional<util::json::Value> leg_geometry;
if (leg_geometries.size() > 0)
{
json_legs.values.push_back(
makeRouteLeg(std::move(leg), std::move(json_steps), annotations[idx]));
leg_geometry = std::move(leg_geometries[idx]);
}
else
if (annotations.size() > 0)
{
json_legs.values.push_back(makeRouteLeg(std::move(leg), std::move(json_steps)));
annotation = std::move(annotations[idx]);
}
json_legs.values.push_back(
makeRouteLeg(std::move(leg), std::move(json_steps), std::move(leg_geometry), std::move(annotation)));
}
return json_legs;
}
Expand Down
Loading
Loading