diff options
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_line.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/style/property_fallback.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/property_key.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/property_value.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/style/style_layer.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/style/style_properties.hpp | 3 |
9 files changed, 32 insertions, 17 deletions
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 28ab0ba456..ae5617bf36 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -17,7 +17,7 @@ LineAtlas::LineAtlas(uint16_t w, uint16_t h) LineAtlas::~LineAtlas() { } -LinePatternPos LineAtlas::getDashPosition(std::vector<float> &dasharray, bool round) { +LinePatternPos LineAtlas::getDashPosition(const std::vector<float> &dasharray, bool round) { std::ostringstream sskey; for (const float &part : dasharray) { @@ -34,7 +34,7 @@ LinePatternPos LineAtlas::getDashPosition(std::vector<float> &dasharray, bool ro return positions[key]; } -LinePatternPos LineAtlas::addDash(std::vector<float> &dasharray, bool round) { +LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool round) { int n = round ? 7 : 0; int dashheight = 2 * n + 1; diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 6e4d8ab5b8..800c047dc8 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -21,8 +21,8 @@ public: void bind(); - LinePatternPos getDashPosition(std::vector<float>&, bool); - LinePatternPos addDash(std::vector<float> &dasharray, bool round); + LinePatternPos getDashPosition(const std::vector<float>&, bool); + LinePatternPos addDash(const std::vector<float> &dasharray, bool round); const int width; const int height; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 654d891d32..0aadd9219d 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -70,7 +70,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c bucket.drawPoints(*linejoinShader); } - if (properties.dash_array.size() && properties.dash_array[1] > 0) { + if (properties.dash_array.size()) { useProgram(linesdfShader->program); @@ -81,8 +81,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c linesdfShader->u_blur = blur; linesdfShader->u_color = color; - std::vector<float> dash = { properties.dash_array[0], properties.dash_array[1] }; - LinePatternPos pos = lineAtlas.getDashPosition(dash, false); + LinePatternPos pos = lineAtlas.getDashPosition(properties.dash_array, false); lineAtlas.bind(); float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0; diff --git a/src/mbgl/style/property_fallback.cpp b/src/mbgl/style/property_fallback.cpp index 965baf6c4b..dc747b37e6 100644 --- a/src/mbgl/style/property_fallback.cpp +++ b/src/mbgl/style/property_fallback.cpp @@ -20,8 +20,6 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = { { PropertyKey::LineWidth, defaultStyleProperties<LineProperties>().width }, { PropertyKey::LineGapWidth, defaultStyleProperties<LineProperties>().gap_width }, { PropertyKey::LineBlur, defaultStyleProperties<LineProperties>().blur }, - { PropertyKey::LineDashLand, defaultStyleProperties<LineProperties>().dash_array[0] }, - { PropertyKey::LineDashGap, defaultStyleProperties<LineProperties>().dash_array[1] }, { PropertyKey::IconOpacity, defaultStyleProperties<SymbolProperties>().icon.opacity }, { PropertyKey::IconRotate, defaultStyleProperties<SymbolProperties>().icon.rotate }, diff --git a/src/mbgl/style/property_key.hpp b/src/mbgl/style/property_key.hpp index efeebf0242..e283f11579 100644 --- a/src/mbgl/style/property_key.hpp +++ b/src/mbgl/style/property_key.hpp @@ -24,8 +24,6 @@ enum class PropertyKey { LineGapWidth, LineBlur, LineDashArray, // for transitions only - LineDashLand, - LineDashGap, LineImage, IconOpacity, diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index 1b22b31177..b6ebcf3f69 100644 --- a/src/mbgl/style/property_value.hpp +++ b/src/mbgl/style/property_value.hpp @@ -5,6 +5,8 @@ #include <mbgl/style/function_properties.hpp> #include <mbgl/style/types.hpp> +#include <vector> + namespace mbgl { typedef mapbox::util::variant< @@ -13,7 +15,8 @@ typedef mapbox::util::variant< RotateAnchorType, Function<bool>, Function<float>, - Function<Color> + Function<Color>, + std::vector<float> > PropertyValue; } diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index 024ac2f2c6..54dfff3004 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -185,8 +185,7 @@ void StyleLayer::applyStyleProperties<LineProperties>(const float z, const times applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now); applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now); applyTransitionedStyleProperty(PropertyKey::LineBlur, line.blur, z, now); - applyTransitionedStyleProperty(PropertyKey::LineDashLand, line.dash_array[0], z, now); - applyTransitionedStyleProperty(PropertyKey::LineDashGap, line.dash_array[1], z, now); + applyStyleProperty(PropertyKey::LineDashArray, line.dash_array, z, now); applyStyleProperty(PropertyKey::LineImage, line.image, z, now); // for scaling dasharrays diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 928392a8dd..b000fd5b5d 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -332,6 +332,24 @@ template<> std::tuple<bool, std::string> StyleParser::parseProperty(JSVal value, return std::tuple<bool, std::string> { true, { value.GetString(), value.GetStringLength() } }; } +template<> std::tuple<bool, std::vector<float>> StyleParser::parseProperty(JSVal value, const char *property_name) { + if (!value.IsArray()) { + Log::Warning(Event::ParseStyle, "value of '%s' must be an array", property_name); + return std::tuple<bool, std::vector<float>> { false, std::vector<float>() }; + } + + std::vector<float> vec; + for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { + JSVal part = value[i]; + if (!part.IsNumber()) { + Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers", property_name); + return std::tuple<bool, std::vector<float>> { false, std::vector<float>() }; + } + vec.push_back(part.GetDouble()); + } + return std::tuple<bool, std::vector<float>> { true, vec }; +} + template<> std::tuple<bool, TranslateAnchorType> StyleParser::parseProperty(JSVal value, const char *property_name) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name); @@ -567,8 +585,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty<PropertyTransition>("line-gap-width-transition", Key::LineGapWidth, klass, value); parseOptionalProperty<Function<float>>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty<PropertyTransition>("line-blur-transition", Key::LineBlur, klass, value); - parseOptionalProperty<Function<float>>("line-dasharray", { Key::LineDashLand, Key::LineDashGap }, klass, value); - parseOptionalProperty<PropertyTransition>("line-dasharray-transition", Key::LineDashArray, klass, value); + parseOptionalProperty<std::vector<float>>("line-dasharray", Key::LineDashArray, klass, value); parseOptionalProperty<std::string>("line-image", Key::LineImage, klass, value); parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value); diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp index e50cd87d3f..c5149b2d1c 100644 --- a/src/mbgl/style/style_properties.hpp +++ b/src/mbgl/style/style_properties.hpp @@ -9,6 +9,7 @@ #include <string> #include <type_traits> #include <memory> +#include <vector> namespace mbgl { @@ -36,7 +37,7 @@ struct LineProperties { float width = 1; float gap_width = 0; float blur = 0; - std::array<float, 2> dash_array = {{ 1, -1 }}; + std::vector<float> dash_array; float dash_line_width = 1; std::string image; |