forked from organicmaps/organicmaps
Merge pull request #1442 from gardster/osrm_plugin_fix
Osrm plugin fix.
This commit is contained in:
commit
d477f8e0b1
3 changed files with 82 additions and 29 deletions
|
@ -29,6 +29,62 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using TMapRepr = pair<size_t, m2::PointD>;
|
||||
|
||||
class UsedMwmChecker
|
||||
{
|
||||
public:
|
||||
static size_t constexpr kInvalidIndex = numeric_limits<size_t>::max();
|
||||
|
||||
UsedMwmChecker() : m_lastUsedMwm(kInvalidIndex) {}
|
||||
|
||||
void AddPoint(size_t mwmIndex, m2::PointD const & pt)
|
||||
{
|
||||
if (mwmIndex == kInvalidIndex)
|
||||
return;
|
||||
if (mwmIndex != m_lastUsedMwm)
|
||||
{
|
||||
CommitUsedPoints();
|
||||
m_lastUsedMwm = mwmIndex;
|
||||
}
|
||||
m_lastMwmPoints.push_back(pt);
|
||||
}
|
||||
|
||||
vector<TMapRepr> const & GetUsedMwms()
|
||||
{
|
||||
// Get point from the last mwm.
|
||||
CommitUsedPoints();
|
||||
|
||||
std::sort(m_usedMwms.begin(), m_usedMwms.end(), []
|
||||
(TMapRepr const & a, TMapRepr const & b)
|
||||
{
|
||||
return a.first < b.first;
|
||||
});
|
||||
auto const it = std::unique(m_usedMwms.begin(), m_usedMwms.end(), []
|
||||
(TMapRepr const & a, TMapRepr const & b)
|
||||
{
|
||||
return a.first == b.first;
|
||||
});
|
||||
m_usedMwms.erase(it, m_usedMwms.end());
|
||||
return m_usedMwms;
|
||||
}
|
||||
|
||||
private:
|
||||
void CommitUsedPoints()
|
||||
{
|
||||
if (!m_lastMwmPoints.empty() && m_lastUsedMwm != kInvalidIndex)
|
||||
{
|
||||
size_t delta = m_lastMwmPoints.size() / 2;
|
||||
m_usedMwms.emplace_back(m_lastUsedMwm, m_lastMwmPoints[delta]);
|
||||
}
|
||||
m_lastMwmPoints.clear();
|
||||
}
|
||||
|
||||
vector<TMapRepr> m_usedMwms;
|
||||
size_t m_lastUsedMwm;
|
||||
vector<m2::PointD> m_lastMwmPoints;
|
||||
};
|
||||
|
||||
template <class DataFacadeT> class MapsMePlugin final : public BasePlugin
|
||||
{
|
||||
class GetByPoint
|
||||
|
@ -105,6 +161,8 @@ public:
|
|||
|
||||
int HandleRequest(const RouteParameters &route_parameters, osrm::json::Object &reply) override final
|
||||
{
|
||||
double constexpr kMaxDistanceToFindMeters = 1000.0;
|
||||
|
||||
//We process only two points case
|
||||
if (route_parameters.coordinates.size() != 2)
|
||||
return 400;
|
||||
|
@ -118,16 +176,22 @@ public:
|
|||
|
||||
for (const auto i : osrm::irange<std::size_t>(0, route_parameters.coordinates.size()))
|
||||
{
|
||||
std::vector<PhantomNode> phantom_node_vector;
|
||||
std::vector<std::pair<PhantomNode, double>> phantom_node_vector;
|
||||
//FixedPointCoordinate &coordinate = route_parameters.coordinates[i];
|
||||
if (m_facade->IncrementalFindPhantomNodeForCoordinate(route_parameters.coordinates[i],
|
||||
phantom_node_vector, 1))
|
||||
if (m_facade->IncrementalFindPhantomNodeForCoordinateWithMaxDistance(route_parameters.coordinates[i],
|
||||
phantom_node_vector, kMaxDistanceToFindMeters,
|
||||
0 /*min_number_of_phantom_nodes*/, 2 /*max_number_of_phantom_nodes*/))
|
||||
{
|
||||
BOOST_ASSERT(!phantom_node_vector.empty());
|
||||
phantom_node_pair_list[i].first = phantom_node_vector.front();
|
||||
// Don't know why, but distance may be higher that maxDistance.
|
||||
if (phantom_node_vector.front().second > kMaxDistanceToFindMeters)
|
||||
continue;
|
||||
phantom_node_pair_list[i].first = phantom_node_vector.front().first;
|
||||
if (phantom_node_vector.size() > 1)
|
||||
{
|
||||
phantom_node_pair_list[i].second = phantom_node_vector.back();
|
||||
if (phantom_node_vector.back().second > kMaxDistanceToFindMeters)
|
||||
continue;
|
||||
phantom_node_pair_list[i].second = phantom_node_vector.back().first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +251,7 @@ public:
|
|||
return 400;
|
||||
}
|
||||
// Get mwm names
|
||||
vector<pair<string, m2::PointD>> usedMwms;
|
||||
UsedMwmChecker usedChecker;
|
||||
|
||||
for (auto i : osrm::irange<std::size_t>(0, raw_route.unpacked_path_segments.size()))
|
||||
{
|
||||
|
@ -202,26 +266,17 @@ public:
|
|||
m2::PointD pt = MercatorBounds::FromLatLon(seg.lat1, seg.lon1);
|
||||
GetByPoint doGet(m_regions, pt);
|
||||
ForEachCountry(pt, doGet);
|
||||
|
||||
if (doGet.m_res != std::numeric_limits<size_t>::max())
|
||||
usedMwms.emplace_back(make_pair(m_countries[doGet.m_res].m_name, pt));
|
||||
usedChecker.AddPoint(doGet.m_res, pt);
|
||||
}
|
||||
}
|
||||
|
||||
auto const it = std::unique(usedMwms.begin(), usedMwms.end(), [&]
|
||||
(pair<string, m2::PointD> const & a, pair<string, m2::PointD> const & b)
|
||||
{
|
||||
return a.first == b.first;
|
||||
});
|
||||
usedMwms.erase(it, usedMwms.end());
|
||||
|
||||
osrm::json::Array json_array;
|
||||
for (auto & mwm : usedMwms)
|
||||
for (auto & mwm : usedChecker.GetUsedMwms())
|
||||
{
|
||||
osrm::json::Array pointArray;
|
||||
pointArray.values.push_back(mwm.second.x);
|
||||
pointArray.values.push_back(mwm.second.y);
|
||||
pointArray.values.push_back(mwm.first);
|
||||
pointArray.values.push_back(m_countries[mwm.first].m_name);
|
||||
json_array.values.push_back(pointArray);
|
||||
}
|
||||
reply.values["used_mwms"] = json_array;
|
||||
|
|
|
@ -11,10 +11,8 @@ UNIT_TEST(OnlineCrossFetcherSmokeTest)
|
|||
TestOnlineFetcher(
|
||||
{61.76, 34.45}, {45.07, 38.94},
|
||||
{"Russia_Central", "Russia_Central", "Russia_Central", "Russia_Central", "Russia_Central",
|
||||
"Russia_Central", "Russia_Central", "Russia_Central", "Russia_Central", "Russia_Central",
|
||||
"Russia_Central", "Russia_Central", "Russia_Central", "Russia_Central", "Russia_Southern",
|
||||
"Russia_Southern", "Russia_Northwestern", "Russia_Northwestern"},
|
||||
routerComponents);
|
||||
"Russia_Central", "Russia_Southern", "Russia_Southern", "Russia_Northwestern",
|
||||
"Russia_Northwestern", "Russia_Northwestern"}, routerComponents);
|
||||
}
|
||||
|
||||
UNIT_TEST(OnlineRussiaNorthToSouthTest)
|
||||
|
@ -24,6 +22,12 @@ UNIT_TEST(OnlineRussiaNorthToSouthTest)
|
|||
{"Russia_Central", "Russia_Southern", "Russia_Northwestern"}, routerComponents);
|
||||
}
|
||||
|
||||
UNIT_TEST(OnlineRoadToSeaCenterTest)
|
||||
{
|
||||
integration::IRouterComponents & routerComponents = integration::GetOsrmComponents();
|
||||
TestOnlineCrosses({61.76, 34.45}, {42.25,30.10}, {}, routerComponents);
|
||||
}
|
||||
|
||||
UNIT_TEST(OnlineEuropeTestNurnbergToMoscow)
|
||||
{
|
||||
integration::IRouterComponents & routerComponents = integration::GetOsrmComponents();
|
||||
|
@ -41,7 +45,7 @@ UNIT_TEST(OnlineAmericanTestOttawaToWashington)
|
|||
UNIT_TEST(OnlineAsiaPhuketToPnompen)
|
||||
{
|
||||
integration::IRouterComponents & routerComponents = integration::GetOsrmComponents();
|
||||
TestOnlineCrosses({7.90, 98.23}, {11.56, 104.86},
|
||||
TestOnlineCrosses({7.89, 98.30}, {11.56, 104.86},
|
||||
{"Thailand", "Cambodia"}, routerComponents);
|
||||
}
|
||||
|
||||
|
|
|
@ -303,12 +303,6 @@ namespace integration
|
|||
vector<m2::PointD> const & points = fetcher.GetMwmPoints();
|
||||
set<string> foundMwms;
|
||||
|
||||
// Start/stop mwm workaround. Remove after borders migration.
|
||||
foundMwms.insert(routerComponents.GetCountryInfoGetter().GetRegionFile(
|
||||
MercatorBounds::FromLatLon(startPoint)));
|
||||
foundMwms.insert(routerComponents.GetCountryInfoGetter().GetRegionFile(
|
||||
MercatorBounds::FromLatLon(finalPoint)));
|
||||
|
||||
for (m2::PointD const & point : points)
|
||||
{
|
||||
string const mwmName = routerComponents.GetCountryInfoGetter().GetRegionFile(point);
|
||||
|
|
Loading…
Add table
Reference in a new issue