Don't enforce ["zoom"] constraints for filters (#11672)
* Don't enforce ["zoom"] constraints for filters Fixes #11594 * Add a couple of comments * Fix ambiguous constructor call * ParsingContext(optional<Type>) => ParsingContext(Type)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/util/geometry.hpp>
|
||||
#include <mbgl/style/expression/expression.hpp>
|
||||
#include <mbgl/style/expression/type.hpp>
|
||||
#include <mbgl/style/conversion/expression.hpp>
|
||||
#include <mbgl/style/expression/parsing_context.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -236,10 +236,13 @@ optional<Filter> convertCompoundFilter(const Convertible& value, Error& error) {
|
||||
}
|
||||
|
||||
optional<Filter> convertExpressionFilter(const Convertible& value, Error& error) {
|
||||
optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(value, error, expression::type::Boolean);
|
||||
expression::ParsingContext ctx(expression::type::Boolean);
|
||||
expression::ParseResult expression = ctx.parseExpression(value);
|
||||
if (!expression) {
|
||||
error = { ctx.getCombinedErrors() };
|
||||
return {};
|
||||
}
|
||||
|
||||
return { ExpressionFilter { std::move(*expression) } };
|
||||
}
|
||||
|
||||
|
||||
@@ -206,8 +206,16 @@ ParseResult ParsingContext::parse(const Convertible& value, TypeAnnotationOption
|
||||
}
|
||||
}
|
||||
|
||||
// if this is the root expression, enforce constraints on the use ["zoom"].
|
||||
if (key.size() == 0 && !isZoomConstant(**parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
ParseResult ParsingContext::parseExpression(const Convertible& value, TypeAnnotationOption typeAnnotationOption) {
|
||||
return parse(value, typeAnnotationOption);
|
||||
}
|
||||
|
||||
ParseResult ParsingContext::parseLayerPropertyExpression(const Convertible& value, TypeAnnotationOption typeAnnotationOption) {
|
||||
ParseResult parsed = parse(value, typeAnnotationOption);
|
||||
if (parsed && !isZoomConstant(**parsed)) {
|
||||
optional<variant<const InterpolateBase*, const Step*, ParsingError>> zoomCurve = findZoomCurve(parsed->get());
|
||||
if (!zoomCurve) {
|
||||
error(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)");
|
||||
@@ -217,10 +225,23 @@ ParseResult ParsingContext::parse(const Convertible& value, TypeAnnotationOption
|
||||
return ParseResult();
|
||||
}
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
const std::string ParsingContext::getCombinedErrors() const {
|
||||
std::string combinedError;
|
||||
for (const ParsingError& parsingError : *errors) {
|
||||
if (combinedError.size() > 0) {
|
||||
combinedError += "\n";
|
||||
}
|
||||
if (parsingError.key.size() > 0) {
|
||||
combinedError += parsingError.key + ": ";
|
||||
}
|
||||
combinedError += parsingError.message;
|
||||
}
|
||||
return combinedError;
|
||||
}
|
||||
|
||||
optional<std::string> ParsingContext::checkType(const type::Type& t) {
|
||||
assert(expected);
|
||||
optional<std::string> err = type::checkSubtype(*expected, t);
|
||||
|
||||
Reference in New Issue
Block a user