summaryrefslogtreecommitdiff
path: root/src/mbgl/style/expression
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/expression')
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp29
-rw-r--r--src/mbgl/style/expression/expression.cpp10
2 files changed, 20 insertions, 19 deletions
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index cc1d58025b..53512ce89e 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -234,8 +234,12 @@ Value featureIdAsExpressionValue(EvaluationContext params) {
optional<Value> featurePropertyAsExpressionValue(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- return property ? toExpressionValue(*property) : optional<Value>();
+ const PropertyMap& properties = params.feature->getProperties();
+ const auto it = properties.find(key);
+ if (it == properties.cend()) {
+ return optional<Value>();
+ }
+ return toExpressionValue(it->second);
};
optional<std::string> featureTypeAsString(FeatureType type) {
@@ -255,9 +259,7 @@ optional<std::string> featureTypeAsString(FeatureType type) {
optional<double> featurePropertyAsDouble(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- if (!property) return {};
- return property->match(
+ return params.feature->getValue(key).match(
[](double value) { return value; },
[](uint64_t value) { return optional<double>(static_cast<double>(value)); },
[](int64_t value) { return optional<double>(static_cast<double>(value)); },
@@ -267,9 +269,7 @@ optional<double> featurePropertyAsDouble(EvaluationContext params, const std::st
optional<std::string> featurePropertyAsString(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- if (!property) return {};
- return property->match(
+ return params.feature->getValue(key).match(
[](std::string value) { return value; },
[](auto) { return optional<std::string>(); }
);
@@ -376,7 +376,8 @@ const auto& hasContextCompoundExpression() {
};
}
- return params.feature->getValue(key) ? true : false;
+ const PropertyMap& properties = params.feature->getProperties();
+ return properties.find(key) != properties.cend();
});
return signature;
}
@@ -396,11 +397,12 @@ const auto& getContextCompoundExpression() {
};
}
- auto propertyValue = params.feature->getValue(key);
- if (!propertyValue) {
+ const PropertyMap& properties = params.feature->getProperties();
+ const auto it = properties.find(key);
+ if (it == properties.cend()) {
return Null;
}
- return Value(toExpressionValue(*propertyValue));
+ return toExpressionValue(it->second);
});
return signature;
}
@@ -817,7 +819,8 @@ const auto& filterIdGreaterOrEqualThanStringCompoundExpression() {
const auto& filterHasCompoundExpression() {
static auto signature = detail::makeSignature("filter-has", [](const EvaluationContext& params, const std::string& key) -> Result<bool> {
assert(params.feature);
- return bool(params.feature->getValue(key));
+ const PropertyMap& properties = params.feature->getProperties();
+ return properties.find(key) != properties.cend();
});
return signature;
}
diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp
index bb03bcc2e5..8b61aef7ca 100644
--- a/src/mbgl/style/expression/expression.cpp
+++ b/src/mbgl/style/expression/expression.cpp
@@ -2,6 +2,8 @@
#include <mbgl/style/expression/compound_expression.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/util/feature.hpp>
+
namespace mbgl {
namespace style {
namespace expression {
@@ -18,12 +20,8 @@ public:
const PropertyMap& getProperties() const override { return feature.properties; }
FeatureIdentifier getID() const override { return feature.id; }
GeometryCollection getGeometries() const override { return {}; }
- optional<mbgl::Value> getValue(const std::string& key) const override {
- auto it = feature.properties.find(key);
- if (it != feature.properties.end()) {
- return optional<mbgl::Value>(it->second);
- }
- return optional<mbgl::Value>();
+ mbgl::Value getValue(const std::string& key) const override {
+ return feature.properties.count(key) ? feature.properties.at(key) : NullValue();
}
};