summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
authorAsheem Mamoowala <asheemm@gmail.com>2017-02-21 18:34:45 -0800
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-03-04 15:42:07 -0800
commit60d10dd27df38ac4e97214d1cd514198c381695c (patch)
treef4ce0ecbf3a7eeb5c19f994d02152fc624b458d9 /src/mbgl/geometry
parentac4e13416a36905b35401fc1a982c680ca37a3d0 (diff)
downloadqtlocation-mapboxgl-60d10dd27df38ac4e97214d1cd514198c381695c.tar.gz
[core] Add support for queryRenderedFeatures filter
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/feature_index.cpp19
-rw-r--r--src/mbgl/geometry/feature_index.hpp6
2 files changed, 17 insertions, 8 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp
index 5019d888ca..64fb7bd247 100644
--- a/src/mbgl/geometry/feature_index.cpp
+++ b/src/mbgl/geometry/feature_index.cpp
@@ -7,6 +7,9 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/math/minmax.hpp>
+#include <mbgl/map/query.hpp>
+#include <mbgl/style/filter.hpp>
+#include <mbgl/style/filter_evaluator.hpp>
#include <mapbox/geometry/envelope.hpp>
@@ -56,7 +59,7 @@ void FeatureIndex::query(
const float bearing,
const double tileSize,
const double scale,
- const optional<std::vector<std::string>>& filterLayerIDs,
+ const QueryOptions& queryOptions,
const GeometryTileData& geometryTileData,
const CanonicalTileID& tileID,
const style::Style& style,
@@ -76,7 +79,7 @@ void FeatureIndex::query(
if (indexedFeature.sortIndex == previousSortIndex) continue;
previousSortIndex = indexedFeature.sortIndex;
- addFeature(result, indexedFeature, queryGeometry, filterLayerIDs, geometryTileData, tileID, style, bearing, pixelsToTileUnits);
+ addFeature(result, indexedFeature, queryGeometry, queryOptions, geometryTileData, tileID, style, bearing, pixelsToTileUnits);
}
// Query symbol features, if they've been placed.
@@ -87,7 +90,7 @@ void FeatureIndex::query(
std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(queryGeometry, scale);
std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols);
for (const auto& symbolFeature : symbolFeatures) {
- addFeature(result, symbolFeature, queryGeometry, filterLayerIDs, geometryTileData, tileID, style, bearing, pixelsToTileUnits);
+ addFeature(result, symbolFeature, queryGeometry, queryOptions, geometryTileData, tileID, style, bearing, pixelsToTileUnits);
}
}
@@ -95,7 +98,7 @@ void FeatureIndex::addFeature(
std::unordered_map<std::string, std::vector<Feature>>& result,
const IndexedSubfeature& indexedFeature,
const GeometryCoordinates& queryGeometry,
- const optional<std::vector<std::string>>& filterLayerIDs,
+ const QueryOptions& options,
const GeometryTileData& geometryTileData,
const CanonicalTileID& tileID,
const style::Style& style,
@@ -103,7 +106,7 @@ void FeatureIndex::addFeature(
const float pixelsToTileUnits) const {
auto& layerIDs = bucketLayerIDs.at(indexedFeature.bucketName);
- if (filterLayerIDs && !vectorsIntersect(layerIDs, *filterLayerIDs)) {
+ if (options.layerIDs && !vectorsIntersect(layerIDs, *options.layerIDs)) {
return;
}
@@ -114,7 +117,7 @@ void FeatureIndex::addFeature(
assert(geometryTileFeature);
for (const auto& layerID : layerIDs) {
- if (filterLayerIDs && !vectorContains(*filterLayerIDs, layerID)) {
+ if (options.layerIDs && !vectorContains(*options.layerIDs, layerID)) {
continue;
}
@@ -125,6 +128,10 @@ void FeatureIndex::addFeature(
continue;
}
+ if (options.filter && !(*options.filter)(*geometryTileFeature)) {
+ continue;
+ }
+
result[layerID].push_back(convertFeature(*geometryTileFeature, tileID));
}
}
diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp
index ca813f4b6b..d2f68fd103 100644
--- a/src/mbgl/geometry/feature_index.hpp
+++ b/src/mbgl/geometry/feature_index.hpp
@@ -11,6 +11,8 @@
namespace mbgl {
+class QueryOptions;
+
namespace style {
class Style;
} // namespace style
@@ -39,7 +41,7 @@ public:
const float bearing,
const double tileSize,
const double scale,
- const optional<std::vector<std::string>>& layerIDs,
+ const QueryOptions& options,
const GeometryTileData&,
const CanonicalTileID&,
const style::Style&,
@@ -59,7 +61,7 @@ private:
std::unordered_map<std::string, std::vector<Feature>>& result,
const IndexedSubfeature&,
const GeometryCoordinates& queryGeometry,
- const optional<std::vector<std::string>>& filterLayerIDs,
+ const QueryOptions& options,
const GeometryTileData&,
const CanonicalTileID&,
const style::Style&,