diff options
author | Jesse Crocker <jesse@gaiagps.com> | 2017-03-01 11:15:11 -0700 |
---|---|---|
committer | Jesse Crocker <jesse@gaiagps.com> | 2017-03-01 11:15:11 -0700 |
commit | 9e8dc9a9e3e86adb9987ae69766cc42c7d9efece (patch) | |
tree | f5f0abd4d342c89ad0405d01969f9d6caecc1c90 /src/mbgl/style/function | |
parent | 16fb0672e64a72b7400c321d55858b73cd5d8c3f (diff) | |
parent | f28d75dccd9bf4a7615df87faccc5cf5eff8df89 (diff) | |
download | qtlocation-mapboxgl-9e8dc9a9e3e86adb9987ae69766cc42c7d9efece.tar.gz |
Merge remote-tracking branch 'origin/master' into feature/custom-vector-source
Diffstat (limited to 'src/mbgl/style/function')
-rw-r--r-- | src/mbgl/style/function/categorical_stops.cpp | 38 | ||||
-rw-r--r-- | src/mbgl/style/function/identity_stops.cpp | 61 |
2 files changed, 99 insertions, 0 deletions
diff --git a/src/mbgl/style/function/categorical_stops.cpp b/src/mbgl/style/function/categorical_stops.cpp new file mode 100644 index 0000000000..2984c3832f --- /dev/null +++ b/src/mbgl/style/function/categorical_stops.cpp @@ -0,0 +1,38 @@ +#include <mbgl/style/function/categorical_stops.hpp> +#include <mbgl/style/types.hpp> +#include <mbgl/util/color.hpp> + +#include <array> + +namespace mbgl { +namespace style { + +optional<CategoricalValue> categoricalValue(const Value& value) { + return value.match( + [] (bool t) { return optional<CategoricalValue>(t); }, + [] (uint64_t t) { return optional<CategoricalValue>(int64_t(t)); }, + [] (int64_t t) { return optional<CategoricalValue>(t); }, + [] (double t) { return optional<CategoricalValue>(int64_t(t)); }, + [] (const std::string& t) { return optional<CategoricalValue>(t); }, + [] (const auto&) { return optional<CategoricalValue>(); } + ); +} + +template <class T> +optional<T> CategoricalStops<T>::evaluate(const Value& value) const { + auto v = categoricalValue(value); + if (!v) { + return {}; + } + auto it = stops.find(*v); + return it == stops.end() ? optional<T>() : it->second; +} + +template class CategoricalStops<float>; +template class CategoricalStops<Color>; +template class CategoricalStops<std::array<float, 2>>; +template class CategoricalStops<std::string>; +template class CategoricalStops<TextTransformType>; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/function/identity_stops.cpp b/src/mbgl/style/function/identity_stops.cpp new file mode 100644 index 0000000000..dfb34e9dd4 --- /dev/null +++ b/src/mbgl/style/function/identity_stops.cpp @@ -0,0 +1,61 @@ +#include <mbgl/style/function/identity_stops.hpp> +#include <mbgl/style/types.hpp> +#include <mbgl/util/enum.hpp> +#include <mbgl/util/color.hpp> + +#include <array> + +namespace mbgl { +namespace style { + +template <> +optional<float> IdentityStops<float>::evaluate(const Value& value) const { + return numericValue<float>(value); +} + +template <> +optional<std::string> IdentityStops<std::string>::evaluate(const Value& value) const { + if (!value.is<std::string>()) { + return {}; + } + + return value.get<std::string>(); +} + +template <> +optional<Color> IdentityStops<Color>::evaluate(const Value& value) const { + if (!value.is<std::string>()) { + return {}; + } + + return Color::parse(value.get<std::string>()); +} + +template <> +optional<TextTransformType> IdentityStops<TextTransformType>::evaluate(const Value& value) const { + if (!value.is<std::string>()) { + return {}; + } + + return Enum<TextTransformType>::toEnum(value.get<std::string>()); +} + +template <> +optional<std::array<float, 2>> IdentityStops<std::array<float, 2>>::evaluate(const Value& value) const { + if (!value.is<std::vector<Value>>()) { + return {}; + } + + const std::vector<Value>& vector = value.get<std::vector<Value>>(); + if (vector.size() != 2 || !numericValue<float>(vector[0]) || !numericValue<float>(vector[1])) { + return {}; + } + + return {{{ + *numericValue<float>(vector[0]), + *numericValue<float>(vector[1]) + }}}; +} + +} // namespace style +} // namespace mbgl |