forked from organicmaps/organicmaps
[search] Repeat search Near My Position if not enough results for current viewport.
This commit is contained in:
parent
0acd6d0d35
commit
8efd58305d
2 changed files with 21 additions and 2 deletions
|
@ -148,7 +148,8 @@ void Engine::SearchAsync()
|
|||
}
|
||||
|
||||
// Initialize query.
|
||||
if (params.IsNearMeMode())
|
||||
bool const nearMe = params.IsNearMeMode();
|
||||
if (nearMe)
|
||||
m_pQuery->SetViewport(GetViewportRect(params.m_lat, params.m_lon));
|
||||
else
|
||||
m_pQuery->SetViewport(viewport);
|
||||
|
@ -158,15 +159,32 @@ void Engine::SearchAsync()
|
|||
else
|
||||
m_pQuery->NullPosition();
|
||||
|
||||
unsigned int const resultsNeeded = 10;
|
||||
Results res;
|
||||
|
||||
// Run first search with needed params.
|
||||
try
|
||||
{
|
||||
m_pQuery->Search(params.m_query, res);
|
||||
m_pQuery->Search(params.m_query, res, resultsNeeded);
|
||||
}
|
||||
catch (Query::CancelException const &)
|
||||
{
|
||||
}
|
||||
|
||||
// If not enough results, run second search with "Near Me" viewport.
|
||||
if (!m_pQuery->IsCanceled() && !nearMe && params.m_validPos && (res.Count() < resultsNeeded))
|
||||
{
|
||||
m_pQuery->SetViewport(GetViewportRect(params.m_lat, params.m_lon));
|
||||
|
||||
try
|
||||
{
|
||||
m_pQuery->Search(params.m_query, res, resultsNeeded);
|
||||
}
|
||||
catch (Query::CancelException const &)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Emit results in any way, even if search was canceled.
|
||||
params.m_callback(res);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void ClearCache();
|
||||
|
||||
inline void DoCancel() { m_cancel = true; }
|
||||
inline bool IsCanceled() const { return m_cancel; }
|
||||
struct CancelException {};
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue