Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Shalnev <c.shalnev@corp.mail.ru>2015-08-19 13:48:15 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:01:54 +0300
commit487a28e33e7f2f4f4f26aeaffcdac379bfd0078b (patch)
tree32718246cf87e07ccdd76a58783035d0c8f6d39d /indexer
parent60952b43503ec79bb5e51e9a7cae8151bd84a162 (diff)
Use natural-land as background color for specified scales
Diffstat (limited to 'indexer')
-rw-r--r--indexer/drawing_rules.cpp73
-rw-r--r--indexer/drawing_rules.hpp9
2 files changed, 52 insertions, 30 deletions
diff --git a/indexer/drawing_rules.cpp b/indexer/drawing_rules.cpp
index 35ad7de737..fa78019104 100644
--- a/indexer/drawing_rules.cpp
+++ b/indexer/drawing_rules.cpp
@@ -12,6 +12,7 @@
#include "std/bind.hpp"
#include "std/iterator_facade.hpp"
+#include "std/unordered_map.hpp"
#include <google/protobuf/text_format.h>
@@ -84,7 +85,7 @@ CircleRuleProto const * BaseRule::GetCircle() const
}
RulesHolder::RulesHolder()
- : m_bgColor(DEFAULT_BG_COLOR)
+ : m_bgColors(scales::UPPER_STYLE_SCALE+1, DEFAULT_BG_COLOR)
{}
RulesHolder::~RulesHolder()
@@ -135,9 +136,11 @@ BaseRule const * RulesHolder::Find(Key const & k) const
return 0;
}
-uint32_t RulesHolder::GetBgColor() const
+uint32_t RulesHolder::GetBgColor(int scale) const
{
- return m_bgColor;
+ ASSERT_LESS(scale, m_bgColors.size(), ());
+ ASSERT_GREATER_OR_EQUAL(scale, 0, ());
+ return m_bgColors[scale];
}
void RulesHolder::ClearCaches()
@@ -355,42 +358,56 @@ namespace
m_names.pop_back();
}
};
+}
- uint32_t GetBackgroundColor(ContainerProto const & cont)
- {
- // WARNING!
- // Background color is not specified in current format.
- // Therefore, we use color of "natural-land" area element as background color.
- // If such element is not present or if the element is not area then we use default background color
+void RulesHolder::InitBackgroundColors(ContainerProto const & cont)
+{
+ // WARNING!
+ // Background color is not specified in current format.
+ // Therefore, we use color of "natural-land" area element as background color.
+ // If such element is not present or if the element is not area then we use default background color
- uint32_t backgroundColor = DEFAULT_BG_COLOR;
+ // Default background color is any found color, it is used if color is not specified for scale
+ uint32_t bgColorDefault = DEFAULT_BG_COLOR;
- // Find the "natural-land" classification element
- for (int i = 0; i < cont.cont_size(); ++i)
+ // Background colors specified for scales
+ unordered_map<int, uint32_t> bgColorForScale;
+
+ // Find the "natural-land" classification element
+ for (int i = 0; i < cont.cont_size(); ++i)
+ {
+ ClassifElementProto const & ce = cont.cont(i);
+ if (ce.name() == "natural-land")
{
- ClassifElementProto const & ce = cont.cont(i);
- if (ce.name() == "natural-land")
+ // Take any area draw element
+ for (int j = 0; j < ce.element_size(); ++j)
{
- // Take any area draw element
- for (int j = 0; j < ce.element_size(); ++j)
+ DrawElementProto const & de = ce.element(j);
+ if (de.has_area())
{
- DrawElementProto const & de = ce.element(j);
- if (de.has_area())
+ // Take the color of the draw element
+ AreaRuleProto const & rule = de.area();
+ if (rule.has_color())
{
- // Take the color of the draw element
- AreaRuleProto const & rule = de.area();
- if (rule.has_color())
- {
- backgroundColor = rule.color();
- break;
- }
+ bgColorDefault = rule.color();
+
+ if (de.has_scale())
+ bgColorForScale.insert(make_pair(de.scale(), rule.color()));
}
}
- break;
}
+ break;
}
+ }
- return backgroundColor;
+ ASSERT_EQUAL(m_bgColors.size(), scales::UPPER_STYLE_SCALE+1, ());
+ for (int scale = 0; scale <= scales::UPPER_STYLE_SCALE; ++scale)
+ {
+ auto const i = bgColorForScale.find(scale);
+ if (bgColorForScale.end() != i)
+ m_bgColors[scale] = i->second;
+ else
+ m_bgColors[scale] = bgColorDefault;
}
}
@@ -404,7 +421,7 @@ void RulesHolder::LoadFromBinaryProto(string const & s)
classif().GetMutableRoot()->ForEachObject(ref(doSet));
- m_bgColor = GetBackgroundColor(doSet.m_cont);
+ InitBackgroundColors(doSet.m_cont);
}
void LoadRules()
diff --git a/indexer/drawing_rules.hpp b/indexer/drawing_rules.hpp
index 57b0aa0e6e..a72b764f99 100644
--- a/indexer/drawing_rules.hpp
+++ b/indexer/drawing_rules.hpp
@@ -17,6 +17,7 @@ class AreaRuleProto;
class SymbolRuleProto;
class CaptionDefProto;
class CircleRuleProto;
+class ContainerProto;
namespace drule
@@ -60,7 +61,8 @@ namespace drule
typedef map<int32_t, array<vector<uint32_t>, count_of_rules> > rules_map_t;
rules_map_t m_rules;
- uint32_t m_bgColor;
+ /// background color for scales in range [0...scales::UPPER_STYLE_SCALE]
+ vector<uint32_t> m_bgColors;
public:
RulesHolder();
@@ -75,7 +77,7 @@ namespace drule
BaseRule const * Find(Key const & k) const;
- uint32_t GetBgColor() const;
+ uint32_t GetBgColor(int scale = 0) const;
#ifdef OMIM_OS_DESKTOP
void LoadFromTextProto(string const & buffer);
@@ -99,6 +101,9 @@ namespace drule
}
}
}
+
+ private:
+ void InitBackgroundColors(ContainerProto const & cp);
};
RulesHolder & rules();