Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Consider tile overscaledZ when querying rendered features
Browse files Browse the repository at this point in the history
Previously, the ScreenBox represented abstract points in the
coordinate space. However, the query rendered features method
works at the level of tiles and therefore at an actual an implied
zoom level. The ScreenBox passed in from the SDK should represent
the query rect in points and that rect should be adjusted to cover
the per zoom level scale.

This commit passes the ScreenBox down to the source's
query `queryRenderedFeatures` method so that it can be adjusted
for each evaluated tile. With this change, the expect number of
point annotations are returned for any arbitrary ScreenBox rect (in
points) at any zoom level.
  • Loading branch information
boundsj committed Aug 24, 2016
1 parent 06d8b41 commit 16da44f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
14 changes: 5 additions & 9 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,25 +724,21 @@ void Map::removeAnnotation(AnnotationID annotation) {

std::vector<Feature> Map::queryRenderedFeatures(const ScreenCoordinate& point, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};

ScreenBox screenBox = { point, point };

return impl->style->queryRenderedFeatures({
{ point },
screenBox,
impl->transform.getState(),
layerIDs
});
}

std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};

return impl->style->queryRenderedFeatures({
{
box.min,
{ box.max.x, box.min.y },
box.max,
{ box.min.x, box.max.y },
box.min
},
box,
impl->transform.getState(),
layerIDs
});
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/query_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace style {

class QueryParameters {
public:
const ScreenLineString& geometry;
const ScreenBox& box;
const TransformState& transformState;
const optional<std::vector<std::string>>& layerIDs;
};
Expand Down
40 changes: 27 additions & 13 deletions src/mbgl/style/source_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,36 @@ std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRendere
return result;
}

LineString<double> queryGeometry;

for (const auto& p : parameters.geometry) {
queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(
parameters.transformState, 0, { p.x, parameters.transformState.getHeight() - p.y }).p);
}

if (queryGeometry.empty()) {
return result;
}

mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);

for (const auto& tilePtr : renderTiles) {
const RenderTile& tile = tilePtr.second;

double scale = std::pow(2, parameters.transformState.getZoom() - tile.tile.id.overscaledZ);
mbgl::ScreenBox scaledScreenBox = parameters.box;

scaledScreenBox.max.x *= scale;
scaledScreenBox.max.y *= scale;

LineString<double> geometry = {
scaledScreenBox.min,
{ scaledScreenBox.max.x, scaledScreenBox.min.y },
scaledScreenBox.max,
{ scaledScreenBox.min.x, scaledScreenBox.max.y },
scaledScreenBox.min
};

LineString<double> 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<double> box = mapbox::geometry::envelope(queryGeometry);

if (queryGeometry.empty()) {
return result;
}

Point<int16_t> tileSpaceBoundsMin = coordinateToTilePoint(tile.id, box.min);
Point<int16_t> tileSpaceBoundsMax = coordinateToTilePoint(tile.id, box.max);

Expand Down

0 comments on commit 16da44f

Please sign in to comment.