summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-04-02 17:41:55 -0700
committerAnsis Brammanis <ansis.brammanis@gmail.com>2018-04-26 18:03:17 -0400
commitf86fe44dbd4de44c9fc8cb364521f966039289d7 (patch)
tree5fa9b4dd9b039640407c5ede97a4d7b94a25c230 /src/mbgl/renderer
parentf7d20a587199ccee42469ecea2299ae73bfaae49 (diff)
downloadqtlocation-mapboxgl-f86fe44dbd4de44c9fc8cb364521f966039289d7.tar.gz
[core] fix circle querying for scale and alignment
This fixes circle querying for cases where either circle-pitch-alignment=map or circle-pitch-scaling=viewport
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/layers/render_circle_layer.cpp66
-rw-r--r--src/mbgl/renderer/layers/render_circle_layer.hpp3
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp7
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp3
-rw-r--r--src/mbgl/renderer/layers/render_fill_layer.cpp7
-rw-r--r--src/mbgl/renderer/layers/render_fill_layer.hpp3
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.cpp6
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.hpp3
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp7
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.hpp3
-rw-r--r--src/mbgl/renderer/render_layer.hpp5
-rw-r--r--src/mbgl/renderer/render_source.hpp3
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp5
-rw-r--r--src/mbgl/renderer/sources/render_custom_geometry_source.cpp5
-rw-r--r--src/mbgl/renderer/sources/render_custom_geometry_source.hpp3
-rw-r--r--src/mbgl/renderer/sources/render_geojson_source.cpp5
-rw-r--r--src/mbgl/renderer/sources/render_geojson_source.hpp3
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp3
-rw-r--r--src/mbgl/renderer/sources/render_image_source.hpp3
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.cpp3
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.hpp3
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.cpp3
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.hpp3
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.cpp5
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.hpp3
-rw-r--r--src/mbgl/renderer/tile_pyramid.cpp11
-rw-r--r--src/mbgl/renderer/tile_pyramid.hpp3
27 files changed, 129 insertions, 48 deletions
diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp
index 6092ff5452..6e1c867a30 100644
--- a/src/mbgl/renderer/layers/render_circle_layer.cpp
+++ b/src/mbgl/renderer/layers/render_circle_layer.cpp
@@ -93,27 +93,75 @@ void RenderCircleLayer::render(PaintParameters& parameters, RenderSource*) {
}
}
+GeometryCoordinate projectPoint(const GeometryCoordinate& p, const mat4& posMatrix, const Size& size) {
+ vec4 pos = {{ static_cast<double>(p.x), static_cast<double>(p.y), 0, 1 }};
+ matrix::transformMat4(pos, pos, posMatrix);
+ return {
+ static_cast<int16_t>((static_cast<float>(pos[0] / pos[3]) + 1) * size.width * 0.5),
+ static_cast<int16_t>((static_cast<float>(pos[1] / pos[3]) + 1) * size.height * 0.5)
+ };
+}
+
+GeometryCoordinates projectQueryGeometry(const GeometryCoordinates& queryGeometry, const mat4& posMatrix, const Size& size) {
+ GeometryCoordinates projectedGeometry;
+ for (auto& p : queryGeometry) {
+ projectedGeometry.push_back(projectPoint(p, posMatrix, size));
+ }
+ return projectedGeometry;
+}
+
bool RenderCircleLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float zoom,
- const float bearing,
- const float pixelsToTileUnits) const {
+ const TransformState& transformState,
+ const float pixelsToTileUnits,
+ const mat4& posMatrix) const {
// Translate query geometry
- auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
+ const GeometryCoordinates& translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::CircleTranslate>(),
evaluated.get<style::CircleTranslateAnchor>(),
- bearing,
- pixelsToTileUnits);
+ transformState.getAngle(),
+ pixelsToTileUnits).value_or(queryGeometry);
// Evaluate functions
- auto radius = evaluated.evaluate<style::CircleRadius>(zoom, feature) * pixelsToTileUnits;
- auto stroke = evaluated.evaluate<style::CircleStrokeWidth>(zoom, feature) * pixelsToTileUnits;
+ auto radius = evaluated.evaluate<style::CircleRadius>(zoom, feature);
+ auto stroke = evaluated.evaluate<style::CircleStrokeWidth>(zoom, feature);
+ auto size = radius + stroke;
+
+ // For pitch-alignment: map, compare feature geometry to query geometry in the plane of the tile
+ // Otherwise, compare geometry in the plane of the viewport
+ // A circle with fixed scaling relative to the viewport gets larger in tile space as it moves into the distance
+ // A circle with fixed scaling relative to the map gets smaller in viewport space as it moves into the distance
+ bool alignWithMap = evaluated.evaluate<style::CirclePitchAlignment>(zoom, feature) == AlignmentType::Map;
+ const GeometryCoordinates& transformedQueryGeometry = alignWithMap ?
+ translatedQueryGeometry :
+ projectQueryGeometry(translatedQueryGeometry, posMatrix, transformState.getSize());
+ auto transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
+
+ auto geometry = feature.getGeometries();
+ for (auto& ring : geometry) {
+ for (auto& point : ring) {
+ const GeometryCoordinate& transformedPoint = alignWithMap ? point : projectPoint(point, posMatrix, transformState.getSize());
+
+ float adjustedSize = transformedSize;
+ vec4 center = {{ static_cast<double>(point.x), static_cast<double>(point.y), 0, 1 }};
+ matrix::transformMat4(center, center, posMatrix);
+ auto pitchScale = evaluated.evaluate<style::CirclePitchScale>(zoom, feature);
+ auto pitchAlignment = evaluated.evaluate<style::CirclePitchAlignment>(zoom, feature);
+ if (pitchScale == CirclePitchScaleType::Viewport && pitchAlignment == AlignmentType::Map) {
+ adjustedSize *= center[3] / transformState.getCameraToCenterDistance();
+ } else if (pitchScale == CirclePitchScaleType::Map && pitchAlignment == AlignmentType::Viewport) {
+ adjustedSize *= transformState.getCameraToCenterDistance() / center[3];
+ }
+
+ if (util::polygonIntersectsBufferedPoint(transformedQueryGeometry, transformedPoint, adjustedSize)) return true;
+ }
+ }
- // Test intersection
- return util::polygonIntersectsBufferedMultiPoint(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries(), radius + stroke);
+ return false;
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/layers/render_circle_layer.hpp b/src/mbgl/renderer/layers/render_circle_layer.hpp
index f31715f98f..c9eeae4652 100644
--- a/src/mbgl/renderer/layers/render_circle_layer.hpp
+++ b/src/mbgl/renderer/layers/render_circle_layer.hpp
@@ -20,8 +20,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const override;
+ const mat4&) const override;
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
index fbd6160e8a..871464223c 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
@@ -151,14 +151,15 @@ bool RenderFillExtrusionLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float,
- const float bearing,
- const float pixelsToTileUnits) const {
+ const TransformState& transformState,
+ const float pixelsToTileUnits,
+ const mat4&) const {
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::FillExtrusionTranslate>(),
evaluated.get<style::FillExtrusionTranslateAnchor>(),
- bearing,
+ transformState.getAngle(),
pixelsToTileUnits);
return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries());
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp
index 838494cf91..f7ba13c267 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp
@@ -22,8 +22,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const override;
+ const mat4&) const override;
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp
index 22cb9563c1..efd3f4215c 100644
--- a/src/mbgl/renderer/layers/render_fill_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_layer.cpp
@@ -188,14 +188,15 @@ bool RenderFillLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float,
- const float bearing,
- const float pixelsToTileUnits) const {
+ const TransformState& transformState,
+ const float pixelsToTileUnits,
+ const mat4&) const {
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::FillTranslate>(),
evaluated.get<style::FillTranslateAnchor>(),
- bearing,
+ transformState.getAngle(),
pixelsToTileUnits);
return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries());
diff --git a/src/mbgl/renderer/layers/render_fill_layer.hpp b/src/mbgl/renderer/layers/render_fill_layer.hpp
index a51865698f..bd195fb828 100644
--- a/src/mbgl/renderer/layers/render_fill_layer.hpp
+++ b/src/mbgl/renderer/layers/render_fill_layer.hpp
@@ -20,8 +20,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const override;
+ const mat4&) const override;
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
index 4f2e899220..72c60446aa 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
@@ -165,12 +165,12 @@ bool RenderHeatmapLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float zoom,
- const float bearing,
- const float pixelsToTileUnits) const {
+ const TransformState&,
+ const float pixelsToTileUnits,
+ const mat4&) const {
(void) queryGeometry;
(void) feature;
(void) zoom;
- (void) bearing;
(void) pixelsToTileUnits;
return false;
}
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp
index 3f0b1f91b4..29fad7d8b8 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp
@@ -22,8 +22,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const override;
+ const mat4&) const override;
void updateColorRamp();
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index 1b4a1c0ff7..02f61af0fa 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -162,15 +162,16 @@ bool RenderLineLayer::queryIntersectsFeature(
const GeometryCoordinates& queryGeometry,
const GeometryTileFeature& feature,
const float zoom,
- const float bearing,
- const float pixelsToTileUnits) const {
+ const TransformState& transformState,
+ const float pixelsToTileUnits,
+ const mat4&) const {
// Translate query geometry
auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
queryGeometry,
evaluated.get<style::LineTranslate>(),
evaluated.get<style::LineTranslateAnchor>(),
- bearing,
+ transformState.getAngle(),
pixelsToTileUnits);
// Evaluate function
diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp
index 8bf7e2329d..5d5d79c044 100644
--- a/src/mbgl/renderer/layers/render_line_layer.hpp
+++ b/src/mbgl/renderer/layers/render_line_layer.hpp
@@ -29,8 +29,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const override;
+ const mat4&) const override;
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp
index 55831cb72c..04a1608564 100644
--- a/src/mbgl/renderer/render_layer.hpp
+++ b/src/mbgl/renderer/render_layer.hpp
@@ -4,6 +4,7 @@
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layer_type.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/util/mat4.hpp>
#include <memory>
#include <string>
@@ -17,6 +18,7 @@ class PropertyEvaluationParameters;
class PaintParameters;
class RenderSource;
class RenderTile;
+class TransformState;
class RenderLayer {
protected:
@@ -69,8 +71,9 @@ public:
const GeometryCoordinates&,
const GeometryTileFeature&,
const float,
+ const TransformState&,
const float,
- const float) const { return false; };
+ const mat4&) const { return false; };
virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const = 0;
diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp
index 54a0b5db43..dc80cb1dc6 100644
--- a/src/mbgl/renderer/render_source.hpp
+++ b/src/mbgl/renderer/render_source.hpp
@@ -64,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 mat4& projMatrix) const = 0;
virtual std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const = 0;
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index 5b739678fb..ded07a0909 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -704,10 +704,13 @@ std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin
sourceIDs.emplace(layer->baseImpl->source);
}
+ mat4 projMatrix;
+ transformState.getProjMatrix(projMatrix);
+
std::unordered_map<std::string, std::vector<Feature>> resultsByLayer;
for (const auto& sourceID : sourceIDs) {
if (RenderSource* renderSource = getRenderSource(sourceID)) {
- auto sourceResults = renderSource->queryRenderedFeatures(geometry, transformState, layers, options);
+ auto sourceResults = renderSource->queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
std::move(sourceResults.begin(), sourceResults.end(), std::inserter(resultsByLayer, resultsByLayer.begin()));
}
}
diff --git a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp
index 88792db00b..2d28b8dd84 100644
--- a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp
+++ b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp
@@ -67,8 +67,9 @@ std::unordered_map<std::string, std::vector<Feature>>
RenderCustomGeometrySource::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 mat4& projMatrix) const {
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
}
std::vector<Feature> RenderCustomGeometrySource::querySourceFeatures(const SourceQueryOptions& options) const {
diff --git a/src/mbgl/renderer/sources/render_custom_geometry_source.hpp b/src/mbgl/renderer/sources/render_custom_geometry_source.hpp
index 9e47b9e392..5533fe2b83 100644
--- a/src/mbgl/renderer/sources/render_custom_geometry_source.hpp
+++ b/src/mbgl/renderer/sources/render_custom_geometry_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp
index 7492a4cf16..0e265efff4 100644
--- a/src/mbgl/renderer/sources/render_geojson_source.cpp
+++ b/src/mbgl/renderer/sources/render_geojson_source.cpp
@@ -85,8 +85,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 mat4& projMatrix) const {
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
}
std::vector<Feature> RenderGeoJSONSource::querySourceFeatures(const SourceQueryOptions& options) const {
diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp
index bcdc109953..297fa09a29 100644
--- a/src/mbgl/renderer/sources/render_geojson_source.hpp
+++ b/src/mbgl/renderer/sources/render_geojson_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index b35e151f82..5c497e8144 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -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 mat4&) const {
return std::unordered_map<std::string, std::vector<Feature>> {};
}
diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp
index 7dc89d3591..cf14e180fd 100644
--- a/src/mbgl/renderer/sources/render_image_source.hpp
+++ b/src/mbgl/renderer/sources/render_image_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
index 58bdba1840..fbf2c09d19 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
@@ -146,7 +146,8 @@ std::unordered_map<std::string, std::vector<Feature>>
RenderRasterDEMSource::queryRenderedFeatures(const ScreenLineString&,
const TransformState&,
const std::vector<const RenderLayer*>&,
- const RenderedQueryOptions&) const {
+ const RenderedQueryOptions&,
+ const mat4&) const {
return std::unordered_map<std::string, std::vector<Feature>> {};
}
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
index 512fe6367c..48c7803e92 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp
index 3162acc7b4..f97ce4e65b 100644
--- a/src/mbgl/renderer/sources/render_raster_source.cpp
+++ b/src/mbgl/renderer/sources/render_raster_source.cpp
@@ -76,7 +76,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 mat4&) const {
return std::unordered_map<std::string, std::vector<Feature>> {};
}
diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp
index c60a51c63b..32539a046d 100644
--- a/src/mbgl/renderer/sources/render_raster_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp
index c9c47359f4..4de4f01e3f 100644
--- a/src/mbgl/renderer/sources/render_vector_source.cpp
+++ b/src/mbgl/renderer/sources/render_vector_source.cpp
@@ -79,8 +79,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 mat4& projMatrix) const {
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
}
std::vector<Feature> RenderVectorSource::querySourceFeatures(const SourceQueryOptions& options) const {
diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp
index a0351c226c..6fd2425aa3 100644
--- a/src/mbgl/renderer/sources/render_vector_source.hpp
+++ b/src/mbgl/renderer/sources/render_vector_source.hpp
@@ -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 mat4& projMatrix) const final;
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const final;
diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp
index b2d72680e7..d28e95181b 100644
--- a/src/mbgl/renderer/tile_pyramid.cpp
+++ b/src/mbgl/renderer/tile_pyramid.cpp
@@ -241,7 +241,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 mat4& projMatrix) const {
std::unordered_map<std::string, std::vector<Feature>> result;
if (renderTiles.empty() || geometry.empty()) {
return result;
@@ -263,8 +264,11 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
std::tie(b.id.canonical.z, b.id.canonical.y, b.id.wrap, b.id.canonical.x);
});
+ auto maxPitchScaleFactor = transformState.maxPitchScaleFactor();
+
for (const RenderTile& renderTile : sortedTiles) {
- auto queryPadding = renderTile.tile.getQueryPadding(layers);
+ const float scale = std::pow(2, transformState.getZoom() - renderTile.id.canonical.z);
+ auto queryPadding = maxPitchScaleFactor * renderTile.tile.getQueryPadding(layers) * util::EXTENT / util::tileSize / scale;
GeometryCoordinate tileSpaceBoundsMin = TileCoordinate::toGeometryCoordinate(renderTile.id, box.min);
if (tileSpaceBoundsMin.x - queryPadding >= util::EXTENT || tileSpaceBoundsMin.y - queryPadding >= util::EXTENT) {
@@ -286,7 +290,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
tileSpaceQueryGeometry,
transformState,
layers,
- options);
+ options,
+ projMatrix);
}
return result;
diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp
index bf3ba0d7b8..0cef9e2c40 100644
--- a/src/mbgl/renderer/tile_pyramid.hpp
+++ b/src/mbgl/renderer/tile_pyramid.hpp
@@ -53,7 +53,8 @@ public:
queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
const std::vector<const RenderLayer*>&,
- const RenderedQueryOptions& options) const;
+ const RenderedQueryOptions& options,
+ const mat4& projMatrix) const;
std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const;