forked from mapbox/mapbox-gl-native-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MGLLight.mm
133 lines (101 loc) · 4.86 KB
/
MGLLight.mm
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
// test
#import "MGLLight.h"
#import "MGLTypes.h"
#import "MGLStyleValue_Private.h"
#import "NSValue+MGLAdditions.h"
#import "MGLLoggingConfiguration_Private.h"
#import <mbgl/style/light.hpp>
#import <mbgl/style/types.hpp>
namespace mbgl {
MBGL_DEFINE_ENUM(MGLLightAnchor, {
{ MGLLightAnchorMap, "map" },
{ MGLLightAnchorViewport, "viewport" },
});
}
@interface MGLLight()
@end
@implementation MGLLight
- (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight
{
if (self = [super init]) {
MGLLogInfo(@"Initializing %@.", NSStringFromClass([self class]));
auto anchor = mbglLight->getAnchor();
NSExpression *anchorExpression;
if (anchor.isUndefined()) {
mbgl::style::PropertyValue<mbgl::style::LightAnchorType> defaultAnchor = mbglLight->getDefaultAnchor();
anchorExpression = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toExpression(defaultAnchor);
} else {
anchorExpression = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toExpression(anchor);
}
_anchor = anchorExpression;
auto positionValue = mbglLight->getPosition();
if (positionValue.isUndefined()) {
_position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toExpression(mbglLight->getDefaultPosition());
} else {
_position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toExpression(positionValue);
}
_positionTransition = MGLTransitionFromOptions(mbglLight->getPositionTransition());
auto colorValue = mbglLight->getColor();
if (colorValue.isUndefined()) {
_color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(mbglLight->getDefaultColor());
} else {
_color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(colorValue);
}
_colorTransition = MGLTransitionFromOptions(mbglLight->getColorTransition());
auto intensityValue = mbglLight->getIntensity();
if (intensityValue.isUndefined()) {
_intensity = MGLStyleValueTransformer<float, NSNumber *>().toExpression(mbglLight->getDefaultIntensity());
} else {
_intensity = MGLStyleValueTransformer<float, NSNumber *>().toExpression(intensityValue);
}
_intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition());
}
return self;
}
- (mbgl::style::Light)mbglLight
{
mbgl::style::Light mbglLight;
auto anchor = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::LightAnchorType>>(self.anchor, false);
mbglLight.setAnchor(anchor);
auto position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::Position>>(self.position, false);
mbglLight.setPosition(position);
mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransition));
auto color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(self.color, false);
mbglLight.setColor(color);
mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransition));
auto intensity = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(self.intensity, false);
mbglLight.setIntensity(intensity);
mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition));
return mbglLight;
}
- (void)setAnchor:(NSExpression *)anchor {
MGLLogDebug(@"Setting anchor: %@", anchor);
_anchor = anchor;
}
- (void)setPosition:(NSExpression *)position {
MGLLogDebug(@"Setting position: %@", position);
_position = position;
}
- (void)setPositionTransition:(MGLTransition)transition {
MGLLogDebug(@"Setting positionTransition: %@", MGLStringFromMGLTransition(transition));
_positionTransition = transition;
}
- (void)setColor:(NSExpression *)color {
MGLLogDebug(@"Setting color: %@", color);
_color = color;
}
- (void)setColorTransition:(MGLTransition)transition {
MGLLogDebug(@"Setting colorTransition: %@", MGLStringFromMGLTransition(transition));
_colorTransition = transition;
}
- (void)setIntensity:(NSExpression *)intensity {
MGLLogDebug(@"Setting intensity: %@", intensity);
_intensity = intensity;
}
- (void)setIntensityTransition:(MGLTransition)transition {
MGLLogDebug(@"Setting intensityTransition: %@", MGLStringFromMGLTransition(transition));
_intensityTransition = transition;
}
@end