summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/custom_layer.cpp
blob: 4f69ce8b52c59855ca57094b40ad73e1f5db98c3 (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
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/layers/custom_layer_impl.hpp>
#include <mbgl/style/layer_observer.hpp>

namespace mbgl {
namespace style {

CustomLayer::~CustomLayer()
{
    printf("~CustomLayer destructor %p\n", this);

    // Need to set rawLayer to nil in the obj-c layer.
    onDestruction();
}

CustomLayer::CustomLayer(const std::string& layerID,
                         std::unique_ptr<CustomLayerContext> context):
    Layer(makeMutable<Impl>(layerID, std::move(context)))
{
    printf("CustomLayer::CustomLayer %p\n", this);

}

const CustomLayer::Impl& CustomLayer::impl() const {
    return static_cast<const Impl&>(*baseImpl);
}

Mutable<CustomLayer::Impl> CustomLayer::mutableImpl() const {
    return makeMutable<Impl>(impl());
}

std::unique_ptr<Layer> CustomLayer::cloneRef(const std::string&) const {
    assert(false);
    return nullptr;
}

void CustomLayer::setObserver(LayerObserver* observer) {

    Layer::setObserver(observer);

    impl().didSetObserver(observer != NULL);
}

// Visibility

void CustomLayer::setVisibility(VisibilityType value) {
    if (value == getVisibility())
        return;
    auto impl_ = mutableImpl();
    impl_->visibility = value;
    baseImpl = std::move(impl_);
    observer->onLayerChanged(*this);
}

// Zoom range

void CustomLayer::setMinZoom(float minZoom) {
    auto impl_ = mutableImpl();
    impl_->minZoom = minZoom;
    baseImpl = std::move(impl_);
}

void CustomLayer::setMaxZoom(float maxZoom) {
    auto impl_ = mutableImpl();
    impl_->maxZoom = maxZoom;
    baseImpl = std::move(impl_);
}

template <>
bool Layer::is<CustomLayer>() const {
    return getType() == LayerType::Custom;
}

} // namespace style
} // namespace mbgl