diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 5ecc825f14..c32388e041 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -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 diff --git a/indexer/scales.hpp b/indexer/scales.hpp index b81c63a948..eb207071cb 100644 --- a/indexer/scales.hpp +++ b/indexer/scales.hpp @@ -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); diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index 7fa4232ec6..47a529789e 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -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; diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index 16e736f97e..02bdd2a81a 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -69,6 +69,21 @@ void FeaturesFetcher::ClearCaches() m_multiIndex.ClearCache(); } +bool FeaturesFetcher::IsCountryLoaded(m2::PointD const & pt) const +{ + vector 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()) diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index 43fa63b920..6edcad28f9 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -46,6 +46,8 @@ namespace model return m_multiIndex.IsLoaded(fName); } + bool IsCountryLoaded(m2::PointD const & pt) const; + /// @name Features enumeration. //@{ template diff --git a/map/framework.cpp b/map/framework.cpp index bcdb1058bf..e499436b80 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -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) diff --git a/map/framework.hpp b/map/framework.hpp index afe95673b2..323f9c6419 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -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); diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 771618beed..0bbec223d3 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -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(); } diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp index ad6d69d10f..b5c2adfd8e 100644 --- a/qt/draw_widget.hpp +++ b/qt/draw_widget.hpp @@ -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(); diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 7f26be3466..ed293c78c5 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -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 {