diff options
Diffstat (limited to 'src/mbgl/style/layers/background_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 68b07cba3c..0b7f0afe4f 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -148,6 +148,8 @@ using namespace conversion; namespace { +constexpr uint8_t kPaintPropertyCount = 6u; + enum class Property : uint8_t { BackgroundColor, BackgroundOpacity, @@ -169,8 +171,46 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"background-color-transition", toUint8(Property::BackgroundColorTransition)}, {"background-opacity-transition", toUint8(Property::BackgroundOpacityTransition)}, {"background-pattern-transition", toUint8(Property::BackgroundPatternTransition)}}); + +StyleProperty getLayerProperty(const BackgroundLayer& layer, Property property) { + switch (property) { + case Property::BackgroundColor: + return makeStyleProperty(layer.getBackgroundColor()); + case Property::BackgroundOpacity: + return makeStyleProperty(layer.getBackgroundOpacity()); + case Property::BackgroundPattern: + return makeStyleProperty(layer.getBackgroundPattern()); + case Property::BackgroundColorTransition: + return makeStyleProperty(layer.getBackgroundColorTransition()); + case Property::BackgroundOpacityTransition: + return makeStyleProperty(layer.getBackgroundOpacityTransition()); + case Property::BackgroundPatternTransition: + return makeStyleProperty(layer.getBackgroundPatternTransition()); + } + return {}; +} + +StyleProperty getLayerProperty(const BackgroundLayer& layer, const std::string& name) { + const auto it = layerProperties.find(name.c_str()); + if (it == layerProperties.end()) { + return {}; + } + return getLayerProperty(layer, static_cast<Property>(it->second)); +} + } // namespace +Value BackgroundLayer::serialize() const { + auto result = Layer::serialize(); + assert(result.getObject()); + for (const auto& property : layerProperties) { + auto styleProperty = getLayerProperty(*this, static_cast<Property>(property.second)); + if (styleProperty.getKind() == StyleProperty::Kind::Undefined) continue; + serializeProperty(result, styleProperty, property.first.c_str(), property.second < kPaintPropertyCount); + } + return result; +} + optional<Error> BackgroundLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { @@ -236,26 +276,7 @@ optional<Error> BackgroundLayer::setProperty(const std::string& name, const Conv } StyleProperty BackgroundLayer::getProperty(const std::string& name) const { - const auto it = layerProperties.find(name.c_str()); - if (it == layerProperties.end()) { - return {}; - } - - switch (static_cast<Property>(it->second)) { - case Property::BackgroundColor: - return makeStyleProperty(getBackgroundColor()); - case Property::BackgroundOpacity: - return makeStyleProperty(getBackgroundOpacity()); - case Property::BackgroundPattern: - return makeStyleProperty(getBackgroundPattern()); - case Property::BackgroundColorTransition: - return makeStyleProperty(getBackgroundColorTransition()); - case Property::BackgroundOpacityTransition: - return makeStyleProperty(getBackgroundOpacityTransition()); - case Property::BackgroundPatternTransition: - return makeStyleProperty(getBackgroundPatternTransition()); - } - return {}; + return getLayerProperty(*this, name); } Mutable<Layer::Impl> BackgroundLayer::mutableBaseImpl() const { |