diff options
Diffstat (limited to 'src/mbgl/style/layers/background_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 66ab46c078..f2e85ce7e7 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -3,6 +3,13 @@ #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/layers/background_layer_impl.hpp> #include <mbgl/style/layer_observer.hpp> +#include <mbgl/style/conversion/color_ramp_property_value.hpp> +#include <mbgl/style/conversion/constant.hpp> +#include <mbgl/style/conversion/property_value.hpp> +#include <mbgl/style/conversion/transition_options.hpp> +#include <mbgl/style/conversion/json.hpp> +#include <mbgl/style/conversion_impl.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -149,5 +156,143 @@ TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { return impl().paint.template get<BackgroundOpacity>().options; } +using namespace conversion; + +optional<Error> BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + BackgroundColor, + BackgroundPattern, + BackgroundOpacity, + BackgroundColorTransition, + BackgroundPatternTransition, + BackgroundOpacityTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("background-color"): + if (name == "background-color") { + property = Property::BackgroundColor; + } + break; + case util::hashFNV1a("background-color-transition"): + if (name == "background-color-transition") { + property = Property::BackgroundColorTransition; + } + break; + case util::hashFNV1a("background-pattern"): + if (name == "background-pattern") { + property = Property::BackgroundPattern; + } + break; + case util::hashFNV1a("background-pattern-transition"): + if (name == "background-pattern-transition") { + property = Property::BackgroundPatternTransition; + } + break; + case util::hashFNV1a("background-opacity"): + if (name == "background-opacity") { + property = Property::BackgroundOpacity; + } + break; + case util::hashFNV1a("background-opacity-transition"): + if (name == "background-opacity-transition") { + property = Property::BackgroundOpacityTransition; + } + break; + + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::BackgroundColor) { + Error error; + optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setBackgroundColor(*typedValue); + return nullopt; + + } + + if (property == Property::BackgroundPattern) { + Error error; + optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setBackgroundPattern(*typedValue); + return nullopt; + + } + + if (property == Property::BackgroundOpacity) { + Error error; + optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + if (!typedValue) { + return error; + } + + setBackgroundOpacity(*typedValue); + return nullopt; + + } + + + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::BackgroundColorTransition) { + setBackgroundColorTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundPatternTransition) { + setBackgroundPatternTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundOpacityTransition) { + setBackgroundOpacityTransition(*transition); + return nullopt; + } + + + return Error { "layer doesn't support this property" }; +} + +optional<Error> BackgroundLayer::setLayoutProperty(const std::string& name, const Convertible& value) { + if (name == "visibility") { + return Layer::setVisibility(value); + } + + enum class Property { + Unknown, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + + return Error { "layer doesn't support this property" }; +} + } // namespace style } // namespace mbgl |