blob: 2d47515e0fe5298295069c1741d91b2d0fc82643 (
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
|
#include <mbgl/tile/vector_tile_data.hpp>
#include <mbgl/util/constants.hpp>
namespace mbgl {
VectorTileFeature::VectorTileFeature(const mapbox::vector_tile::layer& layer,
const protozero::data_view& view)
: feature(view, layer) {
}
FeatureType VectorTileFeature::getType() const {
switch (feature.getType()) {
case mapbox::vector_tile::GeomType::POINT:
return FeatureType::Point;
case mapbox::vector_tile::GeomType::LINESTRING:
return FeatureType::LineString;
case mapbox::vector_tile::GeomType::POLYGON:
return FeatureType::Polygon;
default:
return FeatureType::Unknown;
}
}
optional<Value> VectorTileFeature::getValue(const std::string& key) const {
const optional<Value> value(feature.getValue(key));
return value->is<NullValue>() ? nullopt : std::move(value);
}
std::unordered_map<std::string, Value> VectorTileFeature::getProperties() const {
return feature.getProperties();
}
FeatureIdentifier VectorTileFeature::getID() const {
return feature.getID();
}
GeometryCollection VectorTileFeature::getGeometries() const {
const float scale = float(util::EXTENT) / feature.getExtent();
auto lines = feature.getGeometries<GeometryCollection>(scale);
if (feature.getVersion() >= 2 || feature.getType() != mapbox::vector_tile::GeomType::POLYGON) {
return lines;
} else {
return fixupPolygons(lines);
}
}
VectorTileLayer::VectorTileLayer(std::shared_ptr<const std::string> data_,
const protozero::data_view& view)
: data(std::move(data_)), layer(view) {
}
std::size_t VectorTileLayer::featureCount() const {
return layer.featureCount();
}
std::unique_ptr<GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i) const {
return std::make_unique<VectorTileFeature>(layer, layer.getFeature(i));
}
std::string VectorTileLayer::getName() const {
return layer.getName();
}
VectorTileData::VectorTileData(std::shared_ptr<const std::string> data_) : data(std::move(data_)) {
}
std::unique_ptr<GeometryTileData> VectorTileData::clone() const {
return std::make_unique<VectorTileData>(data);
}
std::unique_ptr<GeometryTileLayer> VectorTileData::getLayer(const std::string& name) const {
if (!parsed) {
// We're parsing this lazily so that we can construct VectorTileData objects on the main
// thread without incurring the overhead of parsing immediately.
layers = mapbox::vector_tile::buffer(*data).getLayers();
parsed = true;
}
auto it = layers.find(name);
if (it != layers.end()) {
return std::make_unique<VectorTileLayer>(data, it->second);
}
return nullptr;
}
std::vector<std::string> VectorTileData::layerNames() const {
return mapbox::vector_tile::buffer(*data).layerNames();
}
} // namespace mbgl
|