blob: 4c4684c86ad883d755ec0d432581519e61208808 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include <mbgl/style/expression/is_constant.hpp>
#include <mbgl/style/expression/collator_expression.hpp>
namespace mbgl {
namespace style {
namespace expression {
constexpr static const char filter[] = "filter-";
bool isFeatureConstant(const Expression& expression) {
if (expression.getKind() == Kind::CompoundExpression) {
auto e = static_cast<const CompoundExpression*>(&expression);
const std::string name = e->getOperator();
optional<std::size_t> parameterCount = e->getParameterCount();
if (name == "get" && parameterCount && *parameterCount == 1) {
return false;
} else if (name == "has" && parameterCount && *parameterCount == 1) {
return false;
} else if (name == "properties" || name == "geometry-type" || name == "id" || name == "feature-state") {
return false;
} else if (0u == name.rfind(filter, 0u)) {
// Legacy filters begin with "filter-" and are never constant.
return false;
}
}
if (expression.getKind() == Kind::FormatSectionOverride) {
return false;
}
if (expression.getKind() == Kind::CollatorExpression) {
// Although the results of a Collator expression with fixed arguments
// generally shouldn't change between executions, we can't serialize them
// as constant expressions because results change based on environment.
return false;
}
bool featureConstant = true;
expression.eachChild([&](const Expression& e) {
if (featureConstant && !isFeatureConstant(e)) {
featureConstant = false;
}
});
return featureConstant;
}
bool isZoomConstant(const Expression& e) {
return isGlobalPropertyConstant(e, std::array<std::string, 1>{{"zoom"}});
}
} // namespace expression
} // namespace style
} // namespace mbgl
|