add translate-anchor property

This commit is contained in:
Konstantin Käfer
2014-05-13 18:41:22 +02:00
parent 05a330f347
commit d97e8899ae
3 changed files with 24 additions and 0 deletions

View File

@@ -31,6 +31,11 @@ enum class Property {
Linear = 4
};
enum class TranslateAnchor : uint8_t {
Map = 1,
Viewport = 2
};
namespace functions {
float null(float z, const std::vector<float>&);
@@ -121,6 +126,7 @@ struct FillProperties {
struct TextClass {
FunctionProperty enabled = true;
std::array<FunctionProperty, 2> translate = {{ 0, 0 }};
TranslateAnchor translateAnchor = TranslateAnchor::Map;
Color color = {{ 0, 0, 0, 1 }};
Color halo = {{ 1, 1, 1, 0.75 }};
FunctionProperty haloRadius = 0.25f;
@@ -133,6 +139,7 @@ struct TextClass {
struct TextProperties {
bool enabled = true;
std::array<float, 2> translate = {{ 0, 0 }};
TranslateAnchor translateAnchor = TranslateAnchor::Map;
Color color = {{ 0, 0, 0, 1 }};
Color halo = {{ 1, 1, 1, 0.75 }};
float haloRadius = 0.25f;

View File

@@ -97,6 +97,7 @@ void Style::cascade(float z) {
text.enabled = layer.enabled.evaluate<bool>(z);
text.translate = {{ layer.translate[0].evaluate<float>(z),
layer.translate[1].evaluate<float>(z) }};
text.translateAnchor = layer.translateAnchor;
text.color = layer.color;
text.size = layer.size.evaluate<float>(z);
text.halo = layer.halo;

View File

@@ -523,6 +523,18 @@ PointClass StyleParser::parsePointClass(JSVal value) {
return klass;
}
TranslateAnchor parseTranslateAnchor(JSVal anchor) {
if (anchor.IsString()) {
std::string a { anchor.GetString(), anchor.GetStringLength() };
if (a == "viewport") {
return TranslateAnchor::Viewport;
} else {
return TranslateAnchor::Map;
}
} else {
throw Style::exception("translate anchor must be a string");
}
}
TextClass StyleParser::parseTextClass(JSVal value) {
TextClass klass;
@@ -536,6 +548,10 @@ TextClass StyleParser::parseTextClass(JSVal value) {
klass.translate = std::array<FunctionProperty, 2> {{ values[0], values[1] }};
}
if (value.HasMember("translate-anchor")) {
klass.translateAnchor = parseTranslateAnchor(value["translate-anchor"]);
}
if (value.HasMember("color")) {
klass.color = parseColor(value["color"]);
}