summaryrefslogtreecommitdiff
path: root/include/mbgl/style/sources/custom_vector_source.hpp
blob: 78835f2bed9ad3d4ca6362dbb25bb84d25cf8a62 (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
#pragma once

#include <mbgl/style/source.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/util/noncopyable.hpp>

namespace mbgl {
namespace style {

struct Error { std::string message; };

using SetTileDataFunction = std::function<void(const CanonicalTileID& tileID, const mapbox::geojson::geojson&)>;
using TileFunction = std::function<void(const CanonicalTileID&)>;

class CustomTileLoader : private util::noncopyable {
public:
    CustomTileLoader(TileFunction&& fetchTileFn, TileFunction&& cancelTileFn);
    ~CustomTileLoader();
    void fetchTile(const CanonicalTileID& tileID, ActorRef<SetTileDataFunction> callbackRef);
    void cancelTile(const CanonicalTileID& tileID);
    void setTileData(const CanonicalTileID& tileID, const mapbox::geojson::geojson& data);
    void removeTile(const CanonicalTileID& tileID);
private:
    class Impl;
    Impl* impl = nullptr;
};

class CustomVectorSource : public Source {
public:
    CustomVectorSource(std::string id,
                       GeoJSONOptions options,
                       TileFunction fetchTile,
                       TileFunction cancelTile);

    void loadDescription(FileSource&) final;
    void setTileData(const CanonicalTileID&, const mapbox::geojson::geojson& geojson);

    // Private implementation
    class Impl;
    const Impl& impl() const;
private:
    std::shared_ptr<Mailbox> mailbox;
    CustomTileLoader loader;

};

template <>
inline bool Source::is<CustomVectorSource>() const {
    return getType() == SourceType::CustomVector;
}

} // namespace style
} // namespace mbgl