diff options
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/style/layers/background_layer.cpp | 124 | ||||
-rw-r--r-- | src/mbgl/style/layers/circle_layer.cpp | 405 | ||||
-rw-r--r-- | src/mbgl/style/layers/fill_extrusion_layer.cpp | 257 | ||||
-rw-r--r-- | src/mbgl/style/layers/fill_layer.cpp | 261 | ||||
-rw-r--r-- | src/mbgl/style/layers/heatmap_layer.cpp | 202 | ||||
-rw-r--r-- | src/mbgl/style/layers/heatmap_layer_properties.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/style/layers/hillshade_layer.cpp | 237 | ||||
-rw-r--r-- | src/mbgl/style/layers/layer.cpp.ejs | 125 | ||||
-rw-r--r-- | src/mbgl/style/layers/layer_properties.hpp.ejs | 3 | ||||
-rw-r--r-- | src/mbgl/style/layers/line_layer.cpp | 423 | ||||
-rw-r--r-- | src/mbgl/style/layers/raster_layer.cpp | 308 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer.cpp | 1193 | ||||
-rw-r--r-- | src/mbgl/util/fnv_hash.hpp | 11 |
13 files changed, 2260 insertions, 1292 deletions
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 837d557722..88e175cb7c 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -158,70 +159,115 @@ TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { 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 (name == "background-color") { + } + + 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 (name == "background-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setBackgroundColorTransition(*transition); - return nullopt; + } - if (name == "background-pattern") { + 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 (name == "background-pattern-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setBackgroundPatternTransition(*transition); - return nullopt; + } - if (name == "background-opacity") { + 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; + } - if (name == "background-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + + 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" }; } @@ -242,7 +288,21 @@ optional<Error> BackgroundLayer::setLayoutProperty(const std::string& name, cons return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index 3f769e935c..eb3227da37 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -402,238 +403,316 @@ TransitionOptions CircleLayer::getCircleStrokeOpacityTransition() const { using namespace conversion; optional<Error> CircleLayer::setPaintProperty(const std::string& name, const Convertible& value) { - - if (name == "circle-radius") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + enum class Property { + Unknown, + CircleRadius, + CircleColor, + CircleBlur, + CircleOpacity, + CircleTranslate, + CircleTranslateAnchor, + CirclePitchScale, + CirclePitchAlignment, + CircleStrokeWidth, + CircleStrokeColor, + CircleStrokeOpacity, + CircleRadiusTransition, + CircleColorTransition, + CircleBlurTransition, + CircleOpacityTransition, + CircleTranslateTransition, + CircleTranslateAnchorTransition, + CirclePitchScaleTransition, + CirclePitchAlignmentTransition, + CircleStrokeWidthTransition, + CircleStrokeColorTransition, + CircleStrokeOpacityTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("circle-radius"): + if (name == "circle-radius") { + property = Property::CircleRadius; } - - setCircleRadius(*typedValue); - return nullopt; - } - if (name == "circle-radius-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + break; + case util::hashFNV1a("circle-radius-transition"): + if (name == "circle-radius-transition") { + property = Property::CircleRadiusTransition; } - - setCircleRadiusTransition(*transition); - return nullopt; - } - - if (name == "circle-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); - if (!typedValue) { - return error; + break; + case util::hashFNV1a("circle-color"): + if (name == "circle-color") { + property = Property::CircleColor; } - - setCircleColor(*typedValue); - return nullopt; - } - if (name == "circle-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + break; + case util::hashFNV1a("circle-color-transition"): + if (name == "circle-color-transition") { + property = Property::CircleColorTransition; + } + break; + case util::hashFNV1a("circle-blur"): + if (name == "circle-blur") { + property = Property::CircleBlur; + } + break; + case util::hashFNV1a("circle-blur-transition"): + if (name == "circle-blur-transition") { + property = Property::CircleBlurTransition; + } + break; + case util::hashFNV1a("circle-opacity"): + if (name == "circle-opacity") { + property = Property::CircleOpacity; + } + break; + case util::hashFNV1a("circle-opacity-transition"): + if (name == "circle-opacity-transition") { + property = Property::CircleOpacityTransition; + } + break; + case util::hashFNV1a("circle-translate"): + if (name == "circle-translate") { + property = Property::CircleTranslate; + } + break; + case util::hashFNV1a("circle-translate-transition"): + if (name == "circle-translate-transition") { + property = Property::CircleTranslateTransition; + } + break; + case util::hashFNV1a("circle-translate-anchor"): + if (name == "circle-translate-anchor") { + property = Property::CircleTranslateAnchor; + } + break; + case util::hashFNV1a("circle-translate-anchor-transition"): + if (name == "circle-translate-anchor-transition") { + property = Property::CircleTranslateAnchorTransition; + } + break; + case util::hashFNV1a("circle-pitch-scale"): + if (name == "circle-pitch-scale") { + property = Property::CirclePitchScale; } + break; + case util::hashFNV1a("circle-pitch-scale-transition"): + if (name == "circle-pitch-scale-transition") { + property = Property::CirclePitchScaleTransition; + } + break; + case util::hashFNV1a("circle-pitch-alignment"): + if (name == "circle-pitch-alignment") { + property = Property::CirclePitchAlignment; + } + break; + case util::hashFNV1a("circle-pitch-alignment-transition"): + if (name == "circle-pitch-alignment-transition") { + property = Property::CirclePitchAlignmentTransition; + } + break; + case util::hashFNV1a("circle-stroke-width"): + if (name == "circle-stroke-width") { + property = Property::CircleStrokeWidth; + } + break; + case util::hashFNV1a("circle-stroke-width-transition"): + if (name == "circle-stroke-width-transition") { + property = Property::CircleStrokeWidthTransition; + } + break; + case util::hashFNV1a("circle-stroke-color"): + if (name == "circle-stroke-color") { + property = Property::CircleStrokeColor; + } + break; + case util::hashFNV1a("circle-stroke-color-transition"): + if (name == "circle-stroke-color-transition") { + property = Property::CircleStrokeColorTransition; + } + break; + case util::hashFNV1a("circle-stroke-opacity"): + if (name == "circle-stroke-opacity") { + property = Property::CircleStrokeOpacity; + } + break; + case util::hashFNV1a("circle-stroke-opacity-transition"): + if (name == "circle-stroke-opacity-transition") { + property = Property::CircleStrokeOpacityTransition; + } + break; + + } - setCircleColorTransition(*transition); - return nullopt; + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; } - - if (name == "circle-blur") { + + + if (property == Property::CircleRadius || property == Property::CircleBlur || property == Property::CircleOpacity || property == Property::CircleStrokeWidth || property == Property::CircleStrokeOpacity) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - - setCircleBlur(*typedValue); - return nullopt; - } - if (name == "circle-blur-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::CircleRadius) { + setCircleRadius(*typedValue); + return nullopt; } - - setCircleBlurTransition(*transition); - return nullopt; + + if (property == Property::CircleBlur) { + setCircleBlur(*typedValue); + return nullopt; + } + + if (property == Property::CircleOpacity) { + setCircleOpacity(*typedValue); + return nullopt; + } + + if (property == Property::CircleStrokeWidth) { + setCircleStrokeWidth(*typedValue); + return nullopt; + } + + if (property == Property::CircleStrokeOpacity) { + setCircleStrokeOpacity(*typedValue); + return nullopt; + } + } - if (name == "circle-opacity") { + if (property == Property::CircleColor || property == Property::CircleStrokeColor) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); if (!typedValue) { return error; } - - setCircleOpacity(*typedValue); - return nullopt; - } - if (name == "circle-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::CircleColor) { + setCircleColor(*typedValue); + return nullopt; } - - setCircleOpacityTransition(*transition); - return nullopt; + + if (property == Property::CircleStrokeColor) { + setCircleStrokeColor(*typedValue); + return nullopt; + } + } - if (name == "circle-translate") { + if (property == Property::CircleTranslate) { Error error; optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslate(*typedValue); return nullopt; - } - if (name == "circle-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setCircleTranslateTransition(*transition); - return nullopt; + } - if (name == "circle-translate-anchor") { + if (property == Property::CircleTranslateAnchor) { Error error; optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslateAnchor(*typedValue); return nullopt; - } - if (name == "circle-translate-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setCircleTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "circle-pitch-scale") { + if (property == Property::CirclePitchScale) { Error error; optional<PropertyValue<CirclePitchScaleType>> typedValue = convert<PropertyValue<CirclePitchScaleType>>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchScale(*typedValue); return nullopt; - } - if (name == "circle-pitch-scale-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setCirclePitchScaleTransition(*transition); - return nullopt; + } - if (name == "circle-pitch-alignment") { + if (property == Property::CirclePitchAlignment) { Error error; optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchAlignment(*typedValue); return nullopt; + } - if (name == "circle-pitch-alignment-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + - setCirclePitchAlignmentTransition(*transition); + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::CircleRadiusTransition) { + setCircleRadiusTransition(*transition); return nullopt; } - if (name == "circle-stroke-width") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeWidth(*typedValue); + if (property == Property::CircleColorTransition) { + setCircleColorTransition(*transition); return nullopt; } - if (name == "circle-stroke-width-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setCircleStrokeWidthTransition(*transition); + + if (property == Property::CircleBlurTransition) { + setCircleBlurTransition(*transition); return nullopt; } - if (name == "circle-stroke-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeColor(*typedValue); + if (property == Property::CircleOpacityTransition) { + setCircleOpacityTransition(*transition); return nullopt; } - if (name == "circle-stroke-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setCircleStrokeColorTransition(*transition); + + if (property == Property::CircleTranslateTransition) { + setCircleTranslateTransition(*transition); return nullopt; } - if (name == "circle-stroke-opacity") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeOpacity(*typedValue); + if (property == Property::CircleTranslateAnchorTransition) { + setCircleTranslateAnchorTransition(*transition); return nullopt; } - if (name == "circle-stroke-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::CirclePitchScaleTransition) { + setCirclePitchScaleTransition(*transition); + return nullopt; + } + + if (property == Property::CirclePitchAlignmentTransition) { + setCirclePitchAlignmentTransition(*transition); + return nullopt; + } + + if (property == Property::CircleStrokeWidthTransition) { + setCircleStrokeWidthTransition(*transition); + return nullopt; + } + + if (property == Property::CircleStrokeColorTransition) { + setCircleStrokeColorTransition(*transition); + return nullopt; + } + + if (property == Property::CircleStrokeOpacityTransition) { setCircleStrokeOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -654,7 +733,21 @@ optional<Error> CircleLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index b48e51c566..33f5bbe87c 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -294,154 +295,226 @@ TransitionOptions FillExtrusionLayer::getFillExtrusionBaseTransition() const { using namespace conversion; optional<Error> FillExtrusionLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + FillExtrusionOpacity, + FillExtrusionColor, + FillExtrusionTranslate, + FillExtrusionTranslateAnchor, + FillExtrusionPattern, + FillExtrusionHeight, + FillExtrusionBase, + FillExtrusionOpacityTransition, + FillExtrusionColorTransition, + FillExtrusionTranslateTransition, + FillExtrusionTranslateAnchorTransition, + FillExtrusionPatternTransition, + FillExtrusionHeightTransition, + FillExtrusionBaseTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("fill-extrusion-opacity"): + if (name == "fill-extrusion-opacity") { + property = Property::FillExtrusionOpacity; + } + break; + case util::hashFNV1a("fill-extrusion-opacity-transition"): + if (name == "fill-extrusion-opacity-transition") { + property = Property::FillExtrusionOpacityTransition; + } + break; + case util::hashFNV1a("fill-extrusion-color"): + if (name == "fill-extrusion-color") { + property = Property::FillExtrusionColor; + } + break; + case util::hashFNV1a("fill-extrusion-color-transition"): + if (name == "fill-extrusion-color-transition") { + property = Property::FillExtrusionColorTransition; + } + break; + case util::hashFNV1a("fill-extrusion-translate"): + if (name == "fill-extrusion-translate") { + property = Property::FillExtrusionTranslate; + } + break; + case util::hashFNV1a("fill-extrusion-translate-transition"): + if (name == "fill-extrusion-translate-transition") { + property = Property::FillExtrusionTranslateTransition; + } + break; + case util::hashFNV1a("fill-extrusion-translate-anchor"): + if (name == "fill-extrusion-translate-anchor") { + property = Property::FillExtrusionTranslateAnchor; + } + break; + case util::hashFNV1a("fill-extrusion-translate-anchor-transition"): + if (name == "fill-extrusion-translate-anchor-transition") { + property = Property::FillExtrusionTranslateAnchorTransition; + } + break; + case util::hashFNV1a("fill-extrusion-pattern"): + if (name == "fill-extrusion-pattern") { + property = Property::FillExtrusionPattern; + } + break; + case util::hashFNV1a("fill-extrusion-pattern-transition"): + if (name == "fill-extrusion-pattern-transition") { + property = Property::FillExtrusionPatternTransition; + } + break; + case util::hashFNV1a("fill-extrusion-height"): + if (name == "fill-extrusion-height") { + property = Property::FillExtrusionHeight; + } + break; + case util::hashFNV1a("fill-extrusion-height-transition"): + if (name == "fill-extrusion-height-transition") { + property = Property::FillExtrusionHeightTransition; + } + break; + case util::hashFNV1a("fill-extrusion-base"): + if (name == "fill-extrusion-base") { + property = Property::FillExtrusionBase; + } + break; + case util::hashFNV1a("fill-extrusion-base-transition"): + if (name == "fill-extrusion-base-transition") { + property = Property::FillExtrusionBaseTransition; + } + break; - if (name == "fill-extrusion-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::FillExtrusionOpacity) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionOpacity(*typedValue); return nullopt; - } - if (name == "fill-extrusion-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionOpacityTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-color") { + if (property == Property::FillExtrusionColor) { Error error; optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); if (!typedValue) { return error; } - + setFillExtrusionColor(*typedValue); return nullopt; - } - if (name == "fill-extrusion-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionColorTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-translate") { + if (property == Property::FillExtrusionTranslate) { Error error; optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslate(*typedValue); return nullopt; - } - if (name == "fill-extrusion-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionTranslateTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-translate-anchor") { + if (property == Property::FillExtrusionTranslateAnchor) { Error error; optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslateAnchor(*typedValue); return nullopt; - } - if (name == "fill-extrusion-translate-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-pattern") { + if (property == Property::FillExtrusionPattern) { Error error; optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionPattern(*typedValue); return nullopt; - } - if (name == "fill-extrusion-pattern-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionPatternTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-height") { + if (property == Property::FillExtrusionHeight || property == Property::FillExtrusionBase) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } + + if (property == Property::FillExtrusionHeight) { + setFillExtrusionHeight(*typedValue); + return nullopt; + } + + if (property == Property::FillExtrusionBase) { + setFillExtrusionBase(*typedValue); + return nullopt; + } + + } + - setFillExtrusionHeight(*typedValue); + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::FillExtrusionOpacityTransition) { + setFillExtrusionOpacityTransition(*transition); return nullopt; } - if (name == "fill-extrusion-height-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillExtrusionHeightTransition(*transition); + + if (property == Property::FillExtrusionColorTransition) { + setFillExtrusionColorTransition(*transition); return nullopt; } - if (name == "fill-extrusion-base") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setFillExtrusionBase(*typedValue); + if (property == Property::FillExtrusionTranslateTransition) { + setFillExtrusionTranslateTransition(*transition); return nullopt; } - if (name == "fill-extrusion-base-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::FillExtrusionTranslateAnchorTransition) { + setFillExtrusionTranslateAnchorTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionPatternTransition) { + setFillExtrusionPatternTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionHeightTransition) { + setFillExtrusionHeightTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionBaseTransition) { setFillExtrusionBaseTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -462,7 +535,21 @@ optional<Error> FillExtrusionLayer::setLayoutProperty(const std::string& name, c return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 04c3bcef3f..c2756dc90e 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -294,154 +295,226 @@ TransitionOptions FillLayer::getFillPatternTransition() const { using namespace conversion; optional<Error> FillLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + FillAntialias, + FillOpacity, + FillColor, + FillOutlineColor, + FillTranslate, + FillTranslateAnchor, + FillPattern, + FillAntialiasTransition, + FillOpacityTransition, + FillColorTransition, + FillOutlineColorTransition, + FillTranslateTransition, + FillTranslateAnchorTransition, + FillPatternTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("fill-antialias"): + if (name == "fill-antialias") { + property = Property::FillAntialias; + } + break; + case util::hashFNV1a("fill-antialias-transition"): + if (name == "fill-antialias-transition") { + property = Property::FillAntialiasTransition; + } + break; + case util::hashFNV1a("fill-opacity"): + if (name == "fill-opacity") { + property = Property::FillOpacity; + } + break; + case util::hashFNV1a("fill-opacity-transition"): + if (name == "fill-opacity-transition") { + property = Property::FillOpacityTransition; + } + break; + case util::hashFNV1a("fill-color"): + if (name == "fill-color") { + property = Property::FillColor; + } + break; + case util::hashFNV1a("fill-color-transition"): + if (name == "fill-color-transition") { + property = Property::FillColorTransition; + } + break; + case util::hashFNV1a("fill-outline-color"): + if (name == "fill-outline-color") { + property = Property::FillOutlineColor; + } + break; + case util::hashFNV1a("fill-outline-color-transition"): + if (name == "fill-outline-color-transition") { + property = Property::FillOutlineColorTransition; + } + break; + case util::hashFNV1a("fill-translate"): + if (name == "fill-translate") { + property = Property::FillTranslate; + } + break; + case util::hashFNV1a("fill-translate-transition"): + if (name == "fill-translate-transition") { + property = Property::FillTranslateTransition; + } + break; + case util::hashFNV1a("fill-translate-anchor"): + if (name == "fill-translate-anchor") { + property = Property::FillTranslateAnchor; + } + break; + case util::hashFNV1a("fill-translate-anchor-transition"): + if (name == "fill-translate-anchor-transition") { + property = Property::FillTranslateAnchorTransition; + } + break; + case util::hashFNV1a("fill-pattern"): + if (name == "fill-pattern") { + property = Property::FillPattern; + } + break; + case util::hashFNV1a("fill-pattern-transition"): + if (name == "fill-pattern-transition") { + property = Property::FillPatternTransition; + } + break; - if (name == "fill-antialias") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::FillAntialias) { Error error; optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); if (!typedValue) { return error; } - + setFillAntialias(*typedValue); return nullopt; - } - if (name == "fill-antialias-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillAntialiasTransition(*transition); - return nullopt; + } - if (name == "fill-opacity") { + if (property == Property::FillOpacity) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - + setFillOpacity(*typedValue); return nullopt; + } - if (name == "fill-opacity-transition") { + + if (property == Property::FillColor || property == Property::FillOutlineColor) { Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { + optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); + if (!typedValue) { return error; } - - setFillOpacityTransition(*transition); - return nullopt; + + if (property == Property::FillColor) { + setFillColor(*typedValue); + return nullopt; + } + + if (property == Property::FillOutlineColor) { + setFillOutlineColor(*typedValue); + return nullopt; + } + } - if (name == "fill-color") { + if (property == Property::FillTranslate) { Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); + optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - - setFillColor(*typedValue); + + setFillTranslate(*typedValue); return nullopt; + } - if (name == "fill-color-transition") { + + if (property == Property::FillTranslateAnchor) { Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { + optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); + if (!typedValue) { return error; } - - setFillColorTransition(*transition); + + setFillTranslateAnchor(*typedValue); return nullopt; + } - if (name == "fill-outline-color") { + if (property == Property::FillPattern) { Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); + optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); if (!typedValue) { return error; } - - setFillOutlineColor(*typedValue); + + setFillPattern(*typedValue); return nullopt; + } - if (name == "fill-outline-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + - setFillOutlineColorTransition(*transition); + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::FillAntialiasTransition) { + setFillAntialiasTransition(*transition); return nullopt; } - if (name == "fill-translate") { - Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setFillTranslate(*typedValue); + if (property == Property::FillOpacityTransition) { + setFillOpacityTransition(*transition); return nullopt; } - if (name == "fill-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillTranslateTransition(*transition); + + if (property == Property::FillColorTransition) { + setFillColorTransition(*transition); return nullopt; } - if (name == "fill-translate-anchor") { - Error error; - optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setFillTranslateAnchor(*typedValue); + if (property == Property::FillOutlineColorTransition) { + setFillOutlineColorTransition(*transition); return nullopt; } - if (name == "fill-translate-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setFillTranslateAnchorTransition(*transition); + + if (property == Property::FillTranslateTransition) { + setFillTranslateTransition(*transition); return nullopt; } - if (name == "fill-pattern") { - Error error; - optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setFillPattern(*typedValue); + if (property == Property::FillTranslateAnchorTransition) { + setFillTranslateAnchorTransition(*transition); return nullopt; } - if (name == "fill-pattern-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::FillPatternTransition) { setFillPatternTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -462,7 +535,21 @@ optional<Error> FillLayer::setLayoutProperty(const std::string& name, const Conv return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index 443b94c2ce..69499e7d4a 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -242,112 +243,163 @@ TransitionOptions HeatmapLayer::getHeatmapOpacityTransition() const { using namespace conversion; optional<Error> HeatmapLayer::setPaintProperty(const std::string& name, const Convertible& value) { - - if (name == "heatmap-radius") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + enum class Property { + Unknown, + HeatmapRadius, + HeatmapWeight, + HeatmapIntensity, + HeatmapColor, + HeatmapOpacity, + HeatmapRadiusTransition, + HeatmapWeightTransition, + HeatmapIntensityTransition, + HeatmapColorTransition, + HeatmapOpacityTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("heatmap-radius"): + if (name == "heatmap-radius") { + property = Property::HeatmapRadius; } - - setHeatmapRadius(*typedValue); - return nullopt; - } - if (name == "heatmap-radius-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + break; + case util::hashFNV1a("heatmap-radius-transition"): + if (name == "heatmap-radius-transition") { + property = Property::HeatmapRadiusTransition; + } + break; + case util::hashFNV1a("heatmap-weight"): + if (name == "heatmap-weight") { + property = Property::HeatmapWeight; } + break; + case util::hashFNV1a("heatmap-weight-transition"): + if (name == "heatmap-weight-transition") { + property = Property::HeatmapWeightTransition; + } + break; + case util::hashFNV1a("heatmap-intensity"): + if (name == "heatmap-intensity") { + property = Property::HeatmapIntensity; + } + break; + case util::hashFNV1a("heatmap-intensity-transition"): + if (name == "heatmap-intensity-transition") { + property = Property::HeatmapIntensityTransition; + } + break; + case util::hashFNV1a("heatmap-color"): + if (name == "heatmap-color") { + property = Property::HeatmapColor; + } + break; + case util::hashFNV1a("heatmap-color-transition"): + if (name == "heatmap-color-transition") { + property = Property::HeatmapColorTransition; + } + break; + case util::hashFNV1a("heatmap-opacity"): + if (name == "heatmap-opacity") { + property = Property::HeatmapOpacity; + } + break; + case util::hashFNV1a("heatmap-opacity-transition"): + if (name == "heatmap-opacity-transition") { + property = Property::HeatmapOpacityTransition; + } + break; + + } - setHeatmapRadiusTransition(*transition); - return nullopt; + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; } - - if (name == "heatmap-weight") { + + + if (property == Property::HeatmapRadius || property == Property::HeatmapWeight) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - - setHeatmapWeight(*typedValue); - return nullopt; - } - if (name == "heatmap-weight-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::HeatmapRadius) { + setHeatmapRadius(*typedValue); + return nullopt; } - - setHeatmapWeightTransition(*transition); - return nullopt; + + if (property == Property::HeatmapWeight) { + setHeatmapWeight(*typedValue); + return nullopt; + } + } - if (name == "heatmap-intensity") { + if (property == Property::HeatmapIntensity || property == Property::HeatmapOpacity) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - - setHeatmapIntensity(*typedValue); - return nullopt; - } - if (name == "heatmap-intensity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::HeatmapIntensity) { + setHeatmapIntensity(*typedValue); + return nullopt; } - - setHeatmapIntensityTransition(*transition); - return nullopt; + + if (property == Property::HeatmapOpacity) { + setHeatmapOpacity(*typedValue); + return nullopt; + } + } - if (name == "heatmap-color") { + if (property == Property::HeatmapColor) { Error error; optional<ColorRampPropertyValue> typedValue = convert<ColorRampPropertyValue>(value, error, false, false); if (!typedValue) { return error; } - + setHeatmapColor(*typedValue); return nullopt; + } - if (name == "heatmap-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + - setHeatmapColorTransition(*transition); + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::HeatmapRadiusTransition) { + setHeatmapRadiusTransition(*transition); return nullopt; } - if (name == "heatmap-opacity") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHeatmapOpacity(*typedValue); + if (property == Property::HeatmapWeightTransition) { + setHeatmapWeightTransition(*transition); return nullopt; } - if (name == "heatmap-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::HeatmapIntensityTransition) { + setHeatmapIntensityTransition(*transition); + return nullopt; + } + + if (property == Property::HeatmapColorTransition) { + setHeatmapColorTransition(*transition); + return nullopt; + } + + if (property == Property::HeatmapOpacityTransition) { setHeatmapOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -368,7 +420,21 @@ optional<Error> HeatmapLayer::setLayoutProperty(const std::string& name, const C return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/heatmap_layer_properties.hpp b/src/mbgl/style/layers/heatmap_layer_properties.hpp index fe7257a78a..4d49a52c72 100644 --- a/src/mbgl/style/layers/heatmap_layer_properties.hpp +++ b/src/mbgl/style/layers/heatmap_layer_properties.hpp @@ -24,7 +24,8 @@ struct HeatmapIntensity : PaintProperty<float> { static float defaultValue() { return 1; } }; -using HeatmapColor = ColorRampProperty; +struct HeatmapColor : ColorRampProperty { +}; struct HeatmapOpacity : PaintProperty<float> { static float defaultValue() { return 1; } diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 2d8c837baa..9ccdd1567b 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -245,133 +246,185 @@ TransitionOptions HillshadeLayer::getHillshadeAccentColorTransition() const { using namespace conversion; optional<Error> HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + HillshadeIlluminationDirection, + HillshadeIlluminationAnchor, + HillshadeExaggeration, + HillshadeShadowColor, + HillshadeHighlightColor, + HillshadeAccentColor, + HillshadeIlluminationDirectionTransition, + HillshadeIlluminationAnchorTransition, + HillshadeExaggerationTransition, + HillshadeShadowColorTransition, + HillshadeHighlightColorTransition, + 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 (name == "hillshade-illumination-direction") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::HillshadeIlluminationDirection || property == Property::HillshadeExaggeration) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - - setHillshadeIlluminationDirection(*typedValue); - return nullopt; - } - if (name == "hillshade-illumination-direction-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::HillshadeIlluminationDirection) { + setHillshadeIlluminationDirection(*typedValue); + return nullopt; } - - setHillshadeIlluminationDirectionTransition(*transition); - return nullopt; + + if (property == Property::HillshadeExaggeration) { + setHillshadeExaggeration(*typedValue); + return nullopt; + } + } - if (name == "hillshade-illumination-anchor") { + if (property == Property::HillshadeIlluminationAnchor) { Error error; optional<PropertyValue<HillshadeIlluminationAnchorType>> typedValue = convert<PropertyValue<HillshadeIlluminationAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - + setHillshadeIlluminationAnchor(*typedValue); return nullopt; - } - if (name == "hillshade-illumination-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setHillshadeIlluminationAnchorTransition(*transition); - return nullopt; + } - if (name == "hillshade-exaggeration") { + if (property == Property::HillshadeShadowColor || property == Property::HillshadeHighlightColor || property == Property::HillshadeAccentColor) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); if (!typedValue) { return error; } - - setHillshadeExaggeration(*typedValue); - return nullopt; - } - if (name == "hillshade-exaggeration-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::HillshadeShadowColor) { + setHillshadeShadowColor(*typedValue); + return nullopt; } - - setHillshadeExaggerationTransition(*transition); - return nullopt; + + if (property == Property::HillshadeHighlightColor) { + setHillshadeHighlightColor(*typedValue); + return nullopt; + } + + if (property == Property::HillshadeAccentColor) { + setHillshadeAccentColor(*typedValue); + return nullopt; + } + } - if (name == "hillshade-shadow-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); - if (!typedValue) { - return error; - } - setHillshadeShadowColor(*typedValue); + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + + if (property == Property::HillshadeIlluminationDirectionTransition) { + setHillshadeIlluminationDirectionTransition(*transition); return nullopt; } - if (name == "hillshade-shadow-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setHillshadeShadowColorTransition(*transition); + + if (property == Property::HillshadeIlluminationAnchorTransition) { + setHillshadeIlluminationAnchorTransition(*transition); return nullopt; } - if (name == "hillshade-highlight-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeHighlightColor(*typedValue); + if (property == Property::HillshadeExaggerationTransition) { + setHillshadeExaggerationTransition(*transition); return nullopt; } - if (name == "hillshade-highlight-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setHillshadeHighlightColorTransition(*transition); + + if (property == Property::HillshadeShadowColorTransition) { + setHillshadeShadowColorTransition(*transition); return nullopt; } - if (name == "hillshade-accent-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeAccentColor(*typedValue); + if (property == Property::HillshadeHighlightColorTransition) { + setHillshadeHighlightColorTransition(*transition); return nullopt; } - if (name == "hillshade-accent-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::HillshadeAccentColorTransition) { setHillshadeAccentColorTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -392,7 +445,21 @@ optional<Error> HillshadeLayer::setLayoutProperty(const std::string& name, const return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 7555054bdb..8a6db749cf 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -14,6 +14,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -178,28 +179,78 @@ TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>T using namespace conversion; optional<Error> <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) { - <% for (const property of paintProperties) { %> - if (name == "<%- property.name %>") { - Error error; - optional<<%- propertyValueType(property) %>> typedValue = convert<<%- propertyValueType(property) %>>(value, error, <%- property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven' %>, <%- property.name === 'icon-image' || property.name === 'text-field' %>); - if (!typedValue) { - return error; + enum class Property { + Unknown, +<% for (const property of paintProperties) { -%> + <%- camelize(property.name) %>, +<% } -%> +<% for (const property of paintProperties) { -%> + <%- camelize(property.name) %>Transition, +<% } -%> + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + <% for (const property of paintProperties) { -%> +case util::hashFNV1a("<%- property.name %>"): + if (name == "<%- property.name %>") { + property = Property::<%- camelize(property.name) %>; } + break; + case util::hashFNV1a("<%- property.name %>-transition"): + if (name == "<%- property.name %>-transition") { + property = Property::<%- camelize(property.name) %>Transition; + } + break; + <% } %> + } - set<%- camelize(property.name) %>(*typedValue); - return nullopt; + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; } - if (name == "<%- property.name %>-transition") { + + <% + const paintConversions = {}; + for (const property of paintProperties) { + const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; + const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; + const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + paintConversions[conversion] = paintConversions[conversion] || []; + paintConversions[conversion].push(property); + } + -%> + <% for (const key in paintConversions) { + const properties = paintConversions[key]; + %> + if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { + <%- key %>; + if (!typedValue) { return error; } + <% if (properties.length == 1) { %> + set<%- camelize(properties[0].name) %>(*typedValue); + return nullopt; + <% } else for (const property of properties) { %> + if (property == Property::<%- camelize(property.name) %>) { + set<%- camelize(property.name) %>(*typedValue); + return nullopt; + } + <% } %> + } + <% } %> + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; + } + <% for (const property of paintProperties) { %> + if (property == Property::<%- camelize(property.name) %>Transition) { set<%- camelize(property.name) %>Transition(*transition); return nullopt; } - <% } -%> + <% } %> return Error { "layer doesn't support this property" }; } @@ -221,18 +272,58 @@ optional<Error> <%- camelize(type) %>Layer::setLayoutProperty(const std::string& return nullopt; } + enum class Property { + Unknown, +<% for (const property of layoutProperties) { -%> + <%- camelize(property.name) %>, +<% } -%> + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { <% for (const property of layoutProperties) { %> - if (name == "<%- property.name %>") { + case util::hashFNV1a("<%- property.name %>"): + if (name == "<%- property.name %>") { + property = Property::<%- camelize(property.name) %>; + } + break; + <% } %> + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + <% + const layoutConversions = {}; + for (const property of layoutProperties) { + const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; + const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; + const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + layoutConversions[conversion] = layoutConversions[conversion] || []; + layoutConversions[conversion].push(property); + } + -%> + <% for (const key in layoutConversions) { + const properties = layoutConversions[key]; + %> + if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { Error error; - optional<<%- propertyValueType(property) %>> typedValue = convert<<%- propertyValueType(property) %>>(value, error, <%- property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven' %>, <%- property.name === 'icon-image' || property.name === 'text-field' %>); + <%- key %>; if (!typedValue) { return error; } - - set<%- camelize(property.name) %>(*typedValue); + <% if (properties.length == 1) { %> + set<%- camelize(properties[0].name) %>(*typedValue); return nullopt; + <% } else for (const property of properties) { %> + if (property == Property::<%- camelize(property.name) %>) { + set<%- camelize(property.name) %>(*typedValue); + return nullopt; + } + <% } %> } - <% } -%> + <% } %> return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 5b774933a6..694d9a62b7 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -26,7 +26,8 @@ struct <%- camelize(property.name) %> : <%- layoutPropertyType(property, type) % <% } -%> <% for (const property of paintProperties) { -%> <% if (property['property-type'] === 'color-ramp') { -%> -using <%- camelize(property.name) %> = ColorRampProperty; +struct <%- camelize(property.name) %> : ColorRampProperty { +}; <% } else { -%> struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> { static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; } diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index c3203f84e4..cc6bfdde37 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -440,217 +441,292 @@ TransitionOptions LineLayer::getLinePatternTransition() const { using namespace conversion; optional<Error> LineLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + LineOpacity, + LineColor, + LineTranslate, + LineTranslateAnchor, + LineWidth, + LineGapWidth, + LineOffset, + LineBlur, + LineDasharray, + LinePattern, + LineOpacityTransition, + LineColorTransition, + LineTranslateTransition, + LineTranslateAnchorTransition, + LineWidthTransition, + LineGapWidthTransition, + LineOffsetTransition, + LineBlurTransition, + LineDasharrayTransition, + LinePatternTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("line-opacity"): + if (name == "line-opacity") { + property = Property::LineOpacity; + } + break; + case util::hashFNV1a("line-opacity-transition"): + if (name == "line-opacity-transition") { + property = Property::LineOpacityTransition; + } + break; + case util::hashFNV1a("line-color"): + if (name == "line-color") { + property = Property::LineColor; + } + break; + case util::hashFNV1a("line-color-transition"): + if (name == "line-color-transition") { + property = Property::LineColorTransition; + } + break; + case util::hashFNV1a("line-translate"): + if (name == "line-translate") { + property = Property::LineTranslate; + } + break; + case util::hashFNV1a("line-translate-transition"): + if (name == "line-translate-transition") { + property = Property::LineTranslateTransition; + } + break; + case util::hashFNV1a("line-translate-anchor"): + if (name == "line-translate-anchor") { + property = Property::LineTranslateAnchor; + } + break; + case util::hashFNV1a("line-translate-anchor-transition"): + if (name == "line-translate-anchor-transition") { + property = Property::LineTranslateAnchorTransition; + } + break; + case util::hashFNV1a("line-width"): + if (name == "line-width") { + property = Property::LineWidth; + } + break; + case util::hashFNV1a("line-width-transition"): + if (name == "line-width-transition") { + property = Property::LineWidthTransition; + } + break; + case util::hashFNV1a("line-gap-width"): + if (name == "line-gap-width") { + property = Property::LineGapWidth; + } + break; + case util::hashFNV1a("line-gap-width-transition"): + if (name == "line-gap-width-transition") { + property = Property::LineGapWidthTransition; + } + break; + case util::hashFNV1a("line-offset"): + if (name == "line-offset") { + property = Property::LineOffset; + } + break; + case util::hashFNV1a("line-offset-transition"): + if (name == "line-offset-transition") { + property = Property::LineOffsetTransition; + } + break; + case util::hashFNV1a("line-blur"): + if (name == "line-blur") { + property = Property::LineBlur; + } + break; + case util::hashFNV1a("line-blur-transition"): + if (name == "line-blur-transition") { + property = Property::LineBlurTransition; + } + break; + case util::hashFNV1a("line-dasharray"): + if (name == "line-dasharray") { + property = Property::LineDasharray; + } + break; + case util::hashFNV1a("line-dasharray-transition"): + if (name == "line-dasharray-transition") { + property = Property::LineDasharrayTransition; + } + break; + case util::hashFNV1a("line-pattern"): + if (name == "line-pattern") { + property = Property::LinePattern; + } + break; + case util::hashFNV1a("line-pattern-transition"): + if (name == "line-pattern-transition") { + property = Property::LinePatternTransition; + } + break; - if (name == "line-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::LineOpacity || property == Property::LineWidth || property == Property::LineGapWidth || property == Property::LineOffset || property == Property::LineBlur) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - - setLineOpacity(*typedValue); - return nullopt; - } - if (name == "line-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::LineOpacity) { + setLineOpacity(*typedValue); + return nullopt; } - - setLineOpacityTransition(*transition); - return nullopt; + + if (property == Property::LineWidth) { + setLineWidth(*typedValue); + return nullopt; + } + + if (property == Property::LineGapWidth) { + setLineGapWidth(*typedValue); + return nullopt; + } + + if (property == Property::LineOffset) { + setLineOffset(*typedValue); + return nullopt; + } + + if (property == Property::LineBlur) { + setLineBlur(*typedValue); + return nullopt; + } + } - if (name == "line-color") { + if (property == Property::LineColor) { Error error; optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); if (!typedValue) { return error; } - + setLineColor(*typedValue); return nullopt; - } - if (name == "line-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineColorTransition(*transition); - return nullopt; + } - if (name == "line-translate") { + if (property == Property::LineTranslate) { Error error; optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslate(*typedValue); return nullopt; - } - if (name == "line-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineTranslateTransition(*transition); - return nullopt; + } - if (name == "line-translate-anchor") { + if (property == Property::LineTranslateAnchor) { Error error; optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslateAnchor(*typedValue); return nullopt; + } - if (name == "line-translate-anchor-transition") { + + if (property == Property::LineDasharray) { Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { + optional<PropertyValue<std::vector<float>>> typedValue = convert<PropertyValue<std::vector<float>>>(value, error, false, false); + if (!typedValue) { return error; } - - setLineTranslateAnchorTransition(*transition); + + setLineDasharray(*typedValue); return nullopt; + } - if (name == "line-width") { + if (property == Property::LinePattern) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); if (!typedValue) { return error; } - - setLineWidth(*typedValue); + + setLinePattern(*typedValue); return nullopt; + } - if (name == "line-width-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + - setLineWidthTransition(*transition); - return nullopt; + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; } - if (name == "line-gap-width") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineGapWidth(*typedValue); + if (property == Property::LineOpacityTransition) { + setLineOpacityTransition(*transition); return nullopt; } - if (name == "line-gap-width-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineGapWidthTransition(*transition); + + if (property == Property::LineColorTransition) { + setLineColorTransition(*transition); return nullopt; } - if (name == "line-offset") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineOffset(*typedValue); + if (property == Property::LineTranslateTransition) { + setLineTranslateTransition(*transition); return nullopt; } - if (name == "line-offset-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineOffsetTransition(*transition); + + if (property == Property::LineTranslateAnchorTransition) { + setLineTranslateAnchorTransition(*transition); return nullopt; } - if (name == "line-blur") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineBlur(*typedValue); + if (property == Property::LineWidthTransition) { + setLineWidthTransition(*transition); return nullopt; } - if (name == "line-blur-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineBlurTransition(*transition); + + if (property == Property::LineGapWidthTransition) { + setLineGapWidthTransition(*transition); return nullopt; } - if (name == "line-dasharray") { - Error error; - optional<PropertyValue<std::vector<float>>> typedValue = convert<PropertyValue<std::vector<float>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setLineDasharray(*typedValue); + if (property == Property::LineOffsetTransition) { + setLineOffsetTransition(*transition); return nullopt; } - if (name == "line-dasharray-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setLineDasharrayTransition(*transition); + + if (property == Property::LineBlurTransition) { + setLineBlurTransition(*transition); return nullopt; } - if (name == "line-pattern") { - Error error; - optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setLinePattern(*typedValue); + if (property == Property::LineDasharrayTransition) { + setLineDasharrayTransition(*transition); return nullopt; } - if (name == "line-pattern-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::LinePatternTransition) { setLinePatternTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -671,51 +747,92 @@ optional<Error> LineLayer::setLayoutProperty(const std::string& name, const Conv return nullopt; } + enum class Property { + Unknown, + LineCap, + LineJoin, + LineMiterLimit, + LineRoundLimit, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + + case util::hashFNV1a("line-cap"): + if (name == "line-cap") { + property = Property::LineCap; + } + break; - if (name == "line-cap") { + case util::hashFNV1a("line-join"): + if (name == "line-join") { + property = Property::LineJoin; + } + break; + + case util::hashFNV1a("line-miter-limit"): + if (name == "line-miter-limit") { + property = Property::LineMiterLimit; + } + break; + + case util::hashFNV1a("line-round-limit"): + if (name == "line-round-limit") { + property = Property::LineRoundLimit; + } + break; + + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::LineCap) { Error error; optional<PropertyValue<LineCapType>> typedValue = convert<PropertyValue<LineCapType>>(value, error, false, false); if (!typedValue) { return error; } - + setLineCap(*typedValue); return nullopt; + } - if (name == "line-join") { + if (property == Property::LineJoin) { Error error; optional<PropertyValue<LineJoinType>> typedValue = convert<PropertyValue<LineJoinType>>(value, error, true, false); if (!typedValue) { return error; } - + setLineJoin(*typedValue); return nullopt; + } - if (name == "line-miter-limit") { + if (property == Property::LineMiterLimit || property == Property::LineRoundLimit) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - - setLineMiterLimit(*typedValue); - return nullopt; - } - - if (name == "line-round-limit") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::LineMiterLimit) { + setLineMiterLimit(*typedValue); + return nullopt; } - - setLineRoundLimit(*typedValue); - return nullopt; + + if (property == Property::LineRoundLimit) { + setLineRoundLimit(*typedValue); + return nullopt; + } + } + return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 0eba8ef886..da3f7f8a18 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -299,175 +300,220 @@ TransitionOptions RasterLayer::getRasterFadeDurationTransition() const { using namespace conversion; optional<Error> RasterLayer::setPaintProperty(const std::string& name, const Convertible& value) { - - if (name == "raster-opacity") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; + enum class Property { + Unknown, + RasterOpacity, + RasterHueRotate, + RasterBrightnessMin, + RasterBrightnessMax, + RasterSaturation, + RasterContrast, + RasterResampling, + RasterFadeDuration, + RasterOpacityTransition, + RasterHueRotateTransition, + RasterBrightnessMinTransition, + RasterBrightnessMaxTransition, + RasterSaturationTransition, + RasterContrastTransition, + RasterResamplingTransition, + RasterFadeDurationTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("raster-opacity"): + if (name == "raster-opacity") { + property = Property::RasterOpacity; } - - setRasterOpacity(*typedValue); - return nullopt; - } - if (name == "raster-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + break; + case util::hashFNV1a("raster-opacity-transition"): + if (name == "raster-opacity-transition") { + property = Property::RasterOpacityTransition; + } + break; + case util::hashFNV1a("raster-hue-rotate"): + if (name == "raster-hue-rotate") { + property = Property::RasterHueRotate; + } + break; + case util::hashFNV1a("raster-hue-rotate-transition"): + if (name == "raster-hue-rotate-transition") { + property = Property::RasterHueRotateTransition; + } + break; + case util::hashFNV1a("raster-brightness-min"): + if (name == "raster-brightness-min") { + property = Property::RasterBrightnessMin; + } + break; + case util::hashFNV1a("raster-brightness-min-transition"): + if (name == "raster-brightness-min-transition") { + property = Property::RasterBrightnessMinTransition; + } + break; + case util::hashFNV1a("raster-brightness-max"): + if (name == "raster-brightness-max") { + property = Property::RasterBrightnessMax; + } + break; + case util::hashFNV1a("raster-brightness-max-transition"): + if (name == "raster-brightness-max-transition") { + property = Property::RasterBrightnessMaxTransition; + } + break; + case util::hashFNV1a("raster-saturation"): + if (name == "raster-saturation") { + property = Property::RasterSaturation; } + break; + case util::hashFNV1a("raster-saturation-transition"): + if (name == "raster-saturation-transition") { + property = Property::RasterSaturationTransition; + } + break; + case util::hashFNV1a("raster-contrast"): + if (name == "raster-contrast") { + property = Property::RasterContrast; + } + break; + case util::hashFNV1a("raster-contrast-transition"): + if (name == "raster-contrast-transition") { + property = Property::RasterContrastTransition; + } + break; + case util::hashFNV1a("raster-resampling"): + if (name == "raster-resampling") { + property = Property::RasterResampling; + } + break; + case util::hashFNV1a("raster-resampling-transition"): + if (name == "raster-resampling-transition") { + property = Property::RasterResamplingTransition; + } + break; + case util::hashFNV1a("raster-fade-duration"): + if (name == "raster-fade-duration") { + property = Property::RasterFadeDuration; + } + break; + case util::hashFNV1a("raster-fade-duration-transition"): + if (name == "raster-fade-duration-transition") { + property = Property::RasterFadeDurationTransition; + } + break; + + } - setRasterOpacityTransition(*transition); - return nullopt; + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; } - - if (name == "raster-hue-rotate") { + + + if (property == Property::RasterOpacity || property == Property::RasterHueRotate || property == Property::RasterBrightnessMin || property == Property::RasterBrightnessMax || property == Property::RasterSaturation || property == Property::RasterContrast || property == Property::RasterFadeDuration) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - - setRasterHueRotate(*typedValue); - return nullopt; - } - if (name == "raster-hue-rotate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::RasterOpacity) { + setRasterOpacity(*typedValue); + return nullopt; } - - setRasterHueRotateTransition(*transition); - return nullopt; + + if (property == Property::RasterHueRotate) { + setRasterHueRotate(*typedValue); + return nullopt; + } + + if (property == Property::RasterBrightnessMin) { + setRasterBrightnessMin(*typedValue); + return nullopt; + } + + if (property == Property::RasterBrightnessMax) { + setRasterBrightnessMax(*typedValue); + return nullopt; + } + + if (property == Property::RasterSaturation) { + setRasterSaturation(*typedValue); + return nullopt; + } + + if (property == Property::RasterContrast) { + setRasterContrast(*typedValue); + return nullopt; + } + + if (property == Property::RasterFadeDuration) { + setRasterFadeDuration(*typedValue); + return nullopt; + } + } - if (name == "raster-brightness-min") { + if (property == Property::RasterResampling) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + optional<PropertyValue<RasterResamplingType>> typedValue = convert<PropertyValue<RasterResamplingType>>(value, error, false, false); if (!typedValue) { return error; } - - setRasterBrightnessMin(*typedValue); + + setRasterResampling(*typedValue); return nullopt; + } - if (name == "raster-brightness-min-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } + - setRasterBrightnessMinTransition(*transition); - return nullopt; + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; } - if (name == "raster-brightness-max") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterBrightnessMax(*typedValue); + if (property == Property::RasterOpacityTransition) { + setRasterOpacityTransition(*transition); return nullopt; } - if (name == "raster-brightness-max-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setRasterBrightnessMaxTransition(*transition); + + if (property == Property::RasterHueRotateTransition) { + setRasterHueRotateTransition(*transition); return nullopt; } - if (name == "raster-saturation") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterSaturation(*typedValue); + if (property == Property::RasterBrightnessMinTransition) { + setRasterBrightnessMinTransition(*transition); return nullopt; } - if (name == "raster-saturation-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setRasterSaturationTransition(*transition); + + if (property == Property::RasterBrightnessMaxTransition) { + setRasterBrightnessMaxTransition(*transition); return nullopt; } - if (name == "raster-contrast") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterContrast(*typedValue); + if (property == Property::RasterSaturationTransition) { + setRasterSaturationTransition(*transition); return nullopt; } - if (name == "raster-contrast-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::RasterContrastTransition) { setRasterContrastTransition(*transition); return nullopt; } - if (name == "raster-resampling") { - Error error; - optional<PropertyValue<RasterResamplingType>> typedValue = convert<PropertyValue<RasterResamplingType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterResampling(*typedValue); - return nullopt; - } - if (name == "raster-resampling-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::RasterResamplingTransition) { setRasterResamplingTransition(*transition); return nullopt; } - if (name == "raster-fade-duration") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterFadeDuration(*typedValue); - return nullopt; - } - if (name == "raster-fade-duration-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::RasterFadeDurationTransition) { setRasterFadeDurationTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -488,7 +534,21 @@ optional<Error> RasterLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + 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" }; } diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index bb5b317a38..e7cba19ea5 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -9,6 +9,7 @@ #include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/transition_options.hpp> #include <mbgl/style/conversion/json.hpp> +#include <mbgl/util/fnv_hash.hpp> namespace mbgl { namespace style { @@ -1060,301 +1061,372 @@ TransitionOptions SymbolLayer::getTextTranslateAnchorTransition() const { using namespace conversion; optional<Error> SymbolLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + IconOpacity, + IconColor, + IconHaloColor, + IconHaloWidth, + IconHaloBlur, + IconTranslate, + IconTranslateAnchor, + TextOpacity, + TextColor, + TextHaloColor, + TextHaloWidth, + TextHaloBlur, + TextTranslate, + TextTranslateAnchor, + IconOpacityTransition, + IconColorTransition, + IconHaloColorTransition, + IconHaloWidthTransition, + IconHaloBlurTransition, + IconTranslateTransition, + IconTranslateAnchorTransition, + TextOpacityTransition, + TextColorTransition, + TextHaloColorTransition, + TextHaloWidthTransition, + TextHaloBlurTransition, + TextTranslateTransition, + TextTranslateAnchorTransition, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { + case util::hashFNV1a("icon-opacity"): + if (name == "icon-opacity") { + property = Property::IconOpacity; + } + break; + case util::hashFNV1a("icon-opacity-transition"): + if (name == "icon-opacity-transition") { + property = Property::IconOpacityTransition; + } + break; + case util::hashFNV1a("icon-color"): + if (name == "icon-color") { + property = Property::IconColor; + } + break; + case util::hashFNV1a("icon-color-transition"): + if (name == "icon-color-transition") { + property = Property::IconColorTransition; + } + break; + case util::hashFNV1a("icon-halo-color"): + if (name == "icon-halo-color") { + property = Property::IconHaloColor; + } + break; + case util::hashFNV1a("icon-halo-color-transition"): + if (name == "icon-halo-color-transition") { + property = Property::IconHaloColorTransition; + } + break; + case util::hashFNV1a("icon-halo-width"): + if (name == "icon-halo-width") { + property = Property::IconHaloWidth; + } + break; + case util::hashFNV1a("icon-halo-width-transition"): + if (name == "icon-halo-width-transition") { + property = Property::IconHaloWidthTransition; + } + break; + case util::hashFNV1a("icon-halo-blur"): + if (name == "icon-halo-blur") { + property = Property::IconHaloBlur; + } + break; + case util::hashFNV1a("icon-halo-blur-transition"): + if (name == "icon-halo-blur-transition") { + property = Property::IconHaloBlurTransition; + } + break; + case util::hashFNV1a("icon-translate"): + if (name == "icon-translate") { + property = Property::IconTranslate; + } + break; + case util::hashFNV1a("icon-translate-transition"): + if (name == "icon-translate-transition") { + property = Property::IconTranslateTransition; + } + break; + case util::hashFNV1a("icon-translate-anchor"): + if (name == "icon-translate-anchor") { + property = Property::IconTranslateAnchor; + } + break; + case util::hashFNV1a("icon-translate-anchor-transition"): + if (name == "icon-translate-anchor-transition") { + property = Property::IconTranslateAnchorTransition; + } + break; + case util::hashFNV1a("text-opacity"): + if (name == "text-opacity") { + property = Property::TextOpacity; + } + break; + case util::hashFNV1a("text-opacity-transition"): + if (name == "text-opacity-transition") { + property = Property::TextOpacityTransition; + } + break; + case util::hashFNV1a("text-color"): + if (name == "text-color") { + property = Property::TextColor; + } + break; + case util::hashFNV1a("text-color-transition"): + if (name == "text-color-transition") { + property = Property::TextColorTransition; + } + break; + case util::hashFNV1a("text-halo-color"): + if (name == "text-halo-color") { + property = Property::TextHaloColor; + } + break; + case util::hashFNV1a("text-halo-color-transition"): + if (name == "text-halo-color-transition") { + property = Property::TextHaloColorTransition; + } + break; + case util::hashFNV1a("text-halo-width"): + if (name == "text-halo-width") { + property = Property::TextHaloWidth; + } + break; + case util::hashFNV1a("text-halo-width-transition"): + if (name == "text-halo-width-transition") { + property = Property::TextHaloWidthTransition; + } + break; + case util::hashFNV1a("text-halo-blur"): + if (name == "text-halo-blur") { + property = Property::TextHaloBlur; + } + break; + case util::hashFNV1a("text-halo-blur-transition"): + if (name == "text-halo-blur-transition") { + property = Property::TextHaloBlurTransition; + } + break; + case util::hashFNV1a("text-translate"): + if (name == "text-translate") { + property = Property::TextTranslate; + } + break; + case util::hashFNV1a("text-translate-transition"): + if (name == "text-translate-transition") { + property = Property::TextTranslateTransition; + } + break; + case util::hashFNV1a("text-translate-anchor"): + if (name == "text-translate-anchor") { + property = Property::TextTranslateAnchor; + } + break; + case util::hashFNV1a("text-translate-anchor-transition"): + if (name == "text-translate-anchor-transition") { + property = Property::TextTranslateAnchorTransition; + } + break; - if (name == "icon-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::IconOpacity || property == Property::IconHaloWidth || property == Property::IconHaloBlur || property == Property::TextOpacity || property == Property::TextHaloWidth || property == Property::TextHaloBlur) { Error error; optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - - setIconOpacity(*typedValue); - return nullopt; - } - if (name == "icon-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::IconOpacity) { + setIconOpacity(*typedValue); + return nullopt; } - - setIconOpacityTransition(*transition); - return nullopt; + + if (property == Property::IconHaloWidth) { + setIconHaloWidth(*typedValue); + return nullopt; + } + + if (property == Property::IconHaloBlur) { + setIconHaloBlur(*typedValue); + return nullopt; + } + + if (property == Property::TextOpacity) { + setTextOpacity(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloWidth) { + setTextHaloWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloBlur) { + setTextHaloBlur(*typedValue); + return nullopt; + } + } - if (name == "icon-color") { + if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || property == Property::TextHaloColor) { Error error; optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); if (!typedValue) { return error; } - - setIconColor(*typedValue); - return nullopt; - } - if (name == "icon-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::IconColor) { + setIconColor(*typedValue); + return nullopt; } - - setIconColorTransition(*transition); - return nullopt; + + if (property == Property::IconHaloColor) { + setIconHaloColor(*typedValue); + return nullopt; + } + + if (property == Property::TextColor) { + setTextColor(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloColor) { + setTextHaloColor(*typedValue); + return nullopt; + } + } - if (name == "icon-halo-color") { + if (property == Property::IconTranslate || property == Property::TextTranslate) { Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); + optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); if (!typedValue) { return error; } - - setIconHaloColor(*typedValue); - return nullopt; - } - if (name == "icon-halo-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::IconTranslate) { + setIconTranslate(*typedValue); + return nullopt; } - - setIconHaloColorTransition(*transition); - return nullopt; + + if (property == Property::TextTranslate) { + setTextTranslate(*typedValue); + return nullopt; + } + } - if (name == "icon-halo-width") { + if (property == Property::IconTranslateAnchor || property == Property::TextTranslateAnchor) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); if (!typedValue) { return error; } - - setIconHaloWidth(*typedValue); - return nullopt; - } - if (name == "icon-halo-width-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; + + if (property == Property::IconTranslateAnchor) { + setIconTranslateAnchor(*typedValue); + return nullopt; } - - setIconHaloWidthTransition(*transition); - return nullopt; + + if (property == Property::TextTranslateAnchor) { + setTextTranslateAnchor(*typedValue); + return nullopt; + } + } - if (name == "icon-halo-blur") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - setIconHaloBlur(*typedValue); - return nullopt; + Error error; + optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); + if (!transition) { + return error; } - if (name == "icon-halo-blur-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setIconHaloBlurTransition(*transition); + + if (property == Property::IconOpacityTransition) { + setIconOpacityTransition(*transition); return nullopt; } - if (name == "icon-translate") { - Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTranslate(*typedValue); + if (property == Property::IconColorTransition) { + setIconColorTransition(*transition); return nullopt; } - if (name == "icon-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setIconTranslateTransition(*transition); + + if (property == Property::IconHaloColorTransition) { + setIconHaloColorTransition(*transition); return nullopt; } - if (name == "icon-translate-anchor") { - Error error; - optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTranslateAnchor(*typedValue); + if (property == Property::IconHaloWidthTransition) { + setIconHaloWidthTransition(*transition); return nullopt; } - if (name == "icon-translate-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setIconTranslateAnchorTransition(*transition); + + if (property == Property::IconHaloBlurTransition) { + setIconHaloBlurTransition(*transition); return nullopt; } - if (name == "text-opacity") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextOpacity(*typedValue); + if (property == Property::IconTranslateTransition) { + setIconTranslateTransition(*transition); return nullopt; } - if (name == "text-opacity-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - - setTextOpacityTransition(*transition); + + if (property == Property::IconTranslateAnchorTransition) { + setIconTranslateAnchorTransition(*transition); return nullopt; } - if (name == "text-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextColor(*typedValue); + if (property == Property::TextOpacityTransition) { + setTextOpacityTransition(*transition); return nullopt; } - if (name == "text-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + + if (property == Property::TextColorTransition) { setTextColorTransition(*transition); return nullopt; } - if (name == "text-halo-color") { - Error error; - optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloColor(*typedValue); - return nullopt; - } - if (name == "text-halo-color-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloColorTransition) { setTextHaloColorTransition(*transition); return nullopt; } - if (name == "text-halo-width") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloWidth(*typedValue); - return nullopt; - } - if (name == "text-halo-width-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloWidthTransition) { setTextHaloWidthTransition(*transition); return nullopt; } - if (name == "text-halo-blur") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloBlur(*typedValue); - return nullopt; - } - if (name == "text-halo-blur-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloBlurTransition) { setTextHaloBlurTransition(*transition); return nullopt; } - if (name == "text-translate") { - Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextTranslate(*typedValue); - return nullopt; - } - if (name == "text-translate-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextTranslateTransition) { setTextTranslateTransition(*transition); return nullopt; } - if (name == "text-translate-anchor") { - Error error; - optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextTranslateAnchor(*typedValue); - return nullopt; - } - if (name == "text-translate-anchor-transition") { - Error error; - optional<TransitionOptions> transition = convert<TransitionOptions>(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextTranslateAnchorTransition) { setTextTranslateAnchorTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -1375,403 +1447,558 @@ optional<Error> SymbolLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + enum class Property { + Unknown, + SymbolPlacement, + SymbolSpacing, + SymbolAvoidEdges, + IconAllowOverlap, + IconIgnorePlacement, + IconOptional, + IconRotationAlignment, + IconSize, + IconTextFit, + IconTextFitPadding, + IconImage, + IconRotate, + IconPadding, + IconKeepUpright, + IconOffset, + IconAnchor, + IconPitchAlignment, + TextPitchAlignment, + TextRotationAlignment, + TextField, + TextFont, + TextSize, + TextMaxWidth, + TextLineHeight, + TextLetterSpacing, + TextJustify, + TextAnchor, + TextMaxAngle, + TextRotate, + TextPadding, + TextKeepUpright, + TextTransform, + TextOffset, + TextAllowOverlap, + TextIgnorePlacement, + TextOptional, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { - if (name == "symbol-placement") { - Error error; - optional<PropertyValue<SymbolPlacementType>> typedValue = convert<PropertyValue<SymbolPlacementType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("symbol-placement"): + if (name == "symbol-placement") { + property = Property::SymbolPlacement; } - - setSymbolPlacement(*typedValue); - return nullopt; - } + break; - if (name == "symbol-spacing") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("symbol-spacing"): + if (name == "symbol-spacing") { + property = Property::SymbolSpacing; } - - setSymbolSpacing(*typedValue); - return nullopt; - } + break; - if (name == "symbol-avoid-edges") { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("symbol-avoid-edges"): + if (name == "symbol-avoid-edges") { + property = Property::SymbolAvoidEdges; } - - setSymbolAvoidEdges(*typedValue); - return nullopt; - } + break; - if (name == "icon-allow-overlap") { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-allow-overlap"): + if (name == "icon-allow-overlap") { + property = Property::IconAllowOverlap; } - - setIconAllowOverlap(*typedValue); - return nullopt; - } + break; - if (name == "icon-ignore-placement") { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-ignore-placement"): + if (name == "icon-ignore-placement") { + property = Property::IconIgnorePlacement; } - - setIconIgnorePlacement(*typedValue); - return nullopt; - } + break; - if (name == "icon-optional") { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-optional"): + if (name == "icon-optional") { + property = Property::IconOptional; } - - setIconOptional(*typedValue); - return nullopt; - } + break; - if (name == "icon-rotation-alignment") { - Error error; - optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-rotation-alignment"): + if (name == "icon-rotation-alignment") { + property = Property::IconRotationAlignment; } - - setIconRotationAlignment(*typedValue); - return nullopt; - } + break; - if (name == "icon-size") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-size"): + if (name == "icon-size") { + property = Property::IconSize; } - - setIconSize(*typedValue); - return nullopt; - } + break; - if (name == "icon-text-fit") { - Error error; - optional<PropertyValue<IconTextFitType>> typedValue = convert<PropertyValue<IconTextFitType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-text-fit"): + if (name == "icon-text-fit") { + property = Property::IconTextFit; } - - setIconTextFit(*typedValue); - return nullopt; - } + break; - if (name == "icon-text-fit-padding") { - Error error; - optional<PropertyValue<std::array<float, 4>>> typedValue = convert<PropertyValue<std::array<float, 4>>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-text-fit-padding"): + if (name == "icon-text-fit-padding") { + property = Property::IconTextFitPadding; } - - setIconTextFitPadding(*typedValue); - return nullopt; - } + break; - if (name == "icon-image") { - Error error; - optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, true, true); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-image"): + if (name == "icon-image") { + property = Property::IconImage; } - - setIconImage(*typedValue); - return nullopt; - } + break; - if (name == "icon-rotate") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-rotate"): + if (name == "icon-rotate") { + property = Property::IconRotate; } - - setIconRotate(*typedValue); - return nullopt; - } + break; - if (name == "icon-padding") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-padding"): + if (name == "icon-padding") { + property = Property::IconPadding; } - - setIconPadding(*typedValue); - return nullopt; - } + break; - if (name == "icon-keep-upright") { - Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-keep-upright"): + if (name == "icon-keep-upright") { + property = Property::IconKeepUpright; } - - setIconKeepUpright(*typedValue); - return nullopt; - } + break; - if (name == "icon-offset") { - Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-offset"): + if (name == "icon-offset") { + property = Property::IconOffset; } - - setIconOffset(*typedValue); - return nullopt; - } + break; - if (name == "icon-anchor") { - Error error; - optional<PropertyValue<SymbolAnchorType>> typedValue = convert<PropertyValue<SymbolAnchorType>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-anchor"): + if (name == "icon-anchor") { + property = Property::IconAnchor; } - - setIconAnchor(*typedValue); - return nullopt; - } + break; - if (name == "icon-pitch-alignment") { - Error error; - optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("icon-pitch-alignment"): + if (name == "icon-pitch-alignment") { + property = Property::IconPitchAlignment; } - - setIconPitchAlignment(*typedValue); - return nullopt; - } + break; - if (name == "text-pitch-alignment") { - Error error; - optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("text-pitch-alignment"): + if (name == "text-pitch-alignment") { + property = Property::TextPitchAlignment; } - - setTextPitchAlignment(*typedValue); - return nullopt; - } + break; - if (name == "text-rotation-alignment") { - Error error; - optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); - if (!typedValue) { - return error; + case util::hashFNV1a("text-rotation-alignment"): + if (name == "text-rotation-alignment") { + property = Property::TextRotationAlignment; } - - setTextRotationAlignment(*typedValue); - return nullopt; - } + break; - if (name == "text-field") { - Error error; - optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, true, true); - if (!typedValue) { - return error; + case util::hashFNV1a("text-field"): + if (name == "text-field") { + property = Property::TextField; } - - setTextField(*typedValue); - return nullopt; - } + break; - if (name == "text-font") { - Error error; - optional<PropertyValue<std::vector<std::string>>> typedValue = convert<PropertyValue<std::vector<std::string>>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("text-font"): + if (name == "text-font") { + property = Property::TextFont; } - - setTextFont(*typedValue); - return nullopt; - } + break; - if (name == "text-size") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("text-size"): + if (name == "text-size") { + property = Property::TextSize; } - - setTextSize(*typedValue); - return nullopt; - } + break; - if (name == "text-max-width") { - Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); - if (!typedValue) { - return error; + case util::hashFNV1a("text-max-width"): + if (name == "text-max-width") { + property = Property::TextMaxWidth; + } + break; + + case util::hashFNV1a("text-line-height"): + if (name == "text-line-height") { + property = Property::TextLineHeight; + } + break; + + case util::hashFNV1a("text-letter-spacing"): + if (name == "text-letter-spacing") { + property = Property::TextLetterSpacing; + } + break; + + case util::hashFNV1a("text-justify"): + if (name == "text-justify") { + property = Property::TextJustify; + } + break; + + case util::hashFNV1a("text-anchor"): + if (name == "text-anchor") { + property = Property::TextAnchor; + } + break; + + case util::hashFNV1a("text-max-angle"): + if (name == "text-max-angle") { + property = Property::TextMaxAngle; + } + break; + + case util::hashFNV1a("text-rotate"): + if (name == "text-rotate") { + property = Property::TextRotate; + } + break; + + case util::hashFNV1a("text-padding"): + if (name == "text-padding") { + property = Property::TextPadding; + } + break; + + case util::hashFNV1a("text-keep-upright"): + if (name == "text-keep-upright") { + property = Property::TextKeepUpright; + } + break; + + case util::hashFNV1a("text-transform"): + if (name == "text-transform") { + property = Property::TextTransform; + } + break; + + case util::hashFNV1a("text-offset"): + if (name == "text-offset") { + property = Property::TextOffset; + } + break; + + case util::hashFNV1a("text-allow-overlap"): + if (name == "text-allow-overlap") { + property = Property::TextAllowOverlap; + } + break; + + case util::hashFNV1a("text-ignore-placement"): + if (name == "text-ignore-placement") { + property = Property::TextIgnorePlacement; + } + break; + + case util::hashFNV1a("text-optional"): + if (name == "text-optional") { + property = Property::TextOptional; } + break; + + } - setTextMaxWidth(*typedValue); - return nullopt; + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; } - - if (name == "text-line-height") { + + + if (property == Property::SymbolPlacement) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + optional<PropertyValue<SymbolPlacementType>> typedValue = convert<PropertyValue<SymbolPlacementType>>(value, error, false, false); if (!typedValue) { return error; } - - setTextLineHeight(*typedValue); + + setSymbolPlacement(*typedValue); return nullopt; + } - if (name == "text-letter-spacing") { + if (property == Property::SymbolSpacing || property == Property::IconPadding || property == Property::TextLineHeight || property == Property::TextMaxAngle || property == Property::TextPadding) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); if (!typedValue) { return error; } - - setTextLetterSpacing(*typedValue); - return nullopt; + + if (property == Property::SymbolSpacing) { + setSymbolSpacing(*typedValue); + return nullopt; + } + + if (property == Property::IconPadding) { + setIconPadding(*typedValue); + return nullopt; + } + + if (property == Property::TextLineHeight) { + setTextLineHeight(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxAngle) { + setTextMaxAngle(*typedValue); + return nullopt; + } + + if (property == Property::TextPadding) { + setTextPadding(*typedValue); + return nullopt; + } + } - if (name == "text-justify") { + if (property == Property::SymbolAvoidEdges || property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || property == Property::IconOptional || property == Property::IconKeepUpright || property == Property::TextKeepUpright || property == Property::TextAllowOverlap || property == Property::TextIgnorePlacement || property == Property::TextOptional) { Error error; - optional<PropertyValue<TextJustifyType>> typedValue = convert<PropertyValue<TextJustifyType>>(value, error, true, false); + optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); if (!typedValue) { return error; } - - setTextJustify(*typedValue); - return nullopt; + + if (property == Property::SymbolAvoidEdges) { + setSymbolAvoidEdges(*typedValue); + return nullopt; + } + + if (property == Property::IconAllowOverlap) { + setIconAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::IconIgnorePlacement) { + setIconIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::IconOptional) { + setIconOptional(*typedValue); + return nullopt; + } + + if (property == Property::IconKeepUpright) { + setIconKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextKeepUpright) { + setTextKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextAllowOverlap) { + setTextAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::TextIgnorePlacement) { + setTextIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::TextOptional) { + setTextOptional(*typedValue); + return nullopt; + } + } - if (name == "text-anchor") { + if (property == Property::IconRotationAlignment || property == Property::IconPitchAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { Error error; - optional<PropertyValue<SymbolAnchorType>> typedValue = convert<PropertyValue<SymbolAnchorType>>(value, error, true, false); + optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false); if (!typedValue) { return error; } - - setTextAnchor(*typedValue); - return nullopt; + + if (property == Property::IconRotationAlignment) { + setIconRotationAlignment(*typedValue); + return nullopt; + } + + if (property == Property::IconPitchAlignment) { + setIconPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextPitchAlignment) { + setTextPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextRotationAlignment) { + setTextRotationAlignment(*typedValue); + return nullopt; + } + } - if (name == "text-max-angle") { + if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRotate) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); if (!typedValue) { return error; } - - setTextMaxAngle(*typedValue); - return nullopt; + + if (property == Property::IconSize) { + setIconSize(*typedValue); + return nullopt; + } + + if (property == Property::IconRotate) { + setIconRotate(*typedValue); + return nullopt; + } + + if (property == Property::TextSize) { + setTextSize(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxWidth) { + setTextMaxWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextLetterSpacing) { + setTextLetterSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextRotate) { + setTextRotate(*typedValue); + return nullopt; + } + } - if (name == "text-rotate") { + if (property == Property::IconTextFit) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false); + optional<PropertyValue<IconTextFitType>> typedValue = convert<PropertyValue<IconTextFitType>>(value, error, false, false); if (!typedValue) { return error; } - - setTextRotate(*typedValue); + + setIconTextFit(*typedValue); return nullopt; + } - if (name == "text-padding") { + if (property == Property::IconTextFitPadding) { Error error; - optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false); + optional<PropertyValue<std::array<float, 4>>> typedValue = convert<PropertyValue<std::array<float, 4>>>(value, error, false, false); if (!typedValue) { return error; } - - setTextPadding(*typedValue); + + setIconTextFitPadding(*typedValue); return nullopt; + } - if (name == "text-keep-upright") { + if (property == Property::IconImage || property == Property::TextField) { Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); + optional<PropertyValue<std::string>> typedValue = convert<PropertyValue<std::string>>(value, error, true, true); if (!typedValue) { return error; } - - setTextKeepUpright(*typedValue); - return nullopt; + + if (property == Property::IconImage) { + setIconImage(*typedValue); + return nullopt; + } + + if (property == Property::TextField) { + setTextField(*typedValue); + return nullopt; + } + } - if (name == "text-transform") { + if (property == Property::IconOffset || property == Property::TextOffset) { Error error; - optional<PropertyValue<TextTransformType>> typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false); + optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, true, false); if (!typedValue) { return error; } - - setTextTransform(*typedValue); - return nullopt; + + if (property == Property::IconOffset) { + setIconOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextOffset) { + setTextOffset(*typedValue); + return nullopt; + } + } - if (name == "text-offset") { + if (property == Property::IconAnchor || property == Property::TextAnchor) { Error error; - optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, true, false); + optional<PropertyValue<SymbolAnchorType>> typedValue = convert<PropertyValue<SymbolAnchorType>>(value, error, true, false); if (!typedValue) { return error; } - - setTextOffset(*typedValue); - return nullopt; + + if (property == Property::IconAnchor) { + setIconAnchor(*typedValue); + return nullopt; + } + + if (property == Property::TextAnchor) { + setTextAnchor(*typedValue); + return nullopt; + } + } - if (name == "text-allow-overlap") { + if (property == Property::TextFont) { Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); + optional<PropertyValue<std::vector<std::string>>> typedValue = convert<PropertyValue<std::vector<std::string>>>(value, error, true, false); if (!typedValue) { return error; } - - setTextAllowOverlap(*typedValue); + + setTextFont(*typedValue); return nullopt; + } - if (name == "text-ignore-placement") { + if (property == Property::TextJustify) { Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); + optional<PropertyValue<TextJustifyType>> typedValue = convert<PropertyValue<TextJustifyType>>(value, error, true, false); if (!typedValue) { return error; } - - setTextIgnorePlacement(*typedValue); + + setTextJustify(*typedValue); return nullopt; + } - if (name == "text-optional") { + if (property == Property::TextTransform) { Error error; - optional<PropertyValue<bool>> typedValue = convert<PropertyValue<bool>>(value, error, false, false); + optional<PropertyValue<TextTransformType>> typedValue = convert<PropertyValue<TextTransformType>>(value, error, true, false); if (!typedValue) { return error; } - - setTextOptional(*typedValue); + + setTextTransform(*typedValue); return nullopt; + } + return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/util/fnv_hash.hpp b/src/mbgl/util/fnv_hash.hpp new file mode 100644 index 0000000000..87d4661c56 --- /dev/null +++ b/src/mbgl/util/fnv_hash.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace mbgl { +namespace util { + +inline constexpr uint64_t hashFNV1a(const char * str, uint64_t value = 0xcbf29ce484222325) { + return str[0] ? hashFNV1a(str + 1, (value ^ uint64_t(str[0])) * 0x100000001b3) : value; +} + +} // end namespace util +} // end namespace mbgl |