forked from organicmaps/organicmaps
[routing] Enable get distance and time to route segment
Signed-off-by: Gonzalo Pesquero <gpesquero@yahoo.es>
This commit is contained in:
parent
8d6b3a3d2f
commit
bae86bf9d5
6 changed files with 75 additions and 5 deletions
|
@ -22,6 +22,7 @@
|
|||
#include "indexer/map_style_reader.hpp"
|
||||
|
||||
#include "platform/country_file.hpp"
|
||||
#include "platform/distance.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "platform/socket.hpp"
|
||||
|
||||
|
@ -820,9 +821,42 @@ bool RoutingManager::IsMyPosition(RouteMarkType type, size_t intermediateIndex)
|
|||
vector<RouteMarkData> RoutingManager::GetRoutePoints() const
|
||||
{
|
||||
vector<RouteMarkData> result;
|
||||
RoutePointsLayout routePoints(*m_bmManager);
|
||||
for (auto const & p : routePoints.GetRoutePoints())
|
||||
result.push_back(p->GetMarkData());
|
||||
RoutePointsLayout routePointsLayout(*m_bmManager);
|
||||
|
||||
auto const & routePoints = routePointsLayout.GetRoutePoints();
|
||||
|
||||
size_t subrouteCount = m_routingSession.GetSubrouteCount();
|
||||
//std::vector<routing::Route::SubrouteAttrs> subroutes = m_routingSession.GetSubroutes();
|
||||
|
||||
// Copy subroute time & distance to mark data only if subroute and route point sizes match.
|
||||
bool bCopy = (routePoints.size() == subrouteCount + 1);
|
||||
|
||||
for(int point = 0; point < (int)routePoints.size(); point++)
|
||||
{
|
||||
auto markData = routePoints[point]->GetMarkData();
|
||||
|
||||
if (bCopy)
|
||||
{
|
||||
if (point == 0)
|
||||
{
|
||||
// This is the first starting point. Time & distance are 0.
|
||||
markData.m_timeSec = 0;
|
||||
markData.m_distance = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get subroute time & distance pair.
|
||||
auto timeDistancePair = m_routingSession.GetSubrouteTotalTimeAndDistance(point - 1);
|
||||
markData.m_timeSec = timeDistancePair.first;
|
||||
markData.m_distance = platform::Distance::CreateFormatted(timeDistancePair.second).ToString();
|
||||
}
|
||||
|
||||
LOG(LINFO, ("point", point, "timeSec", markData.m_timeSec, "distance", markData.m_distance));
|
||||
}
|
||||
|
||||
result.push_back(markData);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
|
||||
routing::RoutingSession const & RoutingSession() const { return m_routingSession; }
|
||||
routing::RoutingSession & RoutingSession() { return m_routingSession; }
|
||||
//std::vector<routing::Route::SubrouteAttrs> GetSubroutes() { return m_routingSession.GetSubroutes(); }
|
||||
void SetRouter(routing::RouterType type);
|
||||
routing::RouterType GetRouter() const { return m_currentRouterType; }
|
||||
bool IsRoutingActive() const { return m_routingSession.IsActive(); }
|
||||
|
|
|
@ -24,6 +24,8 @@ struct RouteMarkData
|
|||
bool m_isPassed = false;
|
||||
bool m_replaceWithMyPositionAfterRestart = false;
|
||||
m2::PointD m_position;
|
||||
long m_timeSec = 0;
|
||||
std::string m_distance;
|
||||
};
|
||||
|
||||
class RouteMarkPoint : public UserMark
|
||||
|
|
|
@ -65,6 +65,13 @@ double Route::GetTotalDistanceMeters() const
|
|||
return m_poly.GetTotalDistanceMeters();
|
||||
}
|
||||
|
||||
double Route::GetTotalDistanceToSegmentMeters(size_t segIdx) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return 0.0;
|
||||
return m_routeSegments[segIdx].GetDistFromBeginningMeters();
|
||||
}
|
||||
|
||||
double Route::GetCurrentDistanceFromBeginMeters() const
|
||||
{
|
||||
if (!IsValid())
|
||||
|
@ -160,6 +167,13 @@ double Route::GetCurrentTimeToSegmentSec(size_t segIdx) const
|
|||
return endTimeSec - passedTimeSec;
|
||||
}
|
||||
|
||||
double Route::GetTotalTimeToSegmentSec(size_t segIdx) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return 0.0;
|
||||
return m_routeSegments[segIdx].GetTimeFromBeginningSec();
|
||||
}
|
||||
|
||||
void Route::GetCurrentSpeedLimit(SpeedInUnits & speedLimit) const
|
||||
{
|
||||
if (!IsValid())
|
||||
|
@ -452,6 +466,14 @@ Route::SubrouteSettings const Route::GetSubrouteSettings(size_t segmentIdx) cons
|
|||
return SubrouteSettings(m_routingSettings, m_router, m_subrouteUid);
|
||||
}
|
||||
|
||||
std::pair<long, double> Route::GetSubrouteTotalTimeAndDistance(size_t subrouteIdx) const
|
||||
{
|
||||
size_t endSegmentIdx = m_subrouteAttrs.at(subrouteIdx).GetEndSegmentIdx() - 1;
|
||||
long timeSec = GetTotalTimeToSegmentSec(endSegmentIdx);
|
||||
double distanceMeters = GetTotalDistanceToSegmentMeters(endSegmentIdx);
|
||||
return std::pair<long, double>(timeSec, distanceMeters);
|
||||
}
|
||||
|
||||
bool Route::IsSubroutePassed(size_t subrouteIdx) const
|
||||
{
|
||||
size_t const endSegmentIdx = GetSubrouteAttrs(subrouteIdx).GetEndSegmentIdx();
|
||||
|
@ -532,7 +554,7 @@ std::string Route::DebugPrintTurns() const
|
|||
{
|
||||
auto const & turn = m_routeSegments[i].GetTurn();
|
||||
|
||||
// Always print first elemenst as Start.
|
||||
// Always print first element as Start.
|
||||
if (i == 0 || !turn.IsTurnNone())
|
||||
{
|
||||
res += DebugPrint(mercator::ToLatLon(m_routeSegments[i].GetJunction()));
|
||||
|
|
|
@ -353,7 +353,10 @@ public:
|
|||
/// \brief estimated time to reach segment.
|
||||
double GetCurrentTimeToSegmentSec(size_t segIdx) const;
|
||||
|
||||
/// \brief estimated time to the nearest turn.
|
||||
/// \brief total route time to reach segment.
|
||||
double GetTotalTimeToSegmentSec(size_t segIdx) const;
|
||||
|
||||
/// \brief estimated time to the nearest turn.
|
||||
double GetCurrentTimeToNearestTurnSec() const;
|
||||
|
||||
FollowedPolyline const & GetFollowedPolyline() const { return m_poly; }
|
||||
|
@ -363,11 +366,13 @@ public:
|
|||
|
||||
size_t GetCurrentSubrouteIdx() const { return m_currentSubrouteIdx; }
|
||||
std::vector<SubrouteAttrs> const & GetSubroutes() const { return m_subrouteAttrs; }
|
||||
std::pair<long, double> GetSubrouteTotalTimeAndDistance(size_t subrouteIdx) const;
|
||||
|
||||
std::vector<double> const & GetSegDistanceMeters() const { return m_poly.GetSegDistanceMeters(); }
|
||||
bool IsValid() const { return m_poly.IsValid(); }
|
||||
|
||||
double GetTotalDistanceMeters() const;
|
||||
double GetTotalDistanceToSegmentMeters(size_t segIdx) const;
|
||||
double GetCurrentDistanceFromBeginMeters() const;
|
||||
double GetCurrentDistanceToEndMeters() const;
|
||||
double GetMercatorDistanceFromBegin() const;
|
||||
|
|
|
@ -174,6 +174,12 @@ public:
|
|||
|
||||
double GetCompletionPercent() const;
|
||||
|
||||
size_t GetSubrouteCount() const { return m_route->GetSubrouteCount(); }
|
||||
std::pair<long, double> GetSubrouteTotalTimeAndDistance(size_t subrouteIdx) const
|
||||
{
|
||||
return m_route->GetSubrouteTotalTimeAndDistance(subrouteIdx);
|
||||
}
|
||||
|
||||
private:
|
||||
struct DoReadyCallback
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue