diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-04-02 17:41:09 -0700 |
---|---|---|
committer | Ansis Brammanis <ansis.brammanis@gmail.com> | 2018-04-26 18:03:17 -0400 |
commit | f7d20a587199ccee42469ecea2299ae73bfaae49 (patch) | |
tree | 19da41f7b8c867aeb860d9aab650773337ef1257 | |
parent | 0767bf06869c380305c57df1b69d74fac5a6c94a (diff) | |
download | qtlocation-mapboxgl-f7d20a587199ccee42469ecea2299ae73bfaae49.tar.gz |
[core] fix querying circles across tile boundaries
-rw-r--r-- | src/mbgl/geometry/feature_index.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/geometry/feature_index.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/tile_pyramid.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.cpp | 22 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/tile/tile.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/tile/tile.hpp | 2 |
7 files changed, 30 insertions, 16 deletions
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index 8ea6259129..728996a2eb 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -42,7 +42,7 @@ void FeatureIndex::query( const RenderedQueryOptions& queryOptions, const UnwrappedTileID& tileID, const std::vector<const RenderLayer*>& layers, - const float additionalQueryRadius) const { + const float additionalQueryPadding) const { if (!tileData) { return; @@ -50,12 +50,12 @@ void FeatureIndex::query( // Determine query radius const float pixelsToTileUnits = util::EXTENT / tileSize / scale; - const int16_t additionalRadius = std::min<int16_t>(util::EXTENT, additionalQueryRadius * pixelsToTileUnits); + const int16_t additionalPadding = std::min<int16_t>(util::EXTENT, additionalQueryPadding * pixelsToTileUnits); // Query the grid index mapbox::geometry::box<int16_t> box = mapbox::geometry::envelope(queryGeometry); - std::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalRadius), - convertPoint<float>(box.max + additionalRadius) }); + std::vector<IndexedSubfeature> features = grid.query({ convertPoint<float>(box.min - additionalPadding), + convertPoint<float>(box.max + additionalPadding) }); std::sort(features.begin(), features.end(), [](const IndexedSubfeature& a, const IndexedSubfeature& b) { diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 5a15a379c4..f105260c0c 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -62,7 +62,7 @@ public: const RenderedQueryOptions& options, const UnwrappedTileID&, const std::vector<const RenderLayer*>&, - const float additionalQueryRadius) const; + const float additionalQueryPadding) const; static optional<GeometryCoordinates> translateQueryGeometry( const GeometryCoordinates& queryGeometry, diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index e2d4d9829f..b2d72680e7 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -264,13 +264,15 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered }); for (const RenderTile& renderTile : sortedTiles) { + auto queryPadding = renderTile.tile.getQueryPadding(layers); + GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(renderTile.id, box.min); - if (tileSpaceBoundsMin.x >= util::EXTENT || tileSpaceBoundsMin.y >= util::EXTENT) { + if (tileSpaceBoundsMin.x - queryPadding >= util::EXTENT || tileSpaceBoundsMin.y - queryPadding >= util::EXTENT) { continue; } GeometryCoordinate tileSpaceBoundsMax = TileCoordinate::toGeometryCoordinate(renderTile.id, box.max); - if (tileSpaceBoundsMax.x < 0 || tileSpaceBoundsMax.y < 0) { + if (tileSpaceBoundsMax.x + queryPadding < 0 || tileSpaceBoundsMax.y + queryPadding < 0) { continue; } diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 317c5454f6..92a226d3c1 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -201,6 +201,17 @@ Bucket* GeometryTile::getBucket(const Layer::Impl& layer) const { return it->second.get(); } +float GeometryTile::getQueryPadding(const std::vector<const RenderLayer*>& layers) { + float queryPadding = 0; + for (const RenderLayer* layer : layers) { + auto bucket = getBucket(*layer->baseImpl); + if (bucket) { + queryPadding = std::max(queryPadding, bucket->getQueryRadius(*layer)); + } + } + return queryPadding; +} + void GeometryTile::queryRenderedFeatures( std::unordered_map<std::string, std::vector<Feature>>& result, const GeometryCoordinates& queryGeometry, @@ -210,14 +221,7 @@ void GeometryTile::queryRenderedFeatures( if (!getData()) return; - // Determine the additional radius needed factoring in property functions - float additionalRadius = 0; - for (const RenderLayer* layer : layers) { - auto bucket = getBucket(*layer->baseImpl); - if (bucket) { - additionalRadius = std::max(additionalRadius, bucket->getQueryRadius(*layer)); - } - } + const float queryPadding = getQueryPadding(layers); latestFeatureIndex->query(result, queryGeometry, @@ -227,7 +231,7 @@ void GeometryTile::queryRenderedFeatures( options, id.toUnwrapped(), layers, - additionalRadius); + queryPadding); } void GeometryTile::querySourceFeatures( diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index a3b2eb6492..a43bf44940 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -60,6 +60,8 @@ public: std::vector<Feature>& result, const SourceQueryOptions&) override; + float getQueryPadding(const std::vector<const RenderLayer*>&) override; + void cancel() override; class LayoutResult { diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index e65bc39540..56698e84c4 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -39,6 +39,10 @@ void Tile::queryRenderedFeatures( const std::vector<const RenderLayer*>&, const RenderedQueryOptions&) {} +float Tile::getQueryPadding(const std::vector<const RenderLayer*>&) { + return 0; +} + void Tile::querySourceFeatures( std::vector<Feature>&, const SourceQueryOptions&) {} diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index a0effa29a1..5f7a076850 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -63,6 +63,8 @@ public: std::vector<Feature>& result, const SourceQueryOptions&); + virtual float getQueryPadding(const std::vector<const RenderLayer*>&); + void setTriedCache(); // Returns true when the tile source has received a first response, regardless of whether a load |