Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Accept constant expressions in non-dds properties (#11960)
Browse files Browse the repository at this point in the history
Closes #11940
  • Loading branch information
anandthakker committed May 23, 2018
1 parent ed1f857 commit 464fefa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions include/mbgl/style/conversion/property_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions test/style/conversion/property_value.test.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 464fefa

Please sign in to comment.