From 719376ffe9d6e2e209a3d1d50bb3b0d15e90a2a4 Mon Sep 17 00:00:00 2001 From: Alexander Marchuk Date: Tue, 3 Nov 2015 16:46:48 +0300 Subject: [PATCH] [routing] add: Last used router type can be retrieved by the client. --- map/framework.cpp | 31 +++++++++++++++++-------------- map/framework.hpp | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index b9515bf4ef..9582660e09 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2385,27 +2385,30 @@ RouterType Framework::GetBestRouter(m2::PointD const & startPoint, m2::PointD co { if (MercatorBounds::DistanceOnEarth(startPoint, finalPoint) < kKeepPedestrianDistanceMeters) { - string routerType; - Settings::Get(kRouterTypeKey, routerType); - if (routerType == routing::ToString(RouterType::Pedestrian)) + if (GetLastUsedRouter() == RouterType::Pedestrian) return RouterType::Pedestrian; - else + + // Return on a short distance the vehicle router flag only if we are already have routing files. + auto countryFileGetter = [this](m2::PointD const & pt) { - // Return on a short distance the vehicle router flag only if we are already have routing files. - auto countryFileGetter = [this](m2::PointD const & pt) - { - return m_infoGetter->GetRegionFile(pt); - }; - if (!OsrmRouter::CheckRoutingAbility(startPoint, finalPoint, countryFileGetter, - &m_model.GetIndex())) - { - return RouterType::Pedestrian; - } + return m_infoGetter->GetRegionFile(pt); + }; + if (!OsrmRouter::CheckRoutingAbility(startPoint, finalPoint, countryFileGetter, + &m_model.GetIndex())) + { + return RouterType::Pedestrian; } } return RouterType::Vehicle; } +RouterType Framework::GetLastUsedRouter() const +{ + string routerType; + Settings::Get(kRouterTypeKey, routerType); + return (routerType == routing::ToString(RouterType::Pedestrian) ? RouterType::Pedestrian : RouterType::Vehicle); +} + void Framework::SetLastUsedRouter(RouterType type) { Settings::Set(kRouterTypeKey, routing::ToString(type)); diff --git a/map/framework.hpp b/map/framework.hpp index 9ae5b5fec2..3f0c957413 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -602,6 +602,7 @@ public: void CloseRouting(); void GetRouteFollowingInfo(location::FollowingInfo & info) const { m_routingSession.GetRouteFollowingInfo(info); } m2::PointD GetRouteEndPoint() const { return m_routingSession.GetEndPoint(); } + routing::RouterType GetLastUsedRouter() const; void SetLastUsedRouter(routing::RouterType type); /// Returns the most situable router engine type. Bases on distance and the last used router. routing::RouterType GetBestRouter(m2::PointD const & startPoint, m2::PointD const & finalPoint);