Accept constant expressions in non-dds properties (#11960)

Closes #11940
This commit is contained in:
Anand Thakker
2018-05-23 09:54:49 -04:00
committed by GitHub
parent ed1f85700c
commit 464fefab18
3 changed files with 33 additions and 3 deletions

View File

@@ -79,6 +79,7 @@ set(MBGL_TEST_FILES
test/style/conversion/geojson_options.test.cpp
test/style/conversion/layer.test.cpp
test/style/conversion/light.test.cpp
test/style/conversion/property_value.test.cpp
test/style/conversion/stringify.test.cpp
test/style/conversion/tileset.test.cpp

View File

@@ -29,11 +29,19 @@ struct Converter<PropertyValue<T>> {
return {};
}
if (isFeatureConstant(**expression)) {
return { CameraFunction<T>(std::move(*expression)) };
} else {
if (!isFeatureConstant(**expression)) {
error = { "property expressions not supported" };
return {};
} else if (!isZoomConstant(**expression)) {
return { CameraFunction<T>(std::move(*expression)) };
} else {
auto literal = dynamic_cast<Literal*>(expression->get());
assert(literal);
optional<T> constant = fromExpressionValue<T>(literal->getValue());
if (!constant) {
return {};
}
return PropertyValue<T>(*constant);
}
} else if (isObject(value)) {
optional<CameraFunction<T>> function = convert<CameraFunction<T>>(value, error);

View File

@@ -0,0 +1,21 @@
#include <mbgl/test/util.hpp>
#include <mbgl/style/conversion/json.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/util/rapidjson.hpp>
using namespace mbgl;
using namespace mbgl::style;
using namespace mbgl::style::conversion;
TEST(StyleConversion, PropertyValue) {
// PropertyValue<T> accepts a constant expression: https://github.com/mapbox/mapbox-gl-native/issues/11940
Error error;
JSDocument doc;
doc.Parse<0>(R"(["literal", [1, 2]])");
auto expected = std::array<float, 2>{{1, 2}};
auto result = convert<PropertyValue<std::array<float, 2>>>(doc, error);
ASSERT_TRUE(result);
ASSERT_TRUE(result->isConstant());
ASSERT_EQ(result->asConstant(), expected);
}