blob: cdb585aa29564271868d8afd7ba8ae954f0c930b (
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
|
#pragma once
#include <mbgl/style/layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/color_ramp_property_value.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/data_driven_property_value.hpp>
#include <mbgl/style/conversion/transition_options.hpp>
#include <string>
namespace mbgl {
namespace style {
namespace conversion {
using PropertySetter = optional<Error> (*) (Layer&, const Convertible&);
template <class L, class PropertyValue, void (L::*setter)(PropertyValue), bool convertTokens = false>
optional<Error> setProperty(Layer& layer, const Convertible& value) {
auto* typedLayer = layer.as<L>();
if (!typedLayer) {
return Error { "layer doesn't support this property" };
}
Error error;
optional<PropertyValue> typedValue = convert<PropertyValue>(value, error, convertTokens);
if (!typedValue) {
return error;
}
(typedLayer->*setter)(*typedValue);
return nullopt;
}
template <class L, void (L::*setter)(const TransitionOptions&)>
optional<Error> setTransition(Layer& layer, const Convertible& value) {
auto* typedLayer = layer.as<L>();
if (!typedLayer) {
return Error { "layer doesn't support this property" };
}
Error error;
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
if (!transition) {
return error;
}
(typedLayer->*setter)(*transition);
return nullopt;
}
inline optional<Error> setVisibility(Layer& layer, const Convertible& value) {
if (isUndefined(value)) {
layer.setVisibility(VisibilityType::Visible);
return nullopt;
}
Error error;
optional<VisibilityType> visibility = convert<VisibilityType>(value, error);
if (!visibility) {
return error;
}
layer.setVisibility(*visibility);
return nullopt;
}
} // namespace conversion
} // namespace style
} // namespace mbgl
|