summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyleAttribute.mm
blob: a30ef534f4a7395f494987f2bf4a9e9db0bb50b2 (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
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
#import "MGLStyleAttribute.h"

#import "MGLStyleAttributeValue_Private.h"
#import "MGLStyleAttributeFunction_Private.h"

@interface MGLStyleAttribute()
@end

@implementation MGLStyleAttribute

+ (id <MGLStyleAttributeValue>)mbgl_colorPropertyValueWith:(mbgl::style::PropertyValue<mbgl::Color>)property
{
    if (property.isConstant()) {
        return [MGLColor mbgl_colorWithColor:property.asConstant()];
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithColorPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id <MGLStyleAttributeValue>)mbgl_numberPropertyValueWith:(mbgl::style::PropertyValue<float>)property
{
    if (property.isConstant()) {
        return @(property.asConstant());
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithNumberPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_boolPropertyValueWith:(mbgl::style::PropertyValue<bool>)property
{
    if (property.isConstant()) {
        return @(property.asConstant());
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithBoolPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_stringPropertyValueWith:(mbgl::style::PropertyValue<std::string>)property
{
    if (property.isConstant()) {
        return @(property.asConstant().c_str());
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithStringPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_offsetPropertyValueWith:(mbgl::style::PropertyValue<std::array<float, 2> >)property
{
    if (property.isConstant()) {
        auto offset = property.asConstant();
        return @[@(offset[0]), @(offset[1])];
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithOffsetPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_paddingPropertyValueWith:(mbgl::style::PropertyValue<std::array<float, 4> >)property
{
    if (property.isConstant()) {
        auto padding = property.asConstant();
        return @[@(padding[0]), @(padding[1]), @(padding[2]), @(padding[3])];
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithPaddingPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_stringArrayPropertyValueWith:(mbgl::style::PropertyValue<std::vector<std::string> >)property
{
    if (property.isConstant()) {
        auto strings = property.asConstant();
        NSMutableArray *convertedStrings = [[NSMutableArray alloc] initWithCapacity:strings.size()];
        for (auto string : strings) {
            [convertedStrings addObject:@(string.c_str())];
        }
        return convertedStrings;
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithStringArrayPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

+ (id<MGLStyleAttributeValue>)mbgl_numberArrayPropertyValueWith:(mbgl::style::PropertyValue<std::vector<float> >)property
{
    if (property.isConstant()) {
        auto numbers = property.asConstant();
        NSMutableArray *convertedNumbers = [NSMutableArray arrayWithCapacity:numbers.size()];
        for (auto number : numbers) {
            [convertedNumbers addObject:@(number)];
        }
        return convertedNumbers;
    } else if (property.isFunction()) {
        return [MGLStyleAttributeFunction functionWithNumberArrayPropertyValue:property.asFunction()];
    } else {
        return nil;
    }
}

@end