Add viaroute suport for new API
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#ifndef ENGINE_API_BASE_API_HPP
|
||||
#define ENGINE_API_BASE_API_HPP
|
||||
|
||||
#include "engine/api/base_parameters.hpp"
|
||||
#include "engine/datafacade/datafacade_base.hpp"
|
||||
|
||||
#include "engine/api/json_factory.hpp"
|
||||
#include "engine/hint.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename ChildT> class BaseAPI_
|
||||
{
|
||||
public:
|
||||
BaseAPI_(const datafacade::BaseDataFacade &facade_, const BaseParameters ¶meters_)
|
||||
: facade(facade_), parameters(parameters_)
|
||||
{
|
||||
}
|
||||
|
||||
virtual util::json::Array
|
||||
MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
|
||||
{
|
||||
BOOST_ASSERT(parameters.coordinates.size() > 0);
|
||||
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
|
||||
|
||||
util::json::Array waypoints;
|
||||
waypoints.values.resize(parameters.coordinates.size());
|
||||
waypoints.values[0] = MakeWaypoint(parameters.coordinates.front(),
|
||||
segment_end_coordinates.front().source_phantom);
|
||||
|
||||
auto coord_iter = std::next(parameters.coordinates.begin());
|
||||
auto out_iter = std::next(waypoints.values.begin());
|
||||
for (const auto &phantoms : segment_end_coordinates)
|
||||
{
|
||||
*out_iter++ = MakeWaypoint(*coord_iter++, phantoms.target_phantom);
|
||||
}
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual util::json::Object MakeWaypoint(const util::FixedPointCoordinate input_coordinate,
|
||||
const PhantomNode &phantom) const
|
||||
{
|
||||
return json::makeWaypoint(phantom.location, facade.get_name_for_id(phantom.name_id),
|
||||
Hint{input_coordinate, phantom, facade.GetCheckSum()});
|
||||
}
|
||||
|
||||
const datafacade::BaseDataFacade &facade;
|
||||
const BaseParameters ¶meters;
|
||||
};
|
||||
}
|
||||
|
||||
// Only expose non-templated version
|
||||
using BaseAPI = detail::BaseAPI_<std::true_type>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef ENGINE_API_BASE_PARAMETERS_HPP
|
||||
#define ENGINE_API_BASE_PARAMETERS_HPP
|
||||
|
||||
#include "engine/hint.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct BaseParameters
|
||||
{
|
||||
struct Bearing
|
||||
{
|
||||
short bearing;
|
||||
short range;
|
||||
};
|
||||
|
||||
std::vector<util::FixedPointCoordinate> coordinates;
|
||||
std::vector<boost::optional<Hint>> hints;
|
||||
std::vector<boost::optional<double>> radiuses;
|
||||
std::vector<boost::optional<Bearing>> bearings;
|
||||
|
||||
// FIXME add validation for invalid bearing values
|
||||
bool IsValid() const
|
||||
{
|
||||
return (hints.empty() || hints.size() == coordinates.size()) &&
|
||||
(bearings.empty() || bearings.size() == coordinates.size()) &&
|
||||
(radiuses.empty() || radiuses.size() == coordinates.size());
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const BaseParameters::Bearing lhs, const BaseParameters::Bearing rhs)
|
||||
{
|
||||
return lhs.bearing == rhs.bearing && lhs.range == rhs.range;
|
||||
}
|
||||
inline bool operator!=(const BaseParameters::Bearing lhs, const BaseParameters::Bearing rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROUTE_PARAMETERS_HPP
|
||||
@@ -0,0 +1,90 @@
|
||||
#ifndef ENGINE_RESPONSE_OBJECTS_HPP_
|
||||
#define ENGINE_RESPONSE_OBJECTS_HPP_
|
||||
|
||||
#include "extractor/turn_instructions.hpp"
|
||||
#include "extractor/travel_mode.hpp"
|
||||
#include "engine/polyline_compressor.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
#include "util/json_container.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
|
||||
struct Hint;
|
||||
|
||||
namespace guidance
|
||||
{
|
||||
class RouteLeg;
|
||||
class RouteStep;
|
||||
class StepManeuver;
|
||||
class Route;
|
||||
class LegGeometry;
|
||||
}
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace json
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
std::string instructionToString(extractor::TurnInstruction instruction);
|
||||
|
||||
util::json::Array coordinateToLonLat(const FixedPointCoordinate &coordinate);
|
||||
|
||||
std::string modeToString(const extractor::TravelMode mode);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename ForwardIter> util::json::String makePolyline(ForwardIter begin, ForwardIter end)
|
||||
{
|
||||
util::json::String polyline;
|
||||
polyline.value = encodePolyline(begin, end);
|
||||
return polyline;
|
||||
}
|
||||
|
||||
template <typename ForwardIter>
|
||||
util::json::Object makeGeoJSONLineString(ForwardIter begin, ForwardIter end)
|
||||
{
|
||||
util::json::Object geojson;
|
||||
geojson.values["type"] = "LineString";
|
||||
util::json::Array coordinates;
|
||||
std::transform(begin, end, std::back_inserter(coordinates.values),
|
||||
[](const util::FixedPointCoordinate loc)
|
||||
{
|
||||
return detail::coordinateToLonLat(loc);
|
||||
});
|
||||
geojson.values["coordinates"] = std::move(coordinates);
|
||||
return geojson;
|
||||
}
|
||||
|
||||
util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver);
|
||||
|
||||
util::json::Object makeRouteStep(guidance::RouteStep &&step,
|
||||
boost::optional<util::json::Value> geometry);
|
||||
|
||||
util::json::Object makeRoute(const guidance::Route &route,
|
||||
util::json::Array &&legs,
|
||||
boost::optional<util::json::Value> geometry);
|
||||
|
||||
util::json::Object
|
||||
makeWaypoint(const FixedPointCoordinate location, std::string &&way_name, const Hint &hint);
|
||||
|
||||
util::json::Object makeRouteLeg(guidance::RouteLeg &&leg, util::json::Array &&steps);
|
||||
|
||||
util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> &&legs,
|
||||
const std::vector<guidance::LegGeometry> &leg_geometries);
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif // ENGINE_GUIDANCE_API_RESPONSE_GENERATOR_HPP_
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef ENGINE_API_MATCH_PARAMETERS_HPP
|
||||
#define ENGINE_API_MATCH_PARAMETERS_HPP
|
||||
|
||||
#include "engine/api/route_parameters.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct MatchParameters : public RouteParameters
|
||||
{
|
||||
std::vector<unsigned> timestamps;
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef ENGINE_API_NEAREST_PARAMETERS_HPP
|
||||
#define ENGINE_API_NEAREST_PARAMETERS_HPP
|
||||
|
||||
#include "engine/api/base_parameters.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct NearestParameters : public BaseParameters
|
||||
{
|
||||
unsigned number_of_results;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROUTE_PARAMETERS_HPP
|
||||
@@ -0,0 +1,135 @@
|
||||
#ifndef ENGINE_API_ROUTE_HPP
|
||||
#define ENGINE_API_ROUTE_HPP
|
||||
|
||||
#include "engine/api/base_api.hpp"
|
||||
#include "engine/api/route_parameters.hpp"
|
||||
#include "engine/api/json_factory.hpp"
|
||||
|
||||
#include "engine/datafacade/datafacade_base.hpp"
|
||||
|
||||
#include "engine/guidance/assemble_leg.hpp"
|
||||
#include "engine/guidance/assemble_route.hpp"
|
||||
#include "engine/guidance/assemble_geometry.hpp"
|
||||
#include "engine/guidance/assemble_overview.hpp"
|
||||
#include "engine/guidance/assemble_steps.hpp"
|
||||
|
||||
#include "engine/internal_route_result.hpp"
|
||||
|
||||
#include "util/integer_range.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename ChildT> class RouteAPI_ : public BaseAPI_<RouteAPI_<ChildT>>
|
||||
{
|
||||
using BaseT = BaseAPI_<RouteAPI_<ChildT>>;
|
||||
|
||||
public:
|
||||
RouteAPI_(const datafacade::BaseDataFacade &facade_, const RouteParameters ¶meters_)
|
||||
: BaseT(facade_, parameters_), parameters(parameters_)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void MakeResponse(const InternalRouteResult &raw_route,
|
||||
util::json::Object &response) const
|
||||
{
|
||||
auto number_of_routes = raw_route.has_alternative() ? 2UL : 1UL;
|
||||
util::json::Array routes;
|
||||
routes.values.resize(number_of_routes);
|
||||
routes.values[0] =
|
||||
MakeRoute(raw_route.segment_end_coordinates, raw_route.unpacked_path_segments,
|
||||
raw_route.source_traversed_in_reverse, raw_route.target_traversed_in_reverse);
|
||||
if (raw_route.has_alternative())
|
||||
{
|
||||
std::vector<std::vector<PathData>> wrapped_leg(1);
|
||||
wrapped_leg.front() = std::move(raw_route.unpacked_alternative);
|
||||
routes.values[1] = MakeRoute(raw_route.segment_end_coordinates, wrapped_leg,
|
||||
raw_route.alt_source_traversed_in_reverse,
|
||||
raw_route.alt_target_traversed_in_reverse);
|
||||
}
|
||||
response.values["waypoints"] = BaseT::MakeWaypoints(raw_route.segment_end_coordinates);
|
||||
response.values["routes"] = std::move(routes);
|
||||
response.values["code"] = "ok";
|
||||
}
|
||||
|
||||
protected:
|
||||
template <typename ForwardIter>
|
||||
util::json::Value MakeGeometry(ForwardIter begin, ForwardIter end) const
|
||||
{
|
||||
if (parameters.geometries == RouteParameters::GeometriesType::Polyline)
|
||||
{
|
||||
return json::makePolyline(begin, end);
|
||||
}
|
||||
|
||||
BOOST_ASSERT(parameters.geometries == RouteParameters::GeometriesType::GeoJSON);
|
||||
return json::makeGeoJSONLineString(begin, end);
|
||||
}
|
||||
|
||||
virtual util::json::Object
|
||||
MakeRoute(const std::vector<PhantomNodes> &segment_end_coordinates,
|
||||
const std::vector<std::vector<PathData>> &unpacked_path_segments,
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
const std::vector<bool> &target_traversed_in_reverse) const
|
||||
{
|
||||
std::vector<guidance::RouteLeg> legs;
|
||||
std::vector<guidance::LegGeometry> leg_geometries;
|
||||
auto number_of_legs = segment_end_coordinates.size();
|
||||
legs.reserve(number_of_legs);
|
||||
leg_geometries.reserve(number_of_legs);
|
||||
for (auto idx : util::irange(0UL, number_of_legs))
|
||||
{
|
||||
const auto &phantoms = segment_end_coordinates[idx];
|
||||
const auto &path_data = unpacked_path_segments[idx];
|
||||
const bool reversed_source = source_traversed_in_reverse[idx];
|
||||
const bool reversed_target = target_traversed_in_reverse[idx];
|
||||
|
||||
auto leg_geometry = guidance::assembleGeometry(
|
||||
BaseT::facade, path_data, phantoms.source_phantom, phantoms.target_phantom);
|
||||
auto leg = guidance::assembleLeg(BaseT::facade, path_data, leg_geometry, phantoms.source_phantom,
|
||||
phantoms.target_phantom, reversed_source, reversed_target);
|
||||
|
||||
if (parameters.steps)
|
||||
{
|
||||
leg.steps = guidance::assembleSteps(BaseT::facade,
|
||||
path_data, leg_geometry, phantoms.source_phantom, phantoms.target_phantom,
|
||||
reversed_source, reversed_target);
|
||||
}
|
||||
|
||||
leg_geometries.push_back(std::move(leg_geometry));
|
||||
legs.push_back(std::move(leg));
|
||||
}
|
||||
auto route = guidance::assembleRoute(legs);
|
||||
boost::optional<util::json::Value> json_overview;
|
||||
if (parameters.overview != RouteParameters::OverviewType::False)
|
||||
{
|
||||
const auto use_simplification =
|
||||
parameters.overview == RouteParameters::OverviewType::Simplified;
|
||||
BOOST_ASSERT(use_simplification ||
|
||||
parameters.overview == RouteParameters::OverviewType::Full);
|
||||
|
||||
auto overview = guidance::assembleOverview(leg_geometries, use_simplification);
|
||||
json_overview = MakeGeometry(overview.begin(), overview.end());
|
||||
}
|
||||
|
||||
return json::makeRoute(route, json::makeRouteLegs(std::move(legs), leg_geometries),
|
||||
std::move(json_overview));
|
||||
}
|
||||
|
||||
const RouteParameters ¶meters;
|
||||
};
|
||||
}
|
||||
|
||||
// Expose non-templated version
|
||||
using RouteAPI = detail::RouteAPI_<std::true_type>;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef ENGINE_API_ROUTE_PARAMETERS_HPP
|
||||
#define ENGINE_API_ROUTE_PARAMETERS_HPP
|
||||
|
||||
#include "engine/api/base_parameters.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct RouteParameters : public BaseParameters
|
||||
{
|
||||
enum class GeometriesType
|
||||
{
|
||||
Polyline,
|
||||
GeoJSON
|
||||
};
|
||||
enum class OverviewType
|
||||
{
|
||||
Simplified,
|
||||
Full,
|
||||
False
|
||||
};
|
||||
|
||||
RouteParameters() = default;
|
||||
|
||||
template<typename... Args>
|
||||
RouteParameters(const bool steps_,
|
||||
const bool alternative_,
|
||||
const GeometriesType geometries_,
|
||||
const OverviewType overview_,
|
||||
std::vector<boost::optional<bool>> uturns_, Args... args_)
|
||||
: BaseParameters{std::forward<Args>(args_)...}, steps{steps_}, alternative{alternative_}, geometries{geometries_},
|
||||
overview{overview_}, uturns{std::move(uturns_)}
|
||||
{
|
||||
}
|
||||
|
||||
bool steps = true;
|
||||
bool alternative = true;
|
||||
GeometriesType geometries = GeometriesType::Polyline;
|
||||
OverviewType overview = OverviewType::Simplified;
|
||||
std::vector<boost::optional<bool>> uturns;
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return coordinates.size() >= 2 && BaseParameters::IsValid() &&
|
||||
(uturns.empty() || uturns.size() == coordinates.size());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef ENGINE_API_TABLE_PARAMETERS_HPP
|
||||
#define ENGINE_API_TABLE_PARAMETERS_HPP
|
||||
|
||||
#include "engine/api/base_parameters.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct TableParameters : public BaseParameters
|
||||
{
|
||||
std::vector<bool> is_source;
|
||||
std::vector<bool> is_destination;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROUTE_PARAMETERS_HPP
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef ENGINE_API_TRIP_PARAMETERS_HPP
|
||||
#define ENGINE_API_TRIP_PARAMETERS_HPP
|
||||
|
||||
#include "engine/api/route_parameters.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
struct TripParameters : public RouteParameters
|
||||
{
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user