diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-04-12 12:31:51 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-04-19 17:21:28 -0700 |
commit | 7ddca3b6116903bae9ecde1d49d29a8f1fedcec3 (patch) | |
tree | efbdeda27dca8238965f6b7e1c263938ebe800d0 /src/mbgl/geometry | |
parent | d752235ec790f8c2d4e646c32648253ec64a60c4 (diff) | |
download | qtlocation-mapboxgl-7ddca3b6116903bae9ecde1d49d29a8f1fedcec3.tar.gz |
[core] account for property functions in query rendered features
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r-- | src/mbgl/geometry/feature_index.cpp | 45 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.hpp | 4 |
2 files changed, 43 insertions, 6 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index 0a159f2ce2..6fae5fe9a1 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -10,6 +10,7 @@ #include <mbgl/map/query.hpp> #include <mbgl/style/filter.hpp> #include <mbgl/style/filter_evaluator.hpp> +#include <mbgl/tile/geometry_tile.hpp> #include <mapbox/geometry/envelope.hpp> @@ -53,6 +54,36 @@ static bool topDownSymbols(const IndexedSubfeature& a, const IndexedSubfeature& return a.sortIndex < b.sortIndex; } +static int16_t getAdditionalQueryRadius(const RenderedQueryOptions& queryOptions, + const style::Style& style, + const GeometryTile& tile, + const float pixelsToTileUnits) { + + // Determine the additional radius needed factoring in property functions + float additionalRadius = 0; + auto getQueryRadius = [&](const style::Layer& layer) { + auto bucket = tile.getBucket(layer); + if (bucket) { + additionalRadius = std::max(additionalRadius, bucket->getQueryRadius(layer) * pixelsToTileUnits); + } + }; + + if (queryOptions.layerIDs) { + for (const auto& layerID : *queryOptions.layerIDs) { + style::Layer* layer = style.getLayer(layerID); + if (layer) { + getQueryRadius(*layer); + } + } + } else { + for (const style::Layer* layer : style.getLayers()) { + getQueryRadius(*layer); + } + } + + return std::min<int16_t>(util::EXTENT, additionalRadius); +} + void FeatureIndex::query( std::unordered_map<std::string, std::vector<Feature>>& result, const GeometryCoordinates& queryGeometry, @@ -63,14 +94,18 @@ void FeatureIndex::query( const GeometryTileData& geometryTileData, const CanonicalTileID& tileID, const style::Style& style, - const CollisionTile* collisionTile) const { - - mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope(queryGeometry); + const CollisionTile* collisionTile, + const GeometryTile& tile) const { + // Determine query radius const float pixelsToTileUnits = util::EXTENT / tileSize / scale; - const int16_t additionalRadius = std::min<int16_t>(util::EXTENT, std::ceil(style.getQueryRadius() * pixelsToTileUnits)); + const int16_t additionalRadius = getAdditionalQueryRadius(queryOptions, style, tile, pixelsToTileUnits); + + // Query the grid index + mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope(queryGeometry); std::vector<IndexedSubfeature> features = grid.query({ box.min - additionalRadius, box.max + additionalRadius }); + std::sort(features.begin(), features.end(), topDown); size_t previousSortIndex = std::numeric_limits<size_t>::max(); for (const auto& indexedFeature : features) { @@ -124,7 +159,7 @@ void FeatureIndex::addFeature( auto styleLayer = style.getLayer(layerID); if (!styleLayer || (!styleLayer->is<style::SymbolLayer>() && - !styleLayer->baseImpl->queryIntersectsGeometry(queryGeometry, geometryTileFeature->getGeometries(), bearing, pixelsToTileUnits))) { + !styleLayer->baseImpl->queryIntersectsFeature(queryGeometry, *geometryTileFeature, tileID.z, bearing, pixelsToTileUnits))) { continue; } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 61f0bad4d5..f7aa0182e4 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -11,6 +11,7 @@ namespace mbgl { +class GeometryTile; class RenderedQueryOptions; namespace style { @@ -45,7 +46,8 @@ public: const GeometryTileData&, const CanonicalTileID&, const style::Style&, - const CollisionTile*) const; + const CollisionTile*, + const GeometryTile& tile) const; static optional<GeometryCoordinates> translateQueryGeometry( const GeometryCoordinates& queryGeometry, |