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

#include <mbgl/style/source.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/actor/mailbox.hpp>

namespace mbgl {

class OverscaledTileID;
class CanonicalTileID;

namespace style {

using TileFunction = std::function<void(const CanonicalTileID&)>;
class CustomTileLoader;

class CustomVectorSource : public Source {
public:
    struct TileOptions {
        double tolerance = 0.375;
        uint16_t tileSize = util::tileSize;
        uint16_t buffer = 128;
    };

    struct Options {
        TileFunction fetchTileFunction;
        TileFunction cancelTileFunction;
        Range<uint8_t> zoomRange = { 0, 18};
        TileOptions tileOptions;
    };
public:
    CustomVectorSource(std::string id, CustomVectorSource::Options options);
    ~CustomVectorSource() final;
    void loadDescription(FileSource&) final;
    void setTileData(const CanonicalTileID&, const mapbox::geojson::geojson&);

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

};

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

} // namespace style
} // namespace mbgl