From f6e79d70735361438655f279c8699a786d25458c Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Thu, 27 Apr 2017 15:56:55 -0700 Subject: [core] Render fill-extrusion layers (#8431) --- include/mbgl/style/conversion/constant.hpp | 49 ++++-------- include/mbgl/style/conversion/layer.hpp | 3 + include/mbgl/style/conversion/light.hpp | 122 +++++++++++++++++++++++++++++ include/mbgl/style/conversion/position.hpp | 29 +++++++ 4 files changed, 169 insertions(+), 34 deletions(-) create mode 100644 include/mbgl/style/conversion/light.hpp create mode 100644 include/mbgl/style/conversion/position.hpp (limited to 'include/mbgl/style/conversion') diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp index 1e1fdc2ee8..07c0a35fae 100644 --- a/include/mbgl/style/conversion/constant.hpp +++ b/include/mbgl/style/conversion/constant.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -92,45 +93,25 @@ struct Converter { } }; -template <> -struct Converter> { +template +struct Converter> { template - optional> operator()(const V& value, Error& error) const { - if (!isArray(value) || arrayLength(value) != 2) { - error = { "value must be an array of two numbers" }; + optional> operator()(const V& value, Error& error) const { + if (!isArray(value) || arrayLength(value) != N) { + error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; } - optional first = toNumber(arrayMember(value, 0)); - optional second = toNumber(arrayMember(value, 1)); - if (!first || !second) { - error = { "value must be an array of two numbers" }; - return {}; - } - - return std::array {{ *first, *second }}; - } -}; - -template <> -struct Converter> { - template - optional> operator()(const V& value, Error& error) const { - if (!isArray(value) || arrayLength(value) != 4) { - error = { "value must be an array of four numbers" }; - return {}; - } - - optional first = toNumber(arrayMember(value, 0)); - optional second = toNumber(arrayMember(value, 1)); - optional third = toNumber(arrayMember(value, 2)); - optional fourth = toNumber(arrayMember(value, 3)); - if (!first || !second) { - error = { "value must be an array of four numbers" }; - return {}; + std::array result; + for (size_t i = 0; i < N; i++) { + optional n = toNumber(arrayMember(value, i)); + if (!n) { + error = { "value must be an array of " + util::toString(N) + " numbers" }; + return {}; + } + result[i] = *n; } - - return std::array {{ *first, *second, *third, *fourth }}; + return result; } }; diff --git a/include/mbgl/style/conversion/layer.hpp b/include/mbgl/style/conversion/layer.hpp index efb1df8fef..3a64c36bf5 100644 --- a/include/mbgl/style/conversion/layer.hpp +++ b/include/mbgl/style/conversion/layer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -92,6 +93,8 @@ public: if (*type == "fill") { converted = convertVectorLayer(*id, value, error); + } else if (*type == "fill-extrusion") { + converted = convertVectorLayer(*id, value, error); } else if (*type == "line") { converted = convertVectorLayer(*id, value, error); } else if (*type == "circle") { diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp new file mode 100644 index 0000000000..631ed04ccb --- /dev/null +++ b/include/mbgl/style/conversion/light.hpp @@ -0,0 +1,122 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { +public: + template + optional operator()(const V& value, Error& error) const { + if (!isObject(value)) { + error = { "light must be an object" }; + return {}; + } + + Light light; + + const auto anchor = objectMember(value, "anchor"); + if (anchor) { + optional> convertedAnchor = + convert>(*anchor, error); + + if (convertedAnchor) { + light.get().value = *convertedAnchor; + } else { + return {}; + } + } + + const auto anchorTransition = objectMember(value, "anchor-transition"); + if (anchorTransition) { + optional transition = + convert(*anchorTransition, error); + if (transition) { + light.get().transition = *transition; + } else { + return {}; + } + } + + const auto color = objectMember(value, "color"); + if (color) { + optional> convertedColor = + convert>(*color, error); + + if (convertedColor) { + light.get().value = *convertedColor; + } else { + return {}; + } + } + + const auto colorTransition = objectMember(value, "color-transition"); + if (colorTransition) { + optional transition = + convert(*colorTransition, error); + if (transition) { + light.get().transition = *transition; + } else { + return {}; + } + } + + const auto position = objectMember(value, "position"); + if (position) { + optional> convertedPosition = + convert>(*position, error); + + if (convertedPosition) { + light.get().value = *convertedPosition; + } else { + return {}; + } + } + + const auto positionTransition = objectMember(value, "position-transition"); + if (positionTransition) { + optional transition = + convert(*positionTransition, error); + if (transition) { + light.get().transition = *transition; + } else { + return {}; + } + } + + const auto intensity = objectMember(value, "intensity"); + if (intensity) { + optional> convertedIntensity = + convert>(*intensity, error); + + if (convertedIntensity) { + light.get().value = *convertedIntensity; + } else { + return {}; + } + } + + const auto intensityTransition = objectMember(value, "intensity-transition"); + if (intensityTransition) { + optional transition = + convert(*intensityTransition, error); + if (transition) { + light.get().transition = *transition; + } else { + return {}; + } + } + return { light }; + }; +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/position.hpp b/include/mbgl/style/conversion/position.hpp new file mode 100644 index 0000000000..7036b03822 --- /dev/null +++ b/include/mbgl/style/conversion/position.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { + template + optional operator()(const V& value, Error& error) const { + optional> spherical = convert>(value, error); + + if (!spherical) { + return {}; + } + + return Position(*spherical); + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl -- cgit v1.2.1