diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index e962e2543e..fc117366db 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -447,16 +447,16 @@ void RoutingManager::InsertRoute(Route const & route) // TODO: Now we always update whole route, so we need to remove previous one. RemoveRoute(false /* deactivateFollowing */); - std::unique_ptr transitRouteDisplay; + std::shared_ptr transitRouteDisplay; auto numMwmIds = make_shared(); if (m_currentRouterType == RouterType::Transit) { m_delegate.RegisterCountryFilesOnRoute(numMwmIds); - auto getMwmId = [this, &numMwmIds](routing::NumMwmId numMwmId) + auto getMwmId = [this, numMwmIds](routing::NumMwmId numMwmId) { return m_callbacks.m_indexGetter().GetMwmIdByCountryFile(numMwmIds->GetFile(numMwmId)); }; - transitRouteDisplay = make_unique(m_transitReadManager, getMwmId, + transitRouteDisplay = make_shared(m_transitReadManager, getMwmId, m_callbacks.m_stringsBundleGetter, m_bmManager, m_transitSymbolSizes); } @@ -547,9 +547,19 @@ void RoutingManager::InsertRoute(Route const & route) m_drapeSubroutes.push_back(subrouteId); } - lock_guard lock(m_drapeSubroutesMutex); - m_transitRouteInfo = m_currentRouterType == RouterType::Transit ? transitRouteDisplay->GetRouteInfo() - : TransitRouteInfo(); + { + lock_guard lock(m_drapeSubroutesMutex); + m_transitRouteInfo = m_currentRouterType == RouterType::Transit ? transitRouteDisplay->GetRouteInfo() + : TransitRouteInfo(); + } + + if (m_currentRouterType == RouterType::Transit) + { + GetPlatform().RunTask(Platform::Thread::Gui, [transitRouteDisplay = std::move(transitRouteDisplay)]() + { + transitRouteDisplay->CreateTransitMarks(); + }); + } } void RoutingManager::FollowRoute() diff --git a/map/transit/transit_display.cpp b/map/transit/transit_display.cpp index fdd335e8db..0b224647e8 100644 --- a/map/transit/transit_display.cpp +++ b/map/transit/transit_display.cpp @@ -201,8 +201,6 @@ void TransitRouteDisplay::ProcessSubroute(vector const & segments, if (!m_transitReadManager.GetTransitDisplayInfo(transitDisplayInfos)) return; - std::vector transitMarks; - subroute.m_maxPixelWidth = m_maxSubrouteWidth; subroute.m_styleType = df::SubrouteStyleType::Multiple; subroute.m_style.clear(); @@ -327,7 +325,7 @@ void TransitRouteDisplay::ProcessSubroute(vector const & segments, subroute.m_markers.push_back(marker); marker = df::SubrouteMarker(); - transitMarks.push_back(transitMarkInfo); + m_transitMarks.push_back(transitMarkInfo); transitMarkInfo = TransitMarkInfo(); lastDir = currentDir; @@ -371,7 +369,7 @@ void TransitRouteDisplay::ProcessSubroute(vector const & segments, transitMarkInfo.m_type = TransitMarkInfo::Type::KeyStop; transitMarkInfo.m_symbolName = kTransitSymbols.at(transitType); transitMarkInfo.m_color = lastColor; - transitMarks.push_back(transitMarkInfo); + m_transitMarks.push_back(transitMarkInfo); transitMarkInfo = TransitMarkInfo(); } else @@ -400,17 +398,12 @@ void TransitRouteDisplay::ProcessSubroute(vector const & segments, gateMarkInfo.m_titles.push_back(TransitTitle(title, df::GetTransitTextColorName("default"))); } - transitMarks.push_back(gateMarkInfo); + m_transitMarks.push_back(gateMarkInfo); } } m_routeInfo.m_totalDistInMeters = prevDistance; m_routeInfo.m_totalTimeInSec = static_cast(ceil(prevTime)); - - GetPlatform().RunTask(Platform::Thread::Gui, [this, transitMarks]() - { - CreateTransitMarks(transitMarks); - }); } void TransitRouteDisplay::CollectTransitDisplayInfo(vector const & segments, @@ -475,8 +468,11 @@ TransitMark * TransitRouteDisplay::CreateMark(m2::PointD const & pt, FeatureID c return transitMark; } -void TransitRouteDisplay::CreateTransitMarks(std::vector const & transitMarks) +void TransitRouteDisplay::CreateTransitMarks() { + if (m_transitMarks.empty()) + return; + std::vector const transferMarkerSizes = GetTransitMarkerSizes(kTransferMarkerScale, m_maxSubrouteWidth); std::vector const stopMarkerSizes = GetTransitMarkerSizes(kStopMarkerScale, m_maxSubrouteWidth); @@ -487,9 +483,8 @@ void TransitRouteDisplay::CreateTransitMarks(std::vector const auto const vs = static_cast(df::VisualParams::Instance().GetVisualScale()); auto editSession = m_bmManager->GetEditSession(); - for (size_t i = 0; i < transitMarks.size(); ++i) + for (auto const & mark : m_transitMarks) { - auto const & mark = transitMarks[i]; auto transitMark = CreateMark(mark.m_point, mark.m_featureId); dp::TitleDecl titleDecl; diff --git a/map/transit/transit_display.hpp b/map/transit/transit_display.hpp index 03127d7a9b..45f20c0d4f 100644 --- a/map/transit/transit_display.hpp +++ b/map/transit/transit_display.hpp @@ -108,14 +108,13 @@ public: std::map const & transitSymbolSizes); void ProcessSubroute(std::vector const & segments, df::Subroute & subroute); - + void CreateTransitMarks(); TransitRouteInfo const & GetRouteInfo(); private: void CollectTransitDisplayInfo(std::vector const & segments, TransitDisplayInfos & transitDisplayInfos); - void CreateTransitMarks(std::vector const & transitMarks); TransitMark * CreateMark(m2::PointD const & pt, FeatureID const & fid); TransitReadManager & m_transitReadManager; @@ -125,6 +124,7 @@ private: std::map const & m_symbolSizes; TransitRouteInfo m_routeInfo; + std::vector m_transitMarks; int m_subrouteIndex = 0; float m_maxSubrouteWidth = -1.0f;