summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/vector_tile_data.cpp
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2016-04-05 16:27:37 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-04-29 12:00:24 -0700
commit61d14089e0dd742719328fd74c693bcae6274a4b (patch)
treee47265a472fe75c635a22815ddc4a0c3fa1dbf84 /src/mbgl/tile/vector_tile_data.cpp
parent25442a77be75001665771097d8978b1191e403d9 (diff)
downloadqtlocation-mapboxgl-61d14089e0dd742719328fd74c693bcae6274a4b.tar.gz
[core] implement queryRenderedFeatures
Diffstat (limited to 'src/mbgl/tile/vector_tile_data.cpp')
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index 9727b4cb0b..c71b2b733d 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -5,6 +5,8 @@
#include <mbgl/util/work_request.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/storage/file_source.hpp>
+#include <mbgl/geometry/feature_index.hpp>
+#include <mbgl/text/collision_tile.hpp>
namespace mbgl {
@@ -65,8 +67,8 @@ VectorTileData::VectorTileData(const TileID& id_,
}
std::exception_ptr error;
- if (result.is<TileParseResultBuckets>()) {
- auto& resultBuckets = result.get<TileParseResultBuckets>();
+ if (result.is<TileParseResultData>()) {
+ auto& resultBuckets = result.get<TileParseResultData>();
state = resultBuckets.state;
// Persist the configuration we just placed so that we can later check whether we need to
@@ -77,6 +79,11 @@ VectorTileData::VectorTileData(const TileID& id_,
// existing buckets in case we got a refresh parse.
buckets = std::move(resultBuckets.buckets);
+ if (state == State::parsed) {
+ featureIndex = std::move(resultBuckets.featureIndex);
+ geometryTile = std::move(resultBuckets.geometryTile);
+ }
+
} else {
error = result.get<std::exception_ptr>();
state = State::obsolete;
@@ -105,8 +112,8 @@ bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callba
}
std::exception_ptr error;
- if (result.is<TileParseResultBuckets>()) {
- auto& resultBuckets = result.get<TileParseResultBuckets>();
+ if (result.is<TileParseResultData>()) {
+ auto& resultBuckets = result.get<TileParseResultData>();
state = resultBuckets.state;
// Move over all buckets we received in this parse request, potentially overwriting
@@ -119,6 +126,11 @@ bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callba
// place again in case the configuration has changed.
placedConfig = config;
+ if (state == State::parsed) {
+ featureIndex = std::move(resultBuckets.featureIndex);
+ geometryTile = std::move(resultBuckets.geometryTile);
+ }
+
} else {
error = result.get<std::exception_ptr>();
state = State::obsolete;
@@ -153,7 +165,7 @@ void VectorTileData::redoPlacement(const std::function<void()>& callback) {
// we are parsing buckets.
if (workRequest) return;
- workRequest = worker.redoPlacement(tileWorker, buckets, targetConfig, [this, callback, config = targetConfig] {
+ workRequest = worker.redoPlacement(tileWorker, buckets, targetConfig, [this, callback, config = targetConfig](std::unique_ptr<CollisionTile> collisionTile) {
workRequest.reset();
// Persist the configuration we just placed so that we can later check whether we need to
@@ -164,6 +176,10 @@ void VectorTileData::redoPlacement(const std::function<void()>& callback) {
bucket.second->swapRenderData();
}
+ if (featureIndex) {
+ featureIndex->setCollisionTile(std::move(collisionTile));
+ }
+
// The target configuration could have changed since we started placement. In this case,
// we're starting another placement run.
if (placedConfig != targetConfig) {
@@ -174,6 +190,19 @@ void VectorTileData::redoPlacement(const std::function<void()>& callback) {
});
}
+void VectorTileData::queryRenderedFeatures(
+ std::unordered_map<std::string, std::vector<std::string>>& result,
+ const GeometryCollection& queryGeometry,
+ const double bearing,
+ const double tileSize,
+ const double scale,
+ const optional<std::vector<std::string>>& layerIDs) {
+
+ if (!featureIndex || !geometryTile) return;
+
+ featureIndex->query(result, queryGeometry, bearing, tileSize, scale, layerIDs, *geometryTile, style);
+}
+
void VectorTileData::cancel() {
state = State::obsolete;
tileRequest.reset();