[core] Update queryRenderedFeatures to use global CollisionIndex.
This commit is contained in:
@@ -63,8 +63,9 @@ std::unordered_map<std::string, std::vector<Feature>>
|
||||
RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options);
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex);
|
||||
}
|
||||
|
||||
std::vector<Feature> RenderAnnotationSource::querySourceFeatures(const SourceQueryOptions&) const {
|
||||
|
||||
@@ -27,7 +27,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const final;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const final;
|
||||
|
||||
std::vector<Feature>
|
||||
querySourceFeatures(const SourceQueryOptions&) const final;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -24,6 +24,7 @@ class SourceQueryOptions;
|
||||
class Tile;
|
||||
class RenderSourceObserver;
|
||||
class TileParameters;
|
||||
class CollisionIndex;
|
||||
|
||||
class RenderSource : protected TileObserver {
|
||||
public:
|
||||
@@ -63,7 +64,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const = 0;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const = 0;
|
||||
|
||||
virtual std::vector<Feature>
|
||||
querySourceFeatures(const SourceQueryOptions&) const = 0;
|
||||
|
||||
@@ -84,8 +84,9 @@ std::unordered_map<std::string, std::vector<Feature>>
|
||||
RenderGeoJSONSource::queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options);
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex);
|
||||
}
|
||||
|
||||
std::vector<Feature> RenderGeoJSONSource::querySourceFeatures(const SourceQueryOptions& options) const {
|
||||
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const final;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex&) const final;
|
||||
|
||||
std::vector<Feature>
|
||||
querySourceFeatures(const SourceQueryOptions&) const final;
|
||||
|
||||
@@ -84,7 +84,8 @@ std::unordered_map<std::string, std::vector<Feature>>
|
||||
RenderImageSource::queryRenderedFeatures(const ScreenLineString&,
|
||||
const TransformState&,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
const RenderedQueryOptions&) const {
|
||||
const RenderedQueryOptions&,
|
||||
const CollisionIndex&) const {
|
||||
return std::unordered_map<std::string, std::vector<Feature>> {};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const final;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const final;
|
||||
|
||||
std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final;
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ std::unordered_map<std::string, std::vector<Feature>>
|
||||
RenderRasterSource::queryRenderedFeatures(const ScreenLineString&,
|
||||
const TransformState&,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
const RenderedQueryOptions&) const {
|
||||
const RenderedQueryOptions&,
|
||||
const CollisionIndex& ) const {
|
||||
return std::unordered_map<std::string, std::vector<Feature>> {};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const final;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const final;
|
||||
|
||||
std::vector<Feature>
|
||||
querySourceFeatures(const SourceQueryOptions&) const final;
|
||||
|
||||
@@ -77,8 +77,9 @@ std::unordered_map<std::string, std::vector<Feature>>
|
||||
RenderVectorSource::queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options);
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const {
|
||||
return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, collisionIndex);
|
||||
}
|
||||
|
||||
std::vector<Feature> RenderVectorSource::querySourceFeatures(const SourceQueryOptions& options) const {
|
||||
|
||||
@@ -27,7 +27,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const final;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const final;
|
||||
|
||||
std::vector<Feature>
|
||||
querySourceFeatures(const SourceQueryOptions&) const final;
|
||||
|
||||
@@ -208,7 +208,8 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
|
||||
std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>& layers,
|
||||
const RenderedQueryOptions& options) const {
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const {
|
||||
std::unordered_map<std::string, std::vector<Feature>> result;
|
||||
if (renderTiles.empty() || geometry.empty()) {
|
||||
return result;
|
||||
@@ -251,7 +252,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
|
||||
tileSpaceQueryGeometry,
|
||||
transformState,
|
||||
layers,
|
||||
options);
|
||||
options,
|
||||
collisionIndex);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -51,7 +51,8 @@ public:
|
||||
queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
const TransformState& transformState,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
const RenderedQueryOptions& options) const;
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex& collisionIndex) const;
|
||||
|
||||
std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const;
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ void Tile::queryRenderedFeatures(
|
||||
const GeometryCoordinates&,
|
||||
const TransformState&,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
const RenderedQueryOptions&) {}
|
||||
const RenderedQueryOptions&,
|
||||
const CollisionIndex&) {}
|
||||
|
||||
void Tile::querySourceFeatures(
|
||||
std::vector<Feature>&,
|
||||
|
||||
@@ -27,6 +27,8 @@ class RenderLayer;
|
||||
class RenderedQueryOptions;
|
||||
class SourceQueryOptions;
|
||||
|
||||
class CollisionIndex;
|
||||
|
||||
namespace gl {
|
||||
class Context;
|
||||
} // namespace gl
|
||||
@@ -55,7 +57,8 @@ public:
|
||||
const GeometryCoordinates& queryGeometry,
|
||||
const TransformState&,
|
||||
const std::vector<const RenderLayer*>&,
|
||||
const RenderedQueryOptions& options);
|
||||
const RenderedQueryOptions& options,
|
||||
const CollisionIndex&);
|
||||
|
||||
virtual void querySourceFeatures(
|
||||
std::vector<Feature>& result,
|
||||
|
||||
Reference in New Issue
Block a user