blob: 57b42ecd1927eb67d89dd18df7b6f65f000578b0 (
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
|
#include <mbgl/tile/geometry_tile_data.hpp>
#include <protozero/pbf_reader.hpp>
#include <unordered_map>
#include <functional>
#include <utility>
namespace mbgl {
class VectorTileLayer;
using packed_iter_type = protozero::iterator_range<protozero::pbf_reader::const_uint32_iterator>;
struct VectorTileLayerData {
VectorTileLayerData(std::shared_ptr<const std::string>);
// Hold a reference to the underlying pbf data that backs the lazily-built
// components of the owning VectorTileLayer and VectorTileFeature objects
std::shared_ptr<const std::string> data;
uint32_t version = 1;
uint32_t extent = 4096;
std::unordered_map<std::string, uint32_t> keysMap;
std::vector<std::reference_wrapper<const std::string>> keys;
std::vector<Value> values;
};
class VectorTileFeature : public GeometryTileFeature {
public:
VectorTileFeature(protozero::pbf_reader, std::shared_ptr<VectorTileLayerData> layerData);
FeatureType getType() const override { return type; }
optional<Value> getValue(const std::string&) const override;
std::unordered_map<std::string,Value> getProperties() const override;
optional<FeatureIdentifier> getID() const override;
GeometryCollection getGeometries() const override;
private:
std::shared_ptr<VectorTileLayerData> layerData;
optional<FeatureIdentifier> id;
FeatureType type = FeatureType::Unknown;
packed_iter_type tags_iter;
packed_iter_type geometry_iter;
};
class VectorTileLayer : public GeometryTileLayer {
public:
VectorTileLayer(protozero::pbf_reader, std::shared_ptr<const std::string>);
std::size_t featureCount() const override { return features.size(); }
std::unique_ptr<GeometryTileFeature> getFeature(std::size_t) const override;
std::string getName() const override;
private:
friend class VectorTileData;
friend class VectorTileFeature;
std::string name;
std::vector<protozero::pbf_reader> features;
std::shared_ptr<VectorTileLayerData> data;
};
class VectorTileData : public GeometryTileData {
public:
VectorTileData(std::shared_ptr<const std::string> data);
std::unique_ptr<GeometryTileData> clone() const override {
return std::make_unique<VectorTileData>(*this);
}
const GeometryTileLayer* getLayer(const std::string&) const override;
std::vector<std::string> layerNames() const;
private:
void parse() const;
private:
std::shared_ptr<const std::string> data;
mutable bool parsed = false;
mutable std::unordered_map<std::string, VectorTileLayer> layers;
};
} // namespace mbgl
|