blob: 8ecc9c3faeb14f139fe5028467a3507878e44377 (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#pragma once
#include <mbgl/util/noncopyable.hpp>
namespace mbgl {
class TileSource : private util::noncopyable {
public:
// TileSources can have two states: optional or required.
// - optional means that only low-cost actions should be taken to obtain the data
// (e.g. load from cache, but accept stale data)
// - required means that every effort should be taken to obtain the data (e.g. load
// from internet and keep the data fresh if it expires)
enum class Necessity : bool {
Optional = false,
Required = true,
};
protected:
TileSource() : necessity(Necessity::Optional) {
}
public:
virtual ~TileSource() = default;
bool isOptional() const {
return necessity == Necessity::Optional;
}
bool isRequired() const {
return necessity == Necessity::Required;
}
void setNecessity(Necessity newNecessity) {
if (newNecessity != necessity) {
necessity = newNecessity;
if (necessity == Necessity::Required) {
makeRequired();
} else {
makeOptional();
}
}
}
protected:
// called when the tile is one of the ideal tiles that we want to show definitely. the tile source
// should try to make every effort (e.g. fetch from internet, or revalidate existing resources).
virtual void makeRequired() {}
// called when the zoom level no longer corresponds to the displayed one, but
// we're still interested in retaining the tile, e.g. for backfill.
// subclassed TileSources should cancel actions they are taking to provide
// an up-to-date version or load new data
virtual void makeOptional() {}
protected:
Necessity necessity;
};
class GeometryTileData;
class RasterTileData;
class GeometryTileSource : public TileSource {
public:
using data_type = GeometryTileData;
protected:
GeometryTileSource(data_type& tileData_)
: tileData(tileData_) {
}
public:
virtual ~GeometryTileSource() = default;
protected:
data_type& tileData;
};
class RasterTileSource : public TileSource {
public:
using data_type = RasterTileData;
protected:
RasterTileSource(data_type& tileData_)
: tileData(tileData_){};
public:
virtual ~RasterTileSource() = default;
protected:
data_type& tileData;
};
} // namespace mbgl
|