summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-08-08 15:09:27 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-08-23 19:01:40 +0300
commitfb5afd34b9b25e993a4b109385215eba0b83923f (patch)
tree61474b72e7d099808eb85ea60275e58da11bdd39 /src/mbgl/style/layers
parent52275f835a38897ebf1aeb2158ccfca2272e4770 (diff)
downloadqtlocation-mapboxgl-fb5afd34b9b25e993a4b109385215eba0b83923f.tar.gz
[core] Add `line-gradient` property
Porting of https://github.com/mapbox/mapbox-gl-js/pull/6303 See the link above for the description of the feature and its limitations). Based on patch from @lbud (Lauren Budorick).
Diffstat (limited to 'src/mbgl/style/layers')
-rw-r--r--src/mbgl/style/layers/line_layer.cpp56
-rw-r--r--src/mbgl/style/layers/line_layer_properties.hpp6
2 files changed, 61 insertions, 1 deletions
diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp
index 1b84c2d73e..1ddc690cc7 100644
--- a/src/mbgl/style/layers/line_layer.cpp
+++ b/src/mbgl/style/layers/line_layer.cpp
@@ -438,6 +438,33 @@ TransitionOptions LineLayer::getLinePatternTransition() const {
return impl().paint.template get<LinePattern>().options;
}
+ColorRampPropertyValue LineLayer::getDefaultLineGradient() {
+ return { {} };
+}
+
+ColorRampPropertyValue LineLayer::getLineGradient() const {
+ return impl().paint.template get<LineGradient>().value;
+}
+
+void LineLayer::setLineGradient(ColorRampPropertyValue value) {
+ if (value == getLineGradient())
+ return;
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<LineGradient>().value = value;
+ baseImpl = std::move(impl_);
+ observer->onLayerChanged(*this);
+}
+
+void LineLayer::setLineGradientTransition(const TransitionOptions& options) {
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<LineGradient>().options = options;
+ baseImpl = std::move(impl_);
+}
+
+TransitionOptions LineLayer::getLineGradientTransition() const {
+ return impl().paint.template get<LineGradient>().options;
+}
+
using namespace conversion;
optional<Error> LineLayer::setPaintProperty(const std::string& name, const Convertible& value) {
@@ -453,6 +480,7 @@ optional<Error> LineLayer::setPaintProperty(const std::string& name, const Conve
LineBlur,
LineDasharray,
LinePattern,
+ LineGradient,
LineOpacityTransition,
LineColorTransition,
LineTranslateTransition,
@@ -463,6 +491,7 @@ optional<Error> LineLayer::setPaintProperty(const std::string& name, const Conve
LineBlurTransition,
LineDasharrayTransition,
LinePatternTransition,
+ LineGradientTransition,
};
Property property = Property::Unknown;
@@ -567,6 +596,16 @@ optional<Error> LineLayer::setPaintProperty(const std::string& name, const Conve
property = Property::LinePatternTransition;
}
break;
+ case util::hashFNV1a("line-gradient"):
+ if (name == "line-gradient") {
+ property = Property::LineGradient;
+ }
+ break;
+ case util::hashFNV1a("line-gradient-transition"):
+ if (name == "line-gradient-transition") {
+ property = Property::LineGradientTransition;
+ }
+ break;
}
@@ -669,6 +708,18 @@ optional<Error> LineLayer::setPaintProperty(const std::string& name, const Conve
}
+ if (property == Property::LineGradient) {
+ Error error;
+ optional<ColorRampPropertyValue> typedValue = convert<ColorRampPropertyValue>(value, error, false, false);
+ if (!typedValue) {
+ return error;
+ }
+
+ setLineGradient(*typedValue);
+ return nullopt;
+
+ }
+
Error error;
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
@@ -726,6 +777,11 @@ optional<Error> LineLayer::setPaintProperty(const std::string& name, const Conve
return nullopt;
}
+ if (property == Property::LineGradientTransition) {
+ setLineGradientTransition(*transition);
+ return nullopt;
+ }
+
return Error { "layer doesn't support this property" };
}
diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp
index aeaf51698a..5fd349d38b 100644
--- a/src/mbgl/style/layers/line_layer_properties.hpp
+++ b/src/mbgl/style/layers/line_layer_properties.hpp
@@ -72,6 +72,9 @@ struct LinePattern : CrossFadedPaintProperty<std::string> {
static std::string defaultValue() { return ""; }
};
+struct LineGradient : ColorRampProperty {
+};
+
class LineLayoutProperties : public Properties<
LineCap,
LineJoin,
@@ -89,7 +92,8 @@ class LinePaintProperties : public Properties<
LineOffset,
LineBlur,
LineDasharray,
- LinePattern
+ LinePattern,
+ LineGradient
> {};
} // namespace style