diff options
Diffstat (limited to 'src/mbgl/style/layers/raster_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/raster_layer.cpp | 101 |
1 files changed, 61 insertions, 40 deletions
diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 97c67de299..3222eebd73 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -283,6 +283,8 @@ using namespace conversion; namespace { +constexpr uint8_t kPaintPropertyCount = 16u; + enum class Property : uint8_t { RasterBrightnessMax, RasterBrightnessMin, @@ -324,8 +326,66 @@ MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map< {"raster-opacity-transition", toUint8(Property::RasterOpacityTransition)}, {"raster-resampling-transition", toUint8(Property::RasterResamplingTransition)}, {"raster-saturation-transition", toUint8(Property::RasterSaturationTransition)}}); + +StyleProperty getLayerProperty(const RasterLayer& layer, Property property) { + switch (property) { + case Property::RasterBrightnessMax: + return makeStyleProperty(layer.getRasterBrightnessMax()); + case Property::RasterBrightnessMin: + return makeStyleProperty(layer.getRasterBrightnessMin()); + case Property::RasterContrast: + return makeStyleProperty(layer.getRasterContrast()); + case Property::RasterFadeDuration: + return makeStyleProperty(layer.getRasterFadeDuration()); + case Property::RasterHueRotate: + return makeStyleProperty(layer.getRasterHueRotate()); + case Property::RasterOpacity: + return makeStyleProperty(layer.getRasterOpacity()); + case Property::RasterResampling: + return makeStyleProperty(layer.getRasterResampling()); + case Property::RasterSaturation: + return makeStyleProperty(layer.getRasterSaturation()); + case Property::RasterBrightnessMaxTransition: + return makeStyleProperty(layer.getRasterBrightnessMaxTransition()); + case Property::RasterBrightnessMinTransition: + return makeStyleProperty(layer.getRasterBrightnessMinTransition()); + case Property::RasterContrastTransition: + return makeStyleProperty(layer.getRasterContrastTransition()); + case Property::RasterFadeDurationTransition: + return makeStyleProperty(layer.getRasterFadeDurationTransition()); + case Property::RasterHueRotateTransition: + return makeStyleProperty(layer.getRasterHueRotateTransition()); + case Property::RasterOpacityTransition: + return makeStyleProperty(layer.getRasterOpacityTransition()); + case Property::RasterResamplingTransition: + return makeStyleProperty(layer.getRasterResamplingTransition()); + case Property::RasterSaturationTransition: + return makeStyleProperty(layer.getRasterSaturationTransition()); + } + return {}; +} + +StyleProperty getLayerProperty(const RasterLayer& 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 RasterLayer::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> RasterLayer::setProperty(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { @@ -441,46 +501,7 @@ optional<Error> RasterLayer::setProperty(const std::string& name, const Converti } StyleProperty RasterLayer::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::RasterBrightnessMax: - return makeStyleProperty(getRasterBrightnessMax()); - case Property::RasterBrightnessMin: - return makeStyleProperty(getRasterBrightnessMin()); - case Property::RasterContrast: - return makeStyleProperty(getRasterContrast()); - case Property::RasterFadeDuration: - return makeStyleProperty(getRasterFadeDuration()); - case Property::RasterHueRotate: - return makeStyleProperty(getRasterHueRotate()); - case Property::RasterOpacity: - return makeStyleProperty(getRasterOpacity()); - case Property::RasterResampling: - return makeStyleProperty(getRasterResampling()); - case Property::RasterSaturation: - return makeStyleProperty(getRasterSaturation()); - case Property::RasterBrightnessMaxTransition: - return makeStyleProperty(getRasterBrightnessMaxTransition()); - case Property::RasterBrightnessMinTransition: - return makeStyleProperty(getRasterBrightnessMinTransition()); - case Property::RasterContrastTransition: - return makeStyleProperty(getRasterContrastTransition()); - case Property::RasterFadeDurationTransition: - return makeStyleProperty(getRasterFadeDurationTransition()); - case Property::RasterHueRotateTransition: - return makeStyleProperty(getRasterHueRotateTransition()); - case Property::RasterOpacityTransition: - return makeStyleProperty(getRasterOpacityTransition()); - case Property::RasterResamplingTransition: - return makeStyleProperty(getRasterResamplingTransition()); - case Property::RasterSaturationTransition: - return makeStyleProperty(getRasterSaturationTransition()); - } - return {}; + return getLayerProperty(*this, name); } Mutable<Layer::Impl> RasterLayer::mutableBaseImpl() const { |