summaryrefslogtreecommitdiff
path: root/src/mbgl/map/live_tile_data.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-10-26 15:45:32 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-10-26 16:44:55 +0100
commit75dec6ffac6f3e79e5a173cd8a3f98d374ed1c09 (patch)
treedd3e2752cfe2c1ea741ac1b97d38e5e4bc4aa008 /src/mbgl/map/live_tile_data.cpp
parentc0c554e36fd43bfe57ef13fe60f9cd50b5c018fd (diff)
downloadqtlocation-mapboxgl-75dec6ffac6f3e79e5a173cd8a3f98d374ed1c09.tar.gz
[core] always reparse with the freshest possible placement config
Fixes an issue where updates to stale tiles would remove labels altogether until the map was rotated.
Diffstat (limited to 'src/mbgl/map/live_tile_data.cpp')
-rw-r--r--src/mbgl/map/live_tile_data.cpp64
1 files changed, 54 insertions, 10 deletions
diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp
index fb8e6c3605..89b1d6fda4 100644
--- a/src/mbgl/map/live_tile_data.cpp
+++ b/src/mbgl/map/live_tile_data.cpp
@@ -14,17 +14,12 @@ using namespace mbgl;
LiveTileData::LiveTileData(const TileID& id_,
std::unique_ptr<AnnotationTile> tile_,
- Style& style_,
- const SourceInfo& source_,
+ Style& style,
+ const SourceInfo& source,
std::function<void()> callback)
: TileData(id_),
- worker(style_.workers),
- tileWorker(id_,
- source_.source_id,
- style_,
- style_.layers,
- state,
- std::make_unique<CollisionTile>(0, 0, false)),
+ worker(style.workers),
+ tileWorker(id, source.source_id, style, style.layers, state),
tile(std::move(tile_)) {
state = State::loaded;
@@ -41,25 +36,41 @@ bool LiveTileData::parsePending(std::function<void()> callback) {
return false;
}
- workRequest = worker.parseLiveTile(tileWorker, *tile, [this, callback] (TileParseResult result) {
+ workRequest.reset();
+ workRequest = worker.parseLiveTile(tileWorker, *tile, targetConfig, [this, callback, config = targetConfig] (TileParseResult result) {
workRequest.reset();
if (result.is<TileParseResultBuckets>()) {
auto& resultBuckets = result.get<TileParseResultBuckets>();
state = resultBuckets.state;
+ // Persist the configuration we just placed so that we can later check whether we need
+ // to place again in case the configuration has changed.
+ placedConfig = config;
+
// Move over all buckets we received in this parse request, potentially overwriting
// existing buckets in case we got a refresh parse.
for (auto& bucket : resultBuckets.buckets) {
buckets[bucket.first] = std::move(bucket.second);
}
+ // The target configuration could have changed since we started placement. In this case,
+ // we're starting another placement run.
+ if (placedConfig != targetConfig) {
+ redoPlacement();
+ }
} else {
error = result.get<std::string>();
state = State::obsolete;
}
callback();
+
+ // The target configuration could have changed since we started placement. In this case,
+ // we're starting another placement run.
+ if (!workRequest && placedConfig != targetConfig) {
+ redoPlacement();
+ }
});
return true;
@@ -87,3 +98,36 @@ void LiveTileData::cancel() {
state = State::obsolete;
workRequest.reset();
}
+
+void LiveTileData::redoPlacement(const PlacementConfig newConfig) {
+ if (newConfig != placedConfig) {
+ targetConfig = newConfig;
+
+ if (!workRequest) {
+ // Don't start a new placement request when the current one hasn't completed yet, or
+ // when we are parsing buckets.
+ redoPlacement();
+ }
+ }
+}
+
+void LiveTileData::redoPlacement() {
+ workRequest.reset();
+ workRequest = worker.redoPlacement(tileWorker, buckets, targetConfig, [this, config = targetConfig] {
+ workRequest.reset();
+
+ // Persist the configuration we just placed so that we can later check whether we need to
+ // place again in case the configuration has changed.
+ placedConfig = config;
+
+ for (auto& bucket : buckets) {
+ bucket.second->swapRenderData();
+ }
+
+ // The target configuration could have changed since we started placement. In this case,
+ // we're starting another placement run.
+ if (placedConfig != targetConfig) {
+ redoPlacement();
+ }
+ });
+}