[traffic] Make traffic initialization work with LoadMapsAsync()

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-07-27 01:24:34 +03:00
parent 958be3dee6
commit 871cd73592
2 changed files with 54 additions and 10 deletions

View File

@@ -394,16 +394,6 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
if (loadMaps)
LoadMapsSync();
m_trafficManager.SetEnabled(LoadTrafficEnabled());
if (!params.m_trafficTestMode && LoadTrafficHttpEnabled())
// TODO handle invalid URLs
traffxml::HttpTraffSource::Create(m_trafficManager, LoadTrafficHttpUrl());
/*
* MockTraffSource for debugging purposes.
*/
//traffxml::MockTraffSource::Create(m_trafficManager);
}
Framework::~Framework()
@@ -423,6 +413,19 @@ Framework::~Framework()
m_featuresFetcher.SetOnMapDeregisteredCallback(nullptr);
}
void Framework::InitializeTraffic()
{
m_trafficManager.SetEnabled(LoadTrafficEnabled());
if (!m_trafficManager.IsTestMode() && LoadTrafficHttpEnabled())
// TODO handle invalid URLs
traffxml::HttpTraffSource::Create(m_trafficManager, LoadTrafficHttpUrl());
/*
* MockTraffSource for debugging purposes.
*/
//traffxml::MockTraffSource::Create(m_trafficManager);
}
void Framework::ShowNode(storage::CountryId const & countryId)
{
StopLocationFollow();
@@ -529,6 +532,8 @@ void Framework::LoadMapsSync()
LOG(LDEBUG, ("Editor initialized"));
GetStorage().RestoreDownloadQueue();
InitializeTraffic();
}
// Small copy-paste with LoadMapsSync, but I don't have a better solution.
@@ -551,6 +556,8 @@ void Framework::LoadMapsAsync(std::function<void()> && callback)
GetStorage().RestoreDownloadQueue();
InitializeTraffic();
callback();
});
}).detach();

View File

@@ -230,7 +230,34 @@ public:
/// \note It works for group and leaf node.
bool HasUnsavedEdits(storage::CountryId const & countryId);
/**
* @brief Loads maps synchronously.
*
* Maps are loaded on the calling thread.
*
* This function also performs certain initialization operations which depend on map data being
* available, such as search, traffic and the download queue.
*
* @note This function is not suitable for use on platforms which enforce restrictions on
* time-consuming or potentially blocking operations on the UI thread (as Android does). On such
* platforms, `LoadMapsAsync()` should be used instead.
*/
void LoadMapsSync();
/**
* @brief Loads maps asynchronously.
*
* Maps are loaded on a new thread. Some operations are executed as part of a separate task which
* is posted to the GUI thread.
*
* This function also performs certain initialization operations which depend on map data being
* available, such as search, traffic and the download queue.
*
* After finishing initialization, the caller-supplied callback function is called. This function
* also runs on the GUI thread and should therefore not perform any time-consuming operations.
*
* @param callback A callback function to run at the end of initialization.
*/
void LoadMapsAsync(std::function<void()> && callback);
/// Registers all local map files in internal indexes.
@@ -389,6 +416,16 @@ private:
private:
std::vector<m2::TriangleD> GetSelectedFeatureTriangles() const;
/**
* @brief Initializes the traffic manager.
*
* This enables the traffic manager if defined in settings. If the traffic manager is not in test
* mode, all cunfigured sources are also added here.
*
* Maps must be loaded prior to calling this method.
*/
void InitializeTraffic();
public:
/// @name GPS location updates routine.
void OnLocationError(location::TLocationError error);