diff options
author | Constantin Shalnev <c.shalnev@corp.mail.ru> | 2015-09-11 16:17:10 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:04:57 +0300 |
commit | 057f55fb515899ba39eb3334da0fc62232cf404d (patch) | |
tree | 3e9486684775c1a5ba857d9168e40e93725cd51e /indexer/drawing_rules.cpp | |
parent | ad8154bac4539ef5921af1cc3f94af8f538c2a9f (diff) |
Added city rank table
Diffstat (limited to 'indexer/drawing_rules.cpp')
-rw-r--r-- | indexer/drawing_rules.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp index 3dd98076af..a825971743 100644 --- a/indexer/drawing_rules.cpp +++ b/indexer/drawing_rules.cpp @@ -91,6 +91,7 @@ ShieldRuleProto const * BaseRule::GetShield() const RulesHolder::RulesHolder() : m_bgColors(scales::UPPER_STYLE_SCALE+1, DEFAULT_BG_COLOR) + , m_cityRankTable(GetConstRankCityRankTable()) {} RulesHolder::~RulesHolder() @@ -148,6 +149,14 @@ uint32_t RulesHolder::GetBgColor(int scale) const return m_bgColors[scale]; } +double RulesHolder::GetCityRank(int scale, uint32_t population) const +{ + double rank; + if (!m_cityRankTable->GetCityRank(scale, population, rank)) + return -1.0; // do not draw + return rank; +} + void RulesHolder::ClearCaches() { ForEachRule(bind(static_cast<void (BaseRule::*)()>(&BaseRule::MakeEmptyID), _4)); @@ -441,12 +450,45 @@ void RulesHolder::LoadFromBinaryProto(string const & s) InitBackgroundColors(doSet.m_cont); } +void RulesHolder::LoadCityRankTableFromString(string & s) +{ + unique_ptr<ICityRankTable> table; + + if (!s.empty()) + { + table = GetCityRankTableFromString(s); + + if (nullptr == table) + LOG(LINFO, ("Invalid city-rank-table file")); + } + + if (nullptr == table) + table = GetConstRankCityRankTable(); + + m_cityRankTable = move(table); +} + void LoadRules() { string buffer; - GetStyleReader().GetDrawingRulesReader().ReadAsString(buffer); + // Load drules_proto + GetStyleReader().GetDrawingRulesReader().ReadAsString(buffer); rules().LoadFromBinaryProto(buffer); + + // Load city_rank + buffer.clear(); + try + { + ReaderPtr<Reader> cityRankFileReader = GetPlatform().GetReader("city_rank.txt"); + cityRankFileReader.ReadAsString(buffer); + } + catch (FileAbsentException & e) + { + // city-rank.txt file is optional, if it does not exist, then default city-rank-table is used + LOG(LINFO, ("File city-rank-table does not exist", e.Msg())); + } + rules().LoadCityRankTableFromString(buffer); } } |