summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Alanen <juha.alanen@mapbox.com>2019-08-21 15:40:11 +0300
committerJuha Alanen <19551460+jmalanen@users.noreply.github.com>2019-09-18 14:29:15 +0300
commit598df1897dcad6f0a003fbae5d9058b1a660f408 (patch)
tree247106b5f0e622af07125927035fa763114dd570
parent8e19be9d9c7f66bff16f97066570e990fe09fd4e (diff)
downloadqtlocation-mapboxgl-598df1897dcad6f0a003fbae5d9058b1a660f408.tar.gz
[core] Add feature state support to queryRenderedFeatures API
-rw-r--r--src/mbgl/annotation/render_annotation_source.cpp2
-rw-r--r--src/mbgl/geometry/feature_index.cpp24
-rw-r--r--src/mbgl/geometry/feature_index.hpp7
-rw-r--r--src/mbgl/renderer/sources/render_tile_source.cpp2
-rw-r--r--src/mbgl/renderer/tile_pyramid.cpp6
-rw-r--r--src/mbgl/renderer/tile_pyramid.hpp3
-rw-r--r--src/mbgl/tile/geometry_tile.cpp6
-rw-r--r--src/mbgl/tile/geometry_tile.hpp3
-rw-r--r--src/mbgl/tile/tile.cpp3
-rw-r--r--src/mbgl/tile/tile.hpp4
10 files changed, 43 insertions, 17 deletions
diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp
index 903825d5f5..e3acfcb3c0 100644
--- a/src/mbgl/annotation/render_annotation_source.cpp
+++ b/src/mbgl/annotation/render_annotation_source.cpp
@@ -49,7 +49,7 @@ RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry,
const std::unordered_map<std::string, const RenderLayer*>& layers,
const RenderedQueryOptions& options,
const mat4& projMatrix) const {
- return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix, {});
}
std::vector<Feature> RenderAnnotationSource::querySourceFeatures(const SourceQueryOptions&) const {
diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp
index b76e02be3f..2601d60979 100644
--- a/src/mbgl/geometry/feature_index.cpp
+++ b/src/mbgl/geometry/feature_index.cpp
@@ -8,6 +8,7 @@
#include <mbgl/math/minmax.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/tile/tile_id.hpp>
+#include <mbgl/renderer/source_state.hpp>
#include <mapbox/geometry/envelope.hpp>
@@ -48,7 +49,8 @@ void FeatureIndex::query(
const RenderedQueryOptions& queryOptions,
const UnwrappedTileID& tileID,
const std::unordered_map<std::string, const RenderLayer*>& layers,
- const float additionalQueryPadding) const {
+ const float additionalQueryPadding,
+ const SourceFeatureState& sourceFeatureState) const {
if (!tileData) {
return;
@@ -74,7 +76,7 @@ void FeatureIndex::query(
if (indexedFeature.sortIndex == previousSortIndex) continue;
previousSortIndex = indexedFeature.sortIndex;
- addFeature(result, indexedFeature, queryOptions, tileID.canonical, layers, queryGeometry, transformState, pixelsToTileUnits, posMatrix);
+ addFeature(result, indexedFeature, queryOptions, tileID.canonical, layers, queryGeometry, transformState, pixelsToTileUnits, posMatrix, &sourceFeatureState);
}
}
@@ -113,7 +115,7 @@ FeatureIndex::lookupSymbolFeatures(const std::vector<IndexedSubfeature>& symbolF
for (const auto& symbolFeature : sortedFeatures) {
mat4 unusedMatrix;
- addFeature(result, symbolFeature, queryOptions, tileID.canonical, layers, GeometryCoordinates(), {}, 0, unusedMatrix);
+ addFeature(result, symbolFeature, queryOptions, tileID.canonical, layers, GeometryCoordinates(), {}, 0, unusedMatrix, nullptr);
}
return result;
}
@@ -127,7 +129,8 @@ void FeatureIndex::addFeature(
const GeometryCoordinates& queryGeometry,
const TransformState& transformState,
const float pixelsToTileUnits,
- const mat4& posMatrix) const {
+ const mat4& posMatrix,
+ const SourceFeatureState* sourceFeatureState) const {
// Lazily calculated.
std::unique_ptr<GeometryTileLayer> sourceLayer;
@@ -148,6 +151,13 @@ void FeatureIndex::addFeature(
geometryTileFeature = sourceLayer->getFeature(indexedFeature.index);
assert(geometryTileFeature);
}
+ FeatureState state;
+ if (sourceFeatureState) {
+ optional<std::string> idStr = featureIDtoString(geometryTileFeature->getID());
+ if (idStr) {
+ sourceFeatureState->getState(state, sourceLayer->getName(), *idStr);
+ }
+ }
bool needsCrossTileIndex = renderLayer->baseImpl->getTypeInfo()->crossTileIndex == style::LayerTypeInfo::CrossTileIndex::Required;
if (!needsCrossTileIndex &&
@@ -159,7 +169,11 @@ void FeatureIndex::addFeature(
continue;
}
- result[layerID].emplace_back(convertFeature(*geometryTileFeature, tileID));
+ Feature feature = convertFeature(*geometryTileFeature, tileID);
+ feature.source = renderLayer->baseImpl->source;
+ feature.sourceLayer = sourceLayer->getName();
+ feature.state = state;
+ result[layerID].emplace_back(feature);
}
}
diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp
index 1a212761fa..ab0cfea7db 100644
--- a/src/mbgl/geometry/feature_index.hpp
+++ b/src/mbgl/geometry/feature_index.hpp
@@ -16,6 +16,7 @@ namespace mbgl {
class RenderedQueryOptions;
class RenderLayer;
class TransformState;
+class SourceFeatureState;
class CollisionIndex;
@@ -68,7 +69,8 @@ public:
const RenderedQueryOptions& options,
const UnwrappedTileID&,
const std::unordered_map<std::string, const RenderLayer*>&,
- const float additionalQueryPadding) const;
+ const float additionalQueryPadding,
+ const SourceFeatureState& sourceFeatureState) const;
static optional<GeometryCoordinates> translateQueryGeometry(
const GeometryCoordinates& queryGeometry,
@@ -96,7 +98,8 @@ private:
const GeometryCoordinates& queryGeometry,
const TransformState& transformState,
const float pixelsToTileUnits,
- const mat4& posMatrix) const;
+ const mat4& posMatrix,
+ const SourceFeatureState* sourceFeatureState) const;
GridIndex<IndexedSubfeature> grid;
unsigned int sortIndex = 0;
diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp
index 6859c454f3..f2297f7ed4 100644
--- a/src/mbgl/renderer/sources/render_tile_source.cpp
+++ b/src/mbgl/renderer/sources/render_tile_source.cpp
@@ -127,7 +127,7 @@ RenderTileSource::queryRenderedFeatures(const ScreenLineString& geometry,
const std::unordered_map<std::string, const RenderLayer*>& layers,
const RenderedQueryOptions& options,
const mat4& projMatrix) const {
- return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix);
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix, featureState);
}
std::vector<Feature> RenderTileSource::querySourceFeatures(const SourceQueryOptions& options) const {
diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp
index 7f0fad1500..db3e731605 100644
--- a/src/mbgl/renderer/tile_pyramid.cpp
+++ b/src/mbgl/renderer/tile_pyramid.cpp
@@ -283,7 +283,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
const TransformState& transformState,
const std::unordered_map<std::string, const RenderLayer*>& layers,
const RenderedQueryOptions& options,
- const mat4& projMatrix) const {
+ const mat4& projMatrix,
+ const SourceFeatureState& featureState) const {
std::unordered_map<std::string, std::vector<Feature>> result;
if (renderedTiles.empty() || geometry.empty()) {
return result;
@@ -336,7 +337,8 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
transformState,
layers,
options,
- projMatrix);
+ projMatrix,
+ featureState);
}
return result;
diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp
index f80eb0db78..bb0b7e9f67 100644
--- a/src/mbgl/renderer/tile_pyramid.hpp
+++ b/src/mbgl/renderer/tile_pyramid.hpp
@@ -54,7 +54,8 @@ public:
const TransformState& transformState,
const std::unordered_map<std::string, const RenderLayer*>&,
const RenderedQueryOptions& options,
- const mat4& projMatrix) const;
+ const mat4& projMatrix,
+ const mbgl::SourceFeatureState& featureState) const;
std::vector<Feature> querySourceFeatures(const SourceQueryOptions&) const;
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 8f624f21dc..2076c73337 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -308,7 +308,8 @@ void GeometryTile::queryRenderedFeatures(
const TransformState& transformState,
const std::unordered_map<std::string, const RenderLayer*>& layers,
const RenderedQueryOptions& options,
- const mat4& projMatrix) {
+ const mat4& projMatrix,
+ const SourceFeatureState& featureState) {
if (!getData()) return;
@@ -327,7 +328,8 @@ void GeometryTile::queryRenderedFeatures(
options,
id.toUnwrapped(),
layers,
- queryPadding * transformState.maxPitchScaleFactor());
+ queryPadding * transformState.maxPitchScaleFactor(),
+ featureState);
}
void GeometryTile::querySourceFeatures(
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index ca9e33218c..4415e0a1fa 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -54,7 +54,8 @@ public:
const TransformState&,
const std::unordered_map<std::string, const RenderLayer*>& layers,
const RenderedQueryOptions& options,
- const mat4& projMatrix) override;
+ const mat4& projMatrix,
+ const SourceFeatureState& featureState) override;
void querySourceFeatures(
std::vector<Feature>& result,
diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp
index 2f342c092d..87223c7933 100644
--- a/src/mbgl/tile/tile.cpp
+++ b/src/mbgl/tile/tile.cpp
@@ -45,7 +45,8 @@ void Tile::queryRenderedFeatures(
const TransformState&,
const std::unordered_map<std::string, const RenderLayer*>&,
const RenderedQueryOptions&,
- const mat4&) {}
+ const mat4&,
+ const SourceFeatureState&) {}
float Tile::getQueryPadding(const std::unordered_map<std::string, const RenderLayer*>&) {
return 0;
diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp
index 65bff305a3..eda4667027 100644
--- a/src/mbgl/tile/tile.hpp
+++ b/src/mbgl/tile/tile.hpp
@@ -28,6 +28,7 @@ class TileRenderData;
class RenderedQueryOptions;
class SourceQueryOptions;
class CollisionIndex;
+class SourceFeatureState;
namespace gfx {
class UploadPass;
@@ -73,7 +74,8 @@ public:
const TransformState&,
const std::unordered_map<std::string, const RenderLayer*>&,
const RenderedQueryOptions& options,
- const mat4& projMatrix);
+ const mat4& projMatrix,
+ const SourceFeatureState& featureState);
virtual void querySourceFeatures(
std::vector<Feature>& result,