Merge branch 'srajkovic-stefan-rajkovic-multiple-nearest-points' into develop
This commit is contained in:
commit
b52f392c92
@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
RouteParameters::RouteParameters()
|
||||
: zoom_level(18), print_instructions(false), alternate_route(true), geometry(true),
|
||||
compression(true), deprecatedAPI(false), uturn_default(false), check_sum(-1)
|
||||
compression(true), deprecatedAPI(false), uturn_default(false), check_sum(-1), num_results(1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -45,6 +45,14 @@ void RouteParameters::setZoomLevel(const short level)
|
||||
}
|
||||
}
|
||||
|
||||
void RouteParameters::setNumberOfResults(const short number)
|
||||
{
|
||||
if (number > 0 && number <= 100)
|
||||
{
|
||||
num_results = number;
|
||||
}
|
||||
}
|
||||
|
||||
void RouteParameters::setAlternateRouteFlag(const bool flag) { alternate_route = flag; }
|
||||
|
||||
void RouteParameters::setUTurn(const bool flag)
|
||||
|
@ -40,6 +40,8 @@ struct RouteParameters
|
||||
RouteParameters();
|
||||
|
||||
void setZoomLevel(const short level);
|
||||
|
||||
void setNumberOfResults(const short number);
|
||||
|
||||
void setAlternateRouteFlag(const bool flag);
|
||||
|
||||
@ -77,6 +79,7 @@ struct RouteParameters
|
||||
bool deprecatedAPI;
|
||||
bool uturn_default;
|
||||
unsigned check_sum;
|
||||
short num_results;
|
||||
std::string service;
|
||||
std::string output_format;
|
||||
std::string jsonp_parameter;
|
||||
|
@ -53,13 +53,13 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
|
||||
reply = http::Reply::StockReply(http::Reply::badRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
int number_of_results = route_parameters.num_results;
|
||||
std::vector<PhantomNode> phantom_node_vector;
|
||||
facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates.front(),
|
||||
phantom_node_vector,
|
||||
route_parameters.zoom_level,
|
||||
1);
|
||||
|
||||
number_of_results);
|
||||
|
||||
JSON::Object json_result;
|
||||
if (phantom_node_vector.empty() || !phantom_node_vector.front().isValid())
|
||||
{
|
||||
@ -69,17 +69,41 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
|
||||
{
|
||||
reply.status = http::Reply::ok;
|
||||
json_result.values["status"] = 0;
|
||||
JSON::Array json_coordinate;
|
||||
json_coordinate.values.push_back(phantom_node_vector.front().location.lat /
|
||||
COORDINATE_PRECISION);
|
||||
json_coordinate.values.push_back(phantom_node_vector.front().location.lon /
|
||||
COORDINATE_PRECISION);
|
||||
json_result.values["mapped_coordinate"] = json_coordinate;
|
||||
std::string temp_string;
|
||||
facade->GetName(phantom_node_vector.front().name_id, temp_string);
|
||||
json_result.values["name"] = temp_string;
|
||||
|
||||
if (number_of_results > 1)
|
||||
{
|
||||
JSON::Array results;
|
||||
|
||||
int vector_length = phantom_node_vector.size();
|
||||
for (const auto i : osrm::irange<std::size_t>(0, std::min(number_of_results, vector_length)))
|
||||
{
|
||||
JSON::Array json_coordinate;
|
||||
JSON::Object result;
|
||||
json_coordinate.values.push_back(phantom_node_vector.at(i).location.lat /
|
||||
COORDINATE_PRECISION);
|
||||
json_coordinate.values.push_back(phantom_node_vector.at(i).location.lon /
|
||||
COORDINATE_PRECISION);
|
||||
result.values["mapped coordinate"] = json_coordinate;
|
||||
std::string temp_string;
|
||||
facade->GetName(phantom_node_vector.front().name_id, temp_string);
|
||||
result.values["name"] = temp_string;
|
||||
results.values.push_back(result);
|
||||
}
|
||||
json_result.values["results"] = results;
|
||||
}
|
||||
else
|
||||
{
|
||||
JSON::Array json_coordinate;
|
||||
json_coordinate.values.push_back(phantom_node_vector.front().location.lat /
|
||||
COORDINATE_PRECISION);
|
||||
json_coordinate.values.push_back(phantom_node_vector.front().location.lon /
|
||||
COORDINATE_PRECISION);
|
||||
json_result.values["mapped_coordinate"] = json_coordinate;
|
||||
std::string temp_string;
|
||||
facade->GetName(phantom_node_vector.front().name_id, temp_string);
|
||||
json_result.values["name"] = temp_string;
|
||||
}
|
||||
}
|
||||
|
||||
JSON::render(reply.content, json_result);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
explicit APIGrammar(HandlerT * h) : APIGrammar::base_type(api_call), handler(h)
|
||||
{
|
||||
api_call = qi::lit('/') >> string[boost::bind(&HandlerT::setService, handler, ::_1)] >> *(query) >> -(uturns);
|
||||
query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | language | instruction | geometry | alt_route | old_API));
|
||||
query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | u | cmp | language | instruction | geometry | alt_route | old_API | num_results) ) ;
|
||||
|
||||
zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)];
|
||||
output = (-qi::lit('&')) >> qi::lit("output") >> '=' >> string[boost::bind(&HandlerT::setOutputFormat, handler, ::_1)];
|
||||
@ -56,6 +56,7 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
language = (-qi::lit('&')) >> qi::lit("hl") >> '=' >> string[boost::bind(&HandlerT::setLanguage, handler, ::_1)];
|
||||
alt_route = (-qi::lit('&')) >> qi::lit("alt") >> '=' >> qi::bool_[boost::bind(&HandlerT::setAlternateRouteFlag, handler, ::_1)];
|
||||
old_API = (-qi::lit('&')) >> qi::lit("geomformat") >> '=' >> string[boost::bind(&HandlerT::setDeprecatedAPIFlag, handler, ::_1)];
|
||||
num_results = (-qi::lit('&')) >> qi::lit("num_results") >> '=' >> qi::short_[boost::bind(&HandlerT::setNumberOfResults, handler, ::_1)];
|
||||
|
||||
string = +(qi::char_("a-zA-Z"));
|
||||
stringwithDot = +(qi::char_("a-zA-Z0-9_.-"));
|
||||
@ -65,7 +66,7 @@ struct APIGrammar : qi::grammar<Iterator>
|
||||
qi::rule<Iterator> api_call, query;
|
||||
qi::rule<Iterator, std::string()> service, zoom, output, string, jsonp, checksum, location, hint,
|
||||
stringwithDot, stringwithPercent, language, instruction, geometry,
|
||||
cmp, alt_route, u, uturns, old_API ;
|
||||
cmp, alt_route, u, uturns, old_API, num_results;
|
||||
|
||||
HandlerT * handler;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user