From d97e8899ae2be618d5ad0f325a471428f8ebe8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 13 May 2014 18:41:22 +0200 Subject: [PATCH] add translate-anchor property --- include/llmr/style/properties.hpp | 7 +++++++ src/style/style.cpp | 1 + src/style/style_parser.cpp | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index 9a6d6d86d..22d5cf9cc 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -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&); @@ -121,6 +126,7 @@ struct FillProperties { struct TextClass { FunctionProperty enabled = true; std::array 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 translate = {{ 0, 0 }}; + TranslateAnchor translateAnchor = TranslateAnchor::Map; Color color = {{ 0, 0, 0, 1 }}; Color halo = {{ 1, 1, 1, 0.75 }}; float haloRadius = 0.25f; diff --git a/src/style/style.cpp b/src/style/style.cpp index a49311030..ecb86108e 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -97,6 +97,7 @@ void Style::cascade(float z) { text.enabled = layer.enabled.evaluate(z); text.translate = {{ layer.translate[0].evaluate(z), layer.translate[1].evaluate(z) }}; + text.translateAnchor = layer.translateAnchor; text.color = layer.color; text.size = layer.size.evaluate(z); text.halo = layer.halo; diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 081dedce1..9860f56c6 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -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 {{ values[0], values[1] }}; } + if (value.HasMember("translate-anchor")) { + klass.translateAnchor = parseTranslateAnchor(value["translate-anchor"]); + } + if (value.HasMember("color")) { klass.color = parseColor(value["color"]); }