summaryrefslogtreecommitdiff
path: root/src/mbgl/map/live_tile_data.cpp
blob: 4935c0134512aae17f3de3ffce3f901034de763f (plain)
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
#include <mbgl/map/annotation.hpp>
#include <mbgl/map/live_tile_data.hpp>
#include <mbgl/map/live_tile.hpp>
#include <mbgl/map/tile_parser.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/map/vector_tile.hpp>
#include <mbgl/platform/log.hpp>

using namespace mbgl;

LiveTileData::LiveTileData(const TileID& id_,
                           AnnotationManager& annotationManager_,
                           Style& style_,
                           GlyphAtlas& glyphAtlas_,
                           GlyphStore& glyphStore_,
                           SpriteAtlas& spriteAtlas_,
                           util::ptr<Sprite> sprite_,
                           const SourceInfo& source_,
                           float angle_,
                           bool collisionDebug_)
    : VectorTileData::VectorTileData(id_, style_, glyphAtlas_, glyphStore_,
                                     spriteAtlas_, sprite_, source_, angle_, collisionDebug_),
      annotationManager(annotationManager_) {
    // live features are always ready
    setState(State::loaded);
}

LiveTileData::~LiveTileData() {
    // Cancel in most derived class destructor so that worker tasks are joined before
    // any member data goes away.
    cancel();
}

void LiveTileData::parse() {
    if (getState() != State::loaded) {
        return;
    }

    const LiveTile* tile = annotationManager.getTile(id);

    if (tile) {
        try {
            // Parsing creates state that is encapsulated in TileParser. While parsing,
            // the TileParser object writes results into this objects. All other state
            // is going to be discarded afterwards.
            TileParser parser(*tile, *this, style, glyphAtlas, glyphStore, spriteAtlas, sprite);
            parser.parse();
        } catch (const std::exception& ex) {
            Log::Error(Event::ParseTile, "Live-parsing [%d/%d/%d] failed: %s", id.z, id.x, id.y, ex.what());
            setState(State::obsolete);
            return;
        }
    }

    if (getState() != State::obsolete) {
        setState(State::parsed);
    }
}