diff options
Diffstat (limited to 'src/mbgl/style/layers/hillshade_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/hillshade_layer.cpp | 129 |
1 files changed, 84 insertions, 45 deletions
diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 710efe5844..a55c079c49 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -1,5 +1,3 @@ -// clang-format off - // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. #include <mbgl/style/layers/hillshade_layer.hpp> @@ -229,40 +227,49 @@ TransitionOptions HillshadeLayer::getHillshadeShadowColorTransition() const { using namespace conversion; +namespace { + +enum class Property : uint8_t { + HillshadeAccentColor, + HillshadeExaggeration, + HillshadeHighlightColor, + HillshadeIlluminationAnchor, + HillshadeIlluminationDirection, + HillshadeShadowColor, + HillshadeAccentColorTransition, + HillshadeExaggerationTransition, + HillshadeHighlightColorTransition, + HillshadeIlluminationAnchorTransition, + HillshadeIlluminationDirectionTransition, + HillshadeShadowColorTransition, +}; + +template <typename T> +constexpr uint8_t toUint8(T t) noexcept { + return uint8_t(mbgl::underlying_type(t)); +} + +MAPBOX_ETERNAL_CONSTEXPR const auto layerProperties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>( + {{"hillshade-accent-color", toUint8(Property::HillshadeAccentColor)}, + {"hillshade-exaggeration", toUint8(Property::HillshadeExaggeration)}, + {"hillshade-highlight-color", toUint8(Property::HillshadeHighlightColor)}, + {"hillshade-illumination-anchor", toUint8(Property::HillshadeIlluminationAnchor)}, + {"hillshade-illumination-direction", toUint8(Property::HillshadeIlluminationDirection)}, + {"hillshade-shadow-color", toUint8(Property::HillshadeShadowColor)}, + {"hillshade-accent-color-transition", toUint8(Property::HillshadeAccentColorTransition)}, + {"hillshade-exaggeration-transition", toUint8(Property::HillshadeExaggerationTransition)}, + {"hillshade-highlight-color-transition", toUint8(Property::HillshadeHighlightColorTransition)}, + {"hillshade-illumination-anchor-transition", toUint8(Property::HillshadeIlluminationAnchorTransition)}, + {"hillshade-illumination-direction-transition", toUint8(Property::HillshadeIlluminationDirectionTransition)}, + {"hillshade-shadow-color-transition", toUint8(Property::HillshadeShadowColorTransition)}}); + +constexpr uint8_t lastPaintPropertyIndex = toUint8(Property::HillshadeShadowColorTransition); +} // namespace + optional<Error> HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - HillshadeAccentColor, - HillshadeExaggeration, - HillshadeHighlightColor, - HillshadeIlluminationAnchor, - HillshadeIlluminationDirection, - HillshadeShadowColor, - HillshadeAccentColorTransition, - HillshadeExaggerationTransition, - HillshadeHighlightColorTransition, - HillshadeIlluminationAnchorTransition, - HillshadeIlluminationDirectionTransition, - HillshadeShadowColorTransition, - }; - - MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({ - { "hillshade-accent-color", mbgl::underlying_type(Property::HillshadeAccentColor) }, - { "hillshade-exaggeration", mbgl::underlying_type(Property::HillshadeExaggeration) }, - { "hillshade-highlight-color", mbgl::underlying_type(Property::HillshadeHighlightColor) }, - { "hillshade-illumination-anchor", mbgl::underlying_type(Property::HillshadeIlluminationAnchor) }, - { "hillshade-illumination-direction", mbgl::underlying_type(Property::HillshadeIlluminationDirection) }, - { "hillshade-shadow-color", mbgl::underlying_type(Property::HillshadeShadowColor) }, - { "hillshade-accent-color-transition", mbgl::underlying_type(Property::HillshadeAccentColorTransition) }, - { "hillshade-exaggeration-transition", mbgl::underlying_type(Property::HillshadeExaggerationTransition) }, - { "hillshade-highlight-color-transition", mbgl::underlying_type(Property::HillshadeHighlightColorTransition) }, - { "hillshade-illumination-anchor-transition", mbgl::underlying_type(Property::HillshadeIlluminationAnchorTransition) }, - { "hillshade-illumination-direction-transition", mbgl::underlying_type(Property::HillshadeIlluminationDirectionTransition) }, - { "hillshade-shadow-color-transition", mbgl::underlying_type(Property::HillshadeShadowColorTransition) } - }); - - const auto it = properties.find(name.c_str()); - if (it == properties.end()) { - return Error { "layer doesn't support this property" }; + const auto it = layerProperties.find(name.c_str()); + if (it == layerProperties.end() || it->second > lastPaintPropertyIndex) { + return Error{"layer doesn't support this property"}; } auto property = static_cast<Property>(it->second); @@ -329,39 +336,73 @@ optional<Error> HillshadeLayer::setPaintProperty(const std::string& name, const if (!transition) { return error; } - + if (property == Property::HillshadeAccentColorTransition) { setHillshadeAccentColorTransition(*transition); return nullopt; } - + if (property == Property::HillshadeExaggerationTransition) { setHillshadeExaggerationTransition(*transition); return nullopt; } - + if (property == Property::HillshadeHighlightColorTransition) { setHillshadeHighlightColorTransition(*transition); return nullopt; } - + if (property == Property::HillshadeIlluminationAnchorTransition) { setHillshadeIlluminationAnchorTransition(*transition); return nullopt; } - + if (property == Property::HillshadeIlluminationDirectionTransition) { setHillshadeIlluminationDirectionTransition(*transition); return nullopt; } - + if (property == Property::HillshadeShadowColorTransition) { setHillshadeShadowColorTransition(*transition); return nullopt; } - - return Error { "layer doesn't support this property" }; + return Error{"layer doesn't support this property"}; +} + +StyleProperty HillshadeLayer::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::HillshadeAccentColor: + return makeStyleProperty(getHillshadeAccentColor()); + case Property::HillshadeExaggeration: + return makeStyleProperty(getHillshadeExaggeration()); + case Property::HillshadeHighlightColor: + return makeStyleProperty(getHillshadeHighlightColor()); + case Property::HillshadeIlluminationAnchor: + return makeStyleProperty(getHillshadeIlluminationAnchor()); + case Property::HillshadeIlluminationDirection: + return makeStyleProperty(getHillshadeIlluminationDirection()); + case Property::HillshadeShadowColor: + return makeStyleProperty(getHillshadeShadowColor()); + case Property::HillshadeAccentColorTransition: + return makeStyleProperty(getHillshadeAccentColorTransition()); + case Property::HillshadeExaggerationTransition: + return makeStyleProperty(getHillshadeExaggerationTransition()); + case Property::HillshadeHighlightColorTransition: + return makeStyleProperty(getHillshadeHighlightColorTransition()); + case Property::HillshadeIlluminationAnchorTransition: + return makeStyleProperty(getHillshadeIlluminationAnchorTransition()); + case Property::HillshadeIlluminationDirectionTransition: + return makeStyleProperty(getHillshadeIlluminationDirectionTransition()); + case Property::HillshadeShadowColorTransition: + return makeStyleProperty(getHillshadeShadowColorTransition()); + } + return {}; } optional<Error> HillshadeLayer::setLayoutProperty(const std::string& name, const Convertible& value) { @@ -378,5 +419,3 @@ Mutable<Layer::Impl> HillshadeLayer::mutableBaseImpl() const { } // namespace style } // namespace mbgl - -// clang-format on |