Commit 26a03e5c authored by Volker Krause's avatar Volker Krause
Browse files

Remember which map locations we have already cached

While reloading something we already have doesn't trigger network
activity it does a map data load from disk to find the area we need
to load, which is especially expensive for larger stations/airports.
Now we only do that once per application start.
parent 5bdbda52
......@@ -109,6 +109,19 @@ void MapDownloadManager::addRequest(double lat, double lon, const QDateTime &cac
// check if we already have this cached
for (auto it = m_cachedRequests.begin(); it != m_cachedRequests.end(); ++it) {
if (LocationUtil::distance(lat, lon, (*it).lat, (*it).lon) > 10.0) {
if ((*it).cacheUntil >= cacheUntil) {
// check if there is a pending request that would cover this
for (auto &req : m_pendingRequests) {
if (LocationUtil::distance(, req.lon, lat, lon) < 10.0) {
req.cacheUntil = std::max(req.cacheUntil, cacheUntil);
......@@ -125,18 +138,19 @@ void MapDownloadManager::downloadNext()
const auto req = std::move(m_pendingRequests.back());
m_currentRequest = std::move(m_pendingRequests.back());
m_loader = new KOSMIndoorMap::MapLoader(this);
connect(m_loader, &KOSMIndoorMap::MapLoader::done, this, &MapDownloadManager::downloadFinished);
m_loader->loadForCoordinate(, req.lon, req.cacheUntil);
m_loader->loadForCoordinate(, m_currentRequest.lon, m_currentRequest.cacheUntil);
void MapDownloadManager::downloadFinished()
m_loader = nullptr;
if (m_pendingRequests.empty()) {
Q_EMIT finished();
......@@ -63,6 +63,8 @@ private:
QDateTime cacheUntil;
std::vector<Request> m_pendingRequests;
std::vector<Request> m_cachedRequests;
Request m_currentRequest;
KOSMIndoorMap::MapLoader *m_loader = nullptr;
SolidExtras::NetworkStatus *m_netStatus = nullptr;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment