summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/geojson_tile.hpp
blob: 340d1053c6c44371612e764ecc9ca5a5de8ed9c1 (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
#ifndef MBGL_ANNOTATION_GEOJSON_VT_TILE
#define MBGL_ANNOTATION_GEOJSON_VT_TILE

#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/map/tile_id.hpp>

#include <unordered_map>

namespace mapbox {
namespace geojsonvt {
class GeoJSONVT;
} // namespace geojsonvt
} // namespace mapbox

namespace mbgl {

// Implements a simple in-memory Tile type that holds GeoJSON values. A GeoJSON tile can only have
// one layer, and it is always returned regardless of which layer is requested.

class GeoJSONTileFeature : public GeometryTileFeature {
public:
    using Tags = std::unordered_map<std::string, std::string>;

    GeoJSONTileFeature(FeatureType, GeometryCollection&&, Tags&& = Tags{});
    FeatureType getType() const override;
    optional<Value> getValue(const std::string&) const override;
    GeometryCollection getGeometries() const override;

private:
    const FeatureType type;
    const GeometryCollection geometries;
    const Tags tags;
};

class GeoJSONTileLayer : public GeometryTileLayer {
public:
    using Features = std::vector<std::shared_ptr<const GeoJSONTileFeature>>;

    GeoJSONTileLayer(Features&&);
    std::size_t featureCount() const override;
    util::ptr<const GeometryTileFeature> getFeature(std::size_t) const override;

private:
    const Features features;
};

class GeoJSONTile : public GeometryTile {
public:
    GeoJSONTile(std::shared_ptr<GeoJSONTileLayer>);
    util::ptr<GeometryTileLayer> getLayer(const std::string&) const override;

private:
    const std::shared_ptr<GeoJSONTileLayer> layer;
};

class GeoJSONTileMonitor : public GeometryTileMonitor {
public:
    GeoJSONTileMonitor(mapbox::geojsonvt::GeoJSONVT*, const TileID&);
    virtual ~GeoJSONTileMonitor();

    std::unique_ptr<AsyncRequest> monitorTile(const GeometryTileMonitor::Callback&) override;

    void setGeoJSONVT(mapbox::geojsonvt::GeoJSONVT*);

private:
    void update();

public:
    const TileID tileID;

private:
    mapbox::geojsonvt::GeoJSONVT* geojsonvt = nullptr;
    GeometryTileMonitor::Callback callback;
};

} // namespace mbgl

#endif