[search] Zoom to 9 level, when no any country loaded under serch result.

This commit is contained in:
vng 2012-03-12 17:49:09 +03:00 committed by Alex Zolotarev
parent 1b9528da6a
commit 15e0cc25f4
10 changed files with 45 additions and 11 deletions

View file

@ -86,9 +86,7 @@ public:
scale = min(scale, GetScaleForType(types[i]));
CorrectScaleForVisibility(types, scale);
/// @todo 0.15 - is dummy constant to fix bug in iPad viewport.
return scales::GetRectForLevel(scale - 0.15, limitRect.Center(), 1.0);
return scales::GetRectForLevelFix(scale, limitRect.Center());
}
uint8_t GetSearchRank(TypesHolder const & types, m2::PointD const & pt, uint32_t population) const

View file

@ -17,8 +17,14 @@ namespace scales
/// @return such ration, that GetScaleLevel(ration) == level
double GetRationForLevel(double level);
/// @return such rect, that GetScaleLevel(rect) == level
m2::RectD GetRectForLevel(double level, m2::PointD const & center, double X2YRatio);
inline m2::RectD GetRectForLevelFix(double level, m2::PointD const & center)
{
/// @todo 0.15 - is dummy constant to fix bug in iPad viewport.
return GetRectForLevel(level - 0.15, center, 1.0);
}
double GetEpsilonForLevel(int level);
double GetEpsilonForSimplify(int level);

View file

@ -524,8 +524,7 @@ static void OnSearchResultCallback(search::Results const & res, int queryId)
{
// Zoom to the feature
case search::Result::RESULT_FEATURE:
m_framework->ShowRect(res.GetFeatureRect());
m_framework->DrawPlacemark(res.GetFeatureCenter());
m_framework->ShowSearchResult(res);
// Same as "Close" button but do not disable placemark
[self dismissModalViewControllerAnimated:YES];
break;

View file

@ -69,6 +69,21 @@ void FeaturesFetcher::ClearCaches()
m_multiIndex.ClearCache();
}
bool FeaturesFetcher::IsCountryLoaded(m2::PointD const & pt) const
{
vector<MwmInfo> info;
m_multiIndex.GetMwmInfo(info);
for (size_t i = 0; i < info.size(); ++i)
if (info[i].isValid() && info[i].isCountry() &&
info[i].m_limitRect.IsPointInside(pt))
{
return true;
}
return false;
}
m2::RectD FeaturesFetcher::GetWorldRect() const
{
if (m_rect == m2::RectD())

View file

@ -46,6 +46,8 @@ namespace model
return m_multiIndex.IsLoaded(fName);
}
bool IsCountryLoaded(m2::PointD const & pt) const;
/// @name Features enumeration.
//@{
template <class ToDo>

View file

@ -727,6 +727,20 @@ bool Framework::GetCurrentPosition(double & lat, double & lon)
else return false;
}
void Framework::ShowSearchResult(search::Result const & res)
{
m2::RectD r = res.GetFeatureRect();
if (scales::GetScaleLevel(r) > scales::GetUpperWorldScale())
{
m2::PointD const c = r.Center();
if (!m_model.IsCountryLoaded(c))
r = scales::GetRectForLevelFix(9, c);
}
ShowRect(r);
DrawPlacemark(res.GetFeatureCenter());
}
void Framework::SetRenderPolicy(RenderPolicy * renderPolicy)
{
if (renderPolicy)

View file

@ -48,9 +48,9 @@
//#define DRAW_TOUCH_POINTS
class DrawerYG;
class RenderPolicy;
namespace search { class Result; }
class Framework
{
@ -147,6 +147,7 @@ public:
void PrepareSearch(bool hasPt, double lat = 0.0, double lon = 0.0);
void Search(search::SearchParams const & params);
bool GetCurrentPosition(double & lat, double & lon);
void ShowSearchResult(search::Result const & res);
/// @return country code in ISO 3166-1 alpha-2 format (two small letters) or empty string
string GetCountryCodeByPosition(double lat, double lon);

View file

@ -460,10 +460,9 @@ namespace qt
m_framework->Search(params);
}
void DrawWidget::ShowFeature(m2::RectD const & rect, m2::PointD const & pt)
void DrawWidget::ShowSearchResult(search::Result const & res)
{
m_framework->ShowRect(rect);
m_framework->DrawPlacemark(pt);
m_framework->ShowSearchResult(res);
UpdateScaleControl();
}

View file

@ -83,7 +83,7 @@ namespace qt
void SetScaleControl(QScaleSlider * pScale);
void Search(search::SearchParams params);
void ShowFeature(m2::RectD const & rect, m2::PointD const & pt);
void ShowSearchResult(search::Result const & res);
void CloseSearch();
void SaveState();

View file

@ -197,7 +197,7 @@ void SearchPanel::OnSearchPanelItemClicked(int row, int)
if (m_results[row].GetResultType() == ResultT::RESULT_FEATURE)
{
// center viewport on clicked item
m_pDrawWidget->ShowFeature(m_results[row].GetFeatureRect(), m_results[row].GetFeatureCenter());
m_pDrawWidget->ShowSearchResult(m_results[row]);
}
else
{