summaryrefslogtreecommitdiff
path: root/src/map/vector_tile_data.cpp
blob: 3c972aa319bd2a6d24be7860c8792024fa3ad35c (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
#include <llmr/map/vector_tile_data.hpp>

#include <llmr/map/map.hpp>
#include <llmr/map/tile_parser.hpp>

using namespace llmr;

VectorTileData::VectorTileData(Tile::ID id, Map &map, const std::string url)
    : TileData(id, map, url) {
}

VectorTileData::~VectorTileData() {
    map.getGlyphAtlas().removeGlyphs(id.to_uint64());
}

void VectorTileData::parse() {
    if (state != State::loaded) {
        return;
    }

    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(data, *this, map.getStyle(), map.getGlyphAtlas(), map.getGlyphStore(), map.getSpriteAtlas());
    } catch (const std::exception& ex) {
        fprintf(stderr, "[%p] exception [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what());
        cancel();
        return;
    }

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

void VectorTileData::render(Painter &painter, const LayerDescription& layer_desc) {
    auto databucket_it = buckets.find(layer_desc.bucket_name);
    if (databucket_it != buckets.end()) {
        assert(databucket_it->second);
        databucket_it->second->render(painter, layer_desc.name, id);
    }
}

bool VectorTileData::hasData(const LayerDescription& layer_desc) const {
    if (state != State::parsed) return false;

    auto databucket_it = buckets.find(layer_desc.bucket_name);
    if (databucket_it != buckets.end()) {
        assert(databucket_it->second);
        return databucket_it->second->hasData();
    } else {
        return false;
    }
}