mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
[traffic] Make traffic initialization work with LoadMapsAsync()
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user