From 38331ad9449a00b696624cbe1742dbd32e945f6f Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Thu, 3 Mar 2016 18:40:09 +0300 Subject: [PATCH] Fixed an issue when swiping through many regions they were all added to the download queue --- map/framework.cpp | 17 +++++++++++++---- map/framework.hpp | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index 339597c69b..57a6afc426 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -288,6 +288,7 @@ Framework::Framework() , m_bmManager(*this) , m_fixedSearchResults(0) , m_lastReportedCountry(kInvalidCountryId) + , m_watchdogCountryUpdate(seconds(2)) { // Restore map style before classificator loading int mapStyle = MapStyleLight; @@ -942,11 +943,19 @@ void Framework::ClearAllCaches() m_searchEngine->ClearCaches(); } +void Framework::OnCheckUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel) +{ + if (zoomLevel <= scales::GetUpperWorldScale()) + m_watchdogCountryUpdate.Drop(); + else + m_watchdogCountryUpdate.RestartWith([this, pt, zoomLevel]{ + OnUpdateCurrentCountry(pt, zoomLevel); + }); +} + void Framework::OnUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel) { - storage::TCountryId newCountryId; - if (zoomLevel > scales::GetUpperWorldScale()) - newCountryId = m_storage.FindCountryIdByFile(m_infoGetter->GetRegionCountryId(m2::PointD(pt))); + storage::TCountryId newCountryId = m_infoGetter->GetRegionCountryId(m2::PointD(pt)); if (newCountryId == m_lastReportedCountry) return; @@ -1356,7 +1365,7 @@ void Framework::CreateDrapeEngine(ref_ptr contextFactory, auto isCountryLoadedFn = bind(&Framework::IsCountryLoaded, this, _1); auto isCountryLoadedByNameFn = bind(&Framework::IsCountryLoadedByName, this, _1); - auto updateCurrentCountryFn = bind(&Framework::OnUpdateCurrentCountry, this, _1, _2); + auto updateCurrentCountryFn = bind(&Framework::OnCheckUpdateCurrentCountry, this, _1, _2); bool allow3d; bool allow3dBuildings; diff --git a/map/framework.hpp b/map/framework.hpp index 125001eb9b..44ea8e6cc8 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -34,6 +34,7 @@ #include "geometry/rect2d.hpp" #include "geometry/screenbase.hpp" +#include "base/deferred_task.hpp" #include "base/macros.hpp" #include "base/strings_bundle.hpp" #include "base/thread_checker.hpp" @@ -41,6 +42,7 @@ #include "std/list.hpp" #include "std/shared_ptr.hpp" #include "std/target_os.hpp" +#include "std/thread.hpp" #include "std/unique_ptr.hpp" #include "std/vector.hpp" #include "std/weak_ptr.hpp" @@ -126,6 +128,7 @@ protected: double m_startForegroundTime; storage::Storage m_storage; + DeferredTask m_watchdogCountryUpdate; location::TMyPositionModeChanged m_myPositionListener; @@ -357,6 +360,7 @@ private: void FillSearchResultsMarks(search::Results const & results); + void OnCheckUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel); void OnUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel); storage::TCountryId m_lastReportedCountry;