summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/symbol_layer_impl.hpp
blob: 0d9a7c07e390f378df58eb1b856503e8e2905ed9 (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
#pragma once

#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>

namespace mbgl {

class SpriteAtlas;
class SymbolLayout;

namespace style {

// Repackaging evaluated values from SymbolLayoutProperties + SymbolPaintProperties
// for genericity over icons vs. text.
class SymbolPropertyValues {
public:
    // Layout
    AlignmentType pitchAlignment;
    AlignmentType rotationAlignment;
    float layoutSize;

    // Paint
    float opacity;
    Color color;
    Color haloColor;
    float haloWidth;
    float haloBlur;
    std::array<float, 2> translate;
    TranslateAnchorType translateAnchor;
    float paintSize;

    float sdfScale;   // Constant (1.0 or 24.0)

    bool hasHalo() const {
        return haloColor.a > 0.0f && haloWidth > 0.0f;
    }

    bool hasForeground() const {
        return color.a > 0.0f;
    }
};

class SymbolLayer::Impl : public Layer::Impl {
public:
    std::unique_ptr<Layer> clone() const override;
    std::unique_ptr<Layer> cloneRef(const std::string& id) const override;
    void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;

    void cascade(const CascadeParameters&) override;
    bool evaluate(const PropertyEvaluationParameters&) override;

    std::unique_ptr<Bucket> createBucket(BucketParameters&, const GeometryTileLayer&) const override;
    std::unique_ptr<SymbolLayout> createLayout(BucketParameters&, const GeometryTileLayer&,
                                               std::vector<std::unique_ptr<Layer>>) const;

    SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const;
    SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const;

    SymbolLayoutProperties layout;
    SymbolPaintProperties paint;

    float iconSize = 1.0f;
    float textSize = 16.0f;

    SpriteAtlas* spriteAtlas = nullptr;
};

} // namespace style
} // namespace mbgl