diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index 6d6521917e5..f89739843e9 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -52,6 +52,7 @@ static bool topDownSymbols(const IndexedSubfeature& a, const IndexedSubfeature& void FeatureIndex::query( std::unordered_map>& result, + const GeometryCollection& scaledQueryGeometry, const GeometryCollection& queryGeometry, const float bearing, const double tileSize, @@ -61,10 +62,10 @@ void FeatureIndex::query( const CanonicalTileID& tileID, const style::Style& style) const { - mapbox::geometry::box box = mapbox::geometry::envelope(queryGeometry); const float pixelsToTileUnits = util::EXTENT / tileSize / scale; const int16_t additionalRadius = std::min(util::EXTENT, std::ceil(style.getQueryRadius() * pixelsToTileUnits)); + mapbox::geometry::box box = mapbox::geometry::envelope(queryGeometry); std::vector features = grid.query({ box.min - additionalRadius, box.max + additionalRadius }); std::sort(features.begin(), features.end(), topDown); @@ -78,12 +79,14 @@ void FeatureIndex::query( addFeature(result, indexedFeature, queryGeometry, filterLayerIDs, geometryTileData, tileID, style, bearing, pixelsToTileUnits); } + mapbox::geometry::box scaledBox = mapbox::geometry::envelope(scaledQueryGeometry); + // query symbol features assert(collisionTile); - std::vector symbolFeatures = collisionTile->queryRenderedSymbols(box, scale); + std::vector symbolFeatures = collisionTile->queryRenderedSymbols(scaledBox, 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, scaledQueryGeometry, filterLayerIDs, geometryTileData, tileID, style, bearing, pixelsToTileUnits); } } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 0fddcb47001..b7ccde9ab03 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -35,6 +35,7 @@ class FeatureIndex { void query( std::unordered_map>& result, + const GeometryCollection& scaledQueryGeometry, const GeometryCollection& queryGeometry, const float bearing, const double tileSize, diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 398b85ae233..a0847d38f3b 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -221,7 +221,7 @@ std::unordered_map> Source::Impl::queryRendere scaledScreenBox.max.x *= scale; scaledScreenBox.max.y *= scale; - LineString geometry = { + LineString scaledGeometry = { scaledScreenBox.min, { scaledScreenBox.max.x, scaledScreenBox.min.y }, scaledScreenBox.max, @@ -229,32 +229,50 @@ std::unordered_map> Source::Impl::queryRendere scaledScreenBox.min }; - LineString queryGeometry; + LineString geometry = { + parameters.box.min, + { parameters.box.max.x, parameters.box.min.y }, + parameters.box.max, + { parameters.box.min.x, parameters.box.max.y }, + parameters.box.min + }; - for (const auto& p : geometry) { - queryGeometry.push_back(TileCoordinate::fromScreenCoordinate( + LineString scaledQueryGeometry; + + for (const auto& p : scaledGeometry) { + scaledQueryGeometry.push_back(TileCoordinate::fromScreenCoordinate( parameters.transformState, 0, { p.x, parameters.transformState.getHeight() - p.y }).p); } - mapbox::geometry::box box = mapbox::geometry::envelope(queryGeometry); - - if (queryGeometry.empty()) { + if (scaledQueryGeometry.empty()) { return result; } + LineString queryGeometry; + + for (const auto& p : geometry) { + queryGeometry.push_back(TileCoordinate::fromScreenCoordinate( + parameters.transformState, 0, { p.x, parameters.transformState.getHeight() - p.y }).p); + } + + mapbox::geometry::box box = mapbox::geometry::envelope(scaledQueryGeometry); Point tileSpaceBoundsMin = coordinateToTilePoint(tile.id, box.min); Point tileSpaceBoundsMax = coordinateToTilePoint(tile.id, box.max); - if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT || tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) continue; + GeometryCoordinates tileSpaceQueryGeometryScaled; + for (const auto& c : scaledQueryGeometry) { + tileSpaceQueryGeometryScaled.push_back(coordinateToTilePoint(tile.id, c)); + } + GeometryCoordinates tileSpaceQueryGeometry; - for (const auto& c : queryGeometry) { tileSpaceQueryGeometry.push_back(coordinateToTilePoint(tile.id, c)); } - + tile.tile.queryRenderedFeatures(result, + tileSpaceQueryGeometryScaled, tileSpaceQueryGeometry, parameters.transformState, parameters.layerIDs); diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index daa358420b6..484c41ee1e9 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -199,6 +199,7 @@ void GeometryTile::redoPlacement() { void GeometryTile::queryRenderedFeatures( std::unordered_map>& result, + const GeometryCoordinates& scaledQueryGeometry, const GeometryCoordinates& queryGeometry, const TransformState& transformState, const optional>& layerIDs) { @@ -206,6 +207,7 @@ void GeometryTile::queryRenderedFeatures( if (!featureIndex || !data) return; featureIndex->query(result, + { scaledQueryGeometry }, { queryGeometry }, transformState.getAngle(), util::tileSize * id.overscaleFactor(), diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 891aba0432c..c30fc5602c8 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -41,6 +41,7 @@ class GeometryTile : public Tile { void queryRenderedFeatures( std::unordered_map>& result, + const GeometryCoordinates& scaledQueryGeometry, const GeometryCoordinates& queryGeometry, const TransformState&, const optional>& layerIDs) override; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index 6595c314eec..6fe08f5d16c 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -29,6 +29,7 @@ void Tile::dumpDebugLogs() const { void Tile::queryRenderedFeatures( std::unordered_map>&, + const GeometryCoordinates& scaledQueryGeometry, const GeometryCoordinates&, const TransformState&, const optional>&) {} diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 65f3aaa2451..0230ef4a3e5 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -52,6 +52,7 @@ class Tile : private util::noncopyable { virtual void queryRenderedFeatures( std::unordered_map>& result, + const GeometryCoordinates& scaledQueryGeometry, const GeometryCoordinates& queryGeometry, const TransformState&, const optional>& layerIDs);