diff options
Diffstat (limited to 'src/mbgl/style/layers/hillshade_layer.cpp')
-rw-r--r-- | src/mbgl/style/layers/hillshade_layer.cpp | 106 |
1 files changed, 22 insertions, 84 deletions
diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 0ae63b18c6..49d3217a3b 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -9,7 +9,8 @@ #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> + +#include <mapbox/eternal.hpp> namespace mbgl { namespace style { @@ -226,8 +227,7 @@ TransitionOptions HillshadeLayer::getHillshadeAccentColorTransition() const { using namespace conversion; optional<Error> HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { HillshadeIlluminationDirection, HillshadeIlluminationAnchor, HillshadeExaggeration, @@ -242,75 +242,28 @@ optional<Error> HillshadeLayer::setPaintProperty(const std::string& name, const HillshadeAccentColorTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("hillshade-illumination-direction"): - if (name == "hillshade-illumination-direction") { - property = Property::HillshadeIlluminationDirection; - } - break; - case util::hashFNV1a("hillshade-illumination-direction-transition"): - if (name == "hillshade-illumination-direction-transition") { - property = Property::HillshadeIlluminationDirectionTransition; - } - break; - case util::hashFNV1a("hillshade-illumination-anchor"): - if (name == "hillshade-illumination-anchor") { - property = Property::HillshadeIlluminationAnchor; - } - break; - case util::hashFNV1a("hillshade-illumination-anchor-transition"): - if (name == "hillshade-illumination-anchor-transition") { - property = Property::HillshadeIlluminationAnchorTransition; - } - break; - case util::hashFNV1a("hillshade-exaggeration"): - if (name == "hillshade-exaggeration") { - property = Property::HillshadeExaggeration; - } - break; - case util::hashFNV1a("hillshade-exaggeration-transition"): - if (name == "hillshade-exaggeration-transition") { - property = Property::HillshadeExaggerationTransition; - } - break; - case util::hashFNV1a("hillshade-shadow-color"): - if (name == "hillshade-shadow-color") { - property = Property::HillshadeShadowColor; - } - break; - case util::hashFNV1a("hillshade-shadow-color-transition"): - if (name == "hillshade-shadow-color-transition") { - property = Property::HillshadeShadowColorTransition; - } - break; - case util::hashFNV1a("hillshade-highlight-color"): - if (name == "hillshade-highlight-color") { - property = Property::HillshadeHighlightColor; - } - break; - case util::hashFNV1a("hillshade-highlight-color-transition"): - if (name == "hillshade-highlight-color-transition") { - property = Property::HillshadeHighlightColorTransition; - } - break; - case util::hashFNV1a("hillshade-accent-color"): - if (name == "hillshade-accent-color") { - property = Property::HillshadeAccentColor; - } - break; - case util::hashFNV1a("hillshade-accent-color-transition"): - if (name == "hillshade-accent-color-transition") { - property = Property::HillshadeAccentColorTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>({ + { "hillshade-illumination-direction", static_cast<uint8_t>(Property::HillshadeIlluminationDirection) }, + { "hillshade-illumination-anchor", static_cast<uint8_t>(Property::HillshadeIlluminationAnchor) }, + { "hillshade-exaggeration", static_cast<uint8_t>(Property::HillshadeExaggeration) }, + { "hillshade-shadow-color", static_cast<uint8_t>(Property::HillshadeShadowColor) }, + { "hillshade-highlight-color", static_cast<uint8_t>(Property::HillshadeHighlightColor) }, + { "hillshade-accent-color", static_cast<uint8_t>(Property::HillshadeAccentColor) }, + { "hillshade-illumination-direction-transition", static_cast<uint8_t>(Property::HillshadeIlluminationDirectionTransition) }, + { "hillshade-illumination-anchor-transition", static_cast<uint8_t>(Property::HillshadeIlluminationAnchorTransition) }, + { "hillshade-exaggeration-transition", static_cast<uint8_t>(Property::HillshadeExaggerationTransition) }, + { "hillshade-shadow-color-transition", static_cast<uint8_t>(Property::HillshadeShadowColorTransition) }, + { "hillshade-highlight-color-transition", static_cast<uint8_t>(Property::HillshadeHighlightColorTransition) }, + { "hillshade-accent-color-transition", static_cast<uint8_t>(Property::HillshadeAccentColorTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast<Property>(it->second); + if (property == Property::HillshadeIlluminationDirection || property == Property::HillshadeExaggeration) { Error error; @@ -413,21 +366,6 @@ optional<Error> HillshadeLayer::setLayoutProperty(const std::string& name, const 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" }; } |