diff --git a/storage/country_info_getter.cpp b/storage/country_info_getter.cpp index 790797276c..eee3f07866 100644 --- a/storage/country_info_getter.cpp +++ b/storage/country_info_getter.cpp @@ -102,6 +102,14 @@ m2::RectD CountryInfoGetter::CalcLimitRect(string const & prefix) const return rect; } +m2::RectD CountryInfoGetter::CalcLimitRectForLeaf(TCountryId leafCountryId) const +{ + auto const index = this->m_countryIndex.find(leafCountryId); + ASSERT(index != this->m_countryIndex.end(), ()); + ASSERT_LESS(index->second, this->m_countries.size(), ()); + return m_countries[index->second].m_rect; +} + void CountryInfoGetter::GetMatchedRegions(string const & enNamePrefix, IdSet & regions) const { for (size_t i = 0; i < m_countries.size(); ++i) @@ -167,6 +175,11 @@ CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countr ReaderSource src(m_reader.GetReader(PACKED_POLYGONS_INFO_TAG)); rw::Read(src, m_countries); + size_t const countrySz = m_countries.size(); + m_countryIndex.reserve(countrySz); + for (size_t i = 0; i < countrySz; ++i) + m_countryIndex[m_countries[i].m_name] = i; + string buffer; countryR.ReadAsString(buffer); LoadCountryFile2CountryInfo(buffer, m_id2info, m_isSingleMwm); diff --git a/storage/country_info_getter.hpp b/storage/country_info_getter.hpp index 462f4289d6..f3d7835475 100644 --- a/storage/country_info_getter.hpp +++ b/storage/country_info_getter.hpp @@ -9,6 +9,7 @@ #include "base/cache.hpp" #include "std/mutex.hpp" +#include "std/unordered_map.hpp" namespace storage { @@ -52,6 +53,10 @@ public: // Calculates limit rect for all countries whose name starts with // |prefix|. m2::RectD CalcLimitRect(string const & prefix) const; + // Calculates limit rect for |countryId| (non-expandable node). + // Returns bound box in mercator coordinates if |countryId| is a country id of non-expandable node + // and zero rect otherwise. + m2::RectD CalcLimitRectForLeaf(TCountryId leafCountryId) const; // Returns identifiers for all regions matching to |enNamePrefix|. void GetMatchedRegions(string const & enNamePrefix, IdSet & regions) const; @@ -83,8 +88,12 @@ protected: // Returns true when |pt| belongs to a country identified by |id|. virtual bool IsBelongToRegionImpl(size_t id, m2::PointD const & pt) const = 0; + // @TODO(bykoianko) Probably it's possible to redesign the class to get rid of m_countryIndex. + // The possibility should be considered. // List of all known countries. vector m_countries; + // Maps all leaf country id (file names) to their index in m_countries. + unordered_map m_countryIndex; // Maps country file name without an extension to a country info. map m_id2info;