summaryrefslogtreecommitdiff
path: root/include/mbgl
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-07-15 16:07:42 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-07-18 12:37:36 -0700
commitda35ef9f49139f4dfc7eb5ea2a04f800e895a65f (patch)
treeb054fff3e07d7a6480059b9ae02910b3580f311c /include/mbgl
parentb03471bc8d2658464aacf02e043ef289e9d6e947 (diff)
downloadqtlocation-mapboxgl-da35ef9f49139f4dfc7eb5ea2a04f800e895a65f.tar.gz
[core] Add support for $id key to filters
https://github.com/mapbox/mapbox-gl-style-spec/issues/391
Diffstat (limited to 'include/mbgl')
-rw-r--r--include/mbgl/style/filter.hpp4
-rw-r--r--include/mbgl/style/filter_evaluator.hpp30
-rw-r--r--include/mbgl/util/feature.hpp6
3 files changed, 29 insertions, 11 deletions
diff --git a/include/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp
index 6a5afb7b47..dd2b20cd0d 100644
--- a/include/mbgl/style/filter.hpp
+++ b/include/mbgl/style/filter.hpp
@@ -107,8 +107,10 @@ class Filter : public FilterBase {
public:
using FilterBase::FilterBase;
+ bool operator()(const Feature&) const;
+
template <class PropertyAccessor>
- bool operator()(FeatureType type, PropertyAccessor accessor) const;
+ bool operator()(FeatureType type, optional<FeatureIdentifier> id, PropertyAccessor accessor) const;
};
} // namespace style
diff --git a/include/mbgl/style/filter_evaluator.hpp b/include/mbgl/style/filter_evaluator.hpp
index cf91fdab1f..793abe6da0 100644
--- a/include/mbgl/style/filter_evaluator.hpp
+++ b/include/mbgl/style/filter_evaluator.hpp
@@ -26,6 +26,7 @@ template <class PropertyAccessor>
class FilterEvaluator {
public:
const FeatureType featureType;
+ const optional<FeatureIdentifier> featureIdentifier;
const PropertyAccessor propertyAccessor;
bool operator()(const NullFilter&) const {
@@ -123,9 +124,19 @@ public:
private:
optional<Value> getValue(const std::string& key_) const {
- return key_ == "$type"
- ? optional<Value>(uint64_t(featureType))
- : propertyAccessor(key_);
+ if (key_ == "$type") {
+ return optional<Value>(uint64_t(featureType));
+ } else if (key_ == "$id") {
+ if (featureIdentifier) {
+ return FeatureIdentifier::visit(*featureIdentifier, [] (auto id) {
+ return Value(std::move(id));
+ });
+ } else {
+ return optional<Value>();
+ }
+ } else {
+ return propertyAccessor(key_);
+ }
}
template <class Op>
@@ -183,9 +194,18 @@ private:
}
};
+inline bool Filter::operator()(const Feature& feature) const {
+ return operator()(apply_visitor(ToFeatureType(), feature.geometry), feature.id, [&] (const std::string& key) -> optional<Value> {
+ auto it = feature.properties.find(key);
+ if (it == feature.properties.end())
+ return {};
+ return it->second;
+ });
+}
+
template <class PropertyAccessor>
-bool Filter::operator()(FeatureType type, PropertyAccessor accessor) const {
- return FilterBase::visit(*this, FilterEvaluator<PropertyAccessor> { type, accessor });
+bool Filter::operator()(FeatureType type, optional<FeatureIdentifier> id, PropertyAccessor accessor) const {
+ return FilterBase::visit(*this, FilterEvaluator<PropertyAccessor> { type, id, accessor });
}
} // namespace style
diff --git a/include/mbgl/util/feature.hpp b/include/mbgl/util/feature.hpp
index 7c5c8d7625..b72aa15ddd 100644
--- a/include/mbgl/util/feature.hpp
+++ b/include/mbgl/util/feature.hpp
@@ -10,10 +10,6 @@ using Value = mapbox::geometry::value;
using NullValue = mapbox::geometry::null_value_t;
using PropertyMap = mapbox::geometry::property_map;
using FeatureIdentifier = mapbox::geometry::identifier;
-class Feature : public mapbox::geometry::feature<double> {
-public:
- Feature(geometry_type&& geometry_)
- : mapbox::geometry::feature<double> { std::move(geometry_) } {}
-};
+using Feature = mapbox::geometry::feature<double>;
} // namespace mbgl