1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <mbgl/map/live_tile_data.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/text/collision_tile.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
#include <mbgl/style/style.hpp>
#include <sstream>
using namespace mbgl;
LiveTileData::LiveTileData(const TileID& id_,
std::unique_ptr<AnnotationTile> tile_,
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)),
tile(std::move(tile_)) {
state = State::loaded;
if (!tile) {
state = State::parsed;
return;
}
reparse(callback);
}
bool LiveTileData::reparse(std::function<void()> callback) {
if (parsing || (state != State::loaded && state != State::partial)) {
return false;
}
parsing = true;
workRequest = worker.parseLiveTile(tileWorker, *tile, [this, callback] (TileParseResult result) {
parsing = false;
if (result.is<State>()) {
state = result.get<State>();
} else {
error = result.get<std::string>();
state = State::obsolete;
}
callback();
});
return true;
}
LiveTileData::~LiveTileData() {
cancel();
}
Bucket* LiveTileData::getBucket(const StyleLayer& layer) {
if (!isReady() || !layer.bucket) {
return nullptr;
}
return tileWorker.getBucket(layer);
}
void LiveTileData::cancel() {
state = State::obsolete;
workRequest.reset();
}
|