diff options
author | Chris Loer <chris.loer@gmail.com> | 2017-11-09 13:24:43 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2017-11-17 10:05:15 -0800 |
commit | 77bfb47fdabbd257272a01bef591d73e8c53c9c7 (patch) | |
tree | 253edfab06524d0626e992e6d31c6c4bba7cbe1f /src/mbgl/geometry | |
parent | c0cb210ddca1901a956cd68e9142b7fb04183248 (diff) | |
download | qtlocation-mapboxgl-77bfb47fdabbd257272a01bef591d73e8c53c9c7.tar.gz |
[core] Update queryRenderedFeatures to use global CollisionIndex.
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r-- | src/mbgl/geometry/feature_index.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.hpp | 39 |
2 files changed, 46 insertions, 19 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index f7dbbfb8b3..e610e5ba5f 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -2,7 +2,7 @@ #include <mbgl/renderer/render_layer.hpp> #include <mbgl/renderer/query.hpp> #include <mbgl/renderer/layers/render_symbol_layer.hpp> -#include <mbgl/text/collision_tile.hpp> +#include <mbgl/text/collision_index.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/math.hpp> #include <mbgl/math/minmax.hpp> @@ -26,8 +26,9 @@ void FeatureIndex::insert(const GeometryCollection& geometries, const std::string& sourceLayerName, const std::string& bucketName) { for (const auto& ring : geometries) { - grid.insert(IndexedSubfeature { index, sourceLayerName, bucketName, sortIndex++ }, - mapbox::geometry::envelope(ring)); + auto envelope = mapbox::geometry::envelope(ring); + grid.insert(IndexedSubfeature(index, sourceLayerName, bucketName, sortIndex++), + {convertPoint<float>(envelope.min), convertPoint<float>(envelope.max)}); } } @@ -47,9 +48,10 @@ void FeatureIndex::query( const double scale, const RenderedQueryOptions& queryOptions, const GeometryTileData& geometryTileData, - const CanonicalTileID& tileID, + const UnwrappedTileID& tileID, + const std::string& sourceID, const std::vector<const RenderLayer*>& layers, - const CollisionTile* collisionTile, + const CollisionIndex& collisionIndex, const float additionalQueryRadius) const { // Determine query radius @@ -58,7 +60,8 @@ void FeatureIndex::query( // 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::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalRadius), + convertPoint<float>(box.max + additionalRadius) }); std::sort(features.begin(), features.end(), topDown); @@ -69,18 +72,13 @@ void FeatureIndex::query( if (indexedFeature.sortIndex == previousSortIndex) continue; previousSortIndex = indexedFeature.sortIndex; - addFeature(result, indexedFeature, queryGeometry, queryOptions, geometryTileData, tileID, layers, bearing, pixelsToTileUnits); + addFeature(result, indexedFeature, queryGeometry, queryOptions, geometryTileData, tileID.canonical, layers, bearing, pixelsToTileUnits); } - // Query symbol features, if they've been placed. - if (!collisionTile) { - return; - } - - std::vector<IndexedSubfeature> symbolFeatures = collisionTile->queryRenderedSymbols(queryGeometry, scale); + std::vector<IndexedSubfeature> symbolFeatures = collisionIndex.queryRenderedSymbols(queryGeometry, tileID, sourceID); std::sort(symbolFeatures.begin(), symbolFeatures.end(), topDownSymbols); for (const auto& symbolFeature : symbolFeatures) { - addFeature(result, symbolFeature, queryGeometry, queryOptions, geometryTileData, tileID, layers, bearing, pixelsToTileUnits); + addFeature(result, symbolFeature, queryGeometry, queryOptions, geometryTileData, tileID.canonical, layers, bearing, pixelsToTileUnits); } } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 2ae7da33df..07dc1b1558 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -2,6 +2,7 @@ #include <mbgl/style/types.hpp> #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/tile/tile_id.hpp> #include <mbgl/util/grid_index.hpp> #include <mbgl/util/feature.hpp> @@ -14,16 +15,43 @@ namespace mbgl { class RenderedQueryOptions; class RenderLayer; -class CollisionTile; -class CanonicalTileID; +class CollisionIndex; class IndexedSubfeature { public: IndexedSubfeature() = delete; - std::size_t index; + IndexedSubfeature(std::size_t index_, std::string sourceLayerName_, std::string bucketName_, size_t sortIndex_) + : index(index_) + , sourceLayerName(std::move(sourceLayerName_)) + , bucketName(std::move(bucketName_)) + , sortIndex(sortIndex_) + , z(0) + , x(0) + , y(0) + {} + + IndexedSubfeature(std::size_t index_, std::string sourceLayerName_, std::string bucketName_, size_t sortIndex_, + std::string sourceID_, uint8_t z_, uint32_t x_, uint32_t y_) + : index(index_) + , sourceLayerName(std::move(sourceLayerName_)) + , bucketName(std::move(bucketName_)) + , sortIndex(std::move(sortIndex_)) + , sourceID(std::move(sourceID_)) + , z(z_) + , x(x_) + , y(y_) + {} + + size_t index; std::string sourceLayerName; std::string bucketName; size_t sortIndex; + + // Only used for symbol features + std::string sourceID; + uint8_t z; + uint32_t x; + uint32_t y; }; class FeatureIndex { @@ -40,9 +68,10 @@ public: const double scale, const RenderedQueryOptions& options, const GeometryTileData&, - const CanonicalTileID&, + const UnwrappedTileID&, + const std::string&, const std::vector<const RenderLayer*>&, - const CollisionTile*, + const CollisionIndex&, const float additionalQueryRadius) const; static optional<GeometryCoordinates> translateQueryGeometry( |