diff --git a/search/ftypes_matcher.cpp b/search/ftypes_matcher.cpp index fd31140231..abb0e1195c 100644 --- a/search/ftypes_matcher.cpp +++ b/search/ftypes_matcher.cpp @@ -111,4 +111,19 @@ Type IsLocalityChecker::GetLocalityType(const FeatureType & f) const return GetLocalityType(types); } +double GetLocationRadius(FeatureType const & ft) +{ + uint32_t population = ft.GetPopulation(); + + if (population < 10) + { + static IsLocalityChecker checker; + if (checker.GetLocalityType(ft) == CITY) + population = 10000; + /// @todo: process all cases of locality types + } + + return pow((double)population, 0.277778) * 550; +} + } diff --git a/search/ftypes_matcher.hpp b/search/ftypes_matcher.hpp index 6a44091f05..16dd222f75 100644 --- a/search/ftypes_matcher.hpp +++ b/search/ftypes_matcher.hpp @@ -49,4 +49,6 @@ public: Type GetLocalityType(FeatureType const & f) const; }; +/// Get city radius (meters) +double GetLocationRadius(FeatureType const & ft); } diff --git a/search/search_query.cpp b/search/search_query.cpp index f51f9f3ba7..6e25236f6d 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -1278,10 +1278,11 @@ namespace impl vector m_matchedTokens; ///< indexes of matched tokens for locality ftypes::Type m_type; + double m_radius; Locality() : m_type(ftypes::NONE) {} Locality(Query::TrieValueT const & val, ftypes::Type type) - : m_value(val), m_type(type) + : m_value(val), m_type(type), m_radius(0) { } @@ -1305,6 +1306,7 @@ namespace impl using std::swap; swap(m_value, rhs.m_value); swap(m_type, rhs.m_type); + swap(m_radius, rhs.m_radius); } bool operator< (Locality const & rhs) const @@ -1472,7 +1474,8 @@ void Query::SearchAddress(Results & res) { params.ProcessAddressTokens(); - SetViewportByIndex(mwmInfo, scales::GetRectForLevel(ADDRESS_SCALE, city.m_value.m_pt), LOCALITY_V); + m2::RectD const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(city.m_value.m_pt, city.m_radius); + SetViewportByIndex(mwmInfo, rect, LOCALITY_V); /// @todo Hack - do not search for address in World.mwm; Do it better in future. bool const b = m_worldSearch; @@ -1657,6 +1660,7 @@ namespace impl Locality * loc = PushLocality(Locality(v, index)); if (loc) { + loc->m_radius = ftypes::GetLocationRadius(f); // m_lang name should exist if we matched feature in search index for this language. VERIFY(f.GetName(m_lang, loc->m_name), ());