From 057f55fb515899ba39eb3334da0fc62232cf404d Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Fri, 11 Sep 2015 16:17:10 +0300 Subject: Added city rank table --- indexer/drawing_rules.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'indexer/drawing_rules.cpp') 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(&BaseRule::MakeEmptyID), _4)); @@ -441,12 +450,45 @@ void RulesHolder::LoadFromBinaryProto(string const & s) InitBackgroundColors(doSet.m_cont); } +void RulesHolder::LoadCityRankTableFromString(string & s) +{ + unique_ptr 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 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); } } -- cgit v1.2.3