summaryrefslogtreecommitdiff
path: root/include/llmr/map/tile_data.hpp
blob: 09f36d59b0436f3e516c2b3d0d07dddde0daad61 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef LLMR_MAP_TILE_DATA
#define LLMR_MAP_TILE_DATA

#include <llmr/map/tile.hpp>
#include <llmr/util/noncopyable.hpp>
#include <llmr/platform/platform.hpp>
#include <llmr/geometry/vao.hpp>
#include <llmr/renderer/debug_bucket.hpp>

#include <cstdint>
#include <string>
#include <memory>
#include <atomic>

namespace llmr {

class Map;
class Painter;
class StyleLayer;

class TileData : public std::enable_shared_from_this<TileData>,
             private util::noncopyable {
public:
    struct exception : std::exception {};
    struct geometry_too_long_exception : exception {};

public:
    typedef std::shared_ptr<TileData> Ptr;

    enum class State {
        invalid,
        initial,
        loading,
        loaded,
        parsed,
        obsolete
    };

public:
    TileData(Tile::ID id, Map &map, const std::string url);
    ~TileData();

    void request();
    void cancel();
    void reparse();
    const std::string toString() const;

    // Override this in the child class.
    virtual void beforeParse();
    virtual void parse() = 0;
    virtual void afterParse();
    virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc) = 0;
    virtual bool hasData(std::shared_ptr<StyleLayer> layer_desc) const = 0;


public:
    const Tile::ID id;
    std::atomic<State> state;

protected:
    Map &map;

    // Request-related information.
    const std::string url;
    std::weak_ptr<platform::Request> req;
    std::string data;

    // Contains the tile ID string for painting debug information.
    DebugFontBuffer debugFontBuffer;

public:
    DebugBucket debugBucket;
};

}

#endif