summaryrefslogtreecommitdiff
path: root/platform/macos/app/MGLStyle+MBXAdditions.m
blob: be571d8b3013b8f1c84ee6b62e496fb0d8fde4bf (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
#import "MGLStyle+MBXAdditions.h"

@implementation MGLStyle (MBXAdditions)

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingReversedLayers {
    return [NSSet setWithObject:@"layers"];
}

- (NS_ARRAY_OF(__kindof MGLStyleLayer *) *)reversedLayers {
    return self.layers.reverseObjectEnumerator.allObjects;
}

- (void)setReversedLayers:(NS_ARRAY_OF(__kindof MGLStyleLayer *) *)reversedLayers {
    self.layers = reversedLayers.reverseObjectEnumerator.allObjects;
}

- (NSUInteger)countOfReversedLayers {
    return self.layers.count;
}

- (id)objectInReversedLayersAtIndex:(NSUInteger)index {
    NSArray *layers = self.layers;
    return layers[layers.count - 1 - index];
}

- (void)getReversedLayers:(__kindof MGLStyleLayer **)buffer range:(NSRange)inRange {
    NSArray *layers = self.layers;
    for (NSUInteger i = inRange.location; i < NSMaxRange(inRange); i++) {
        MGLStyleLayer *styleLayer = layers[layers.count - 1 - i];
        buffer[i] = styleLayer;
    }
}

- (void)insertObject:(__kindof MGLStyleLayer *)object inReversedLayersAtIndex:(NSUInteger)index {
    [self insertLayer:object atIndex:self.layers.count - index];
}

- (void)removeObjectFromReversedLayersAtIndex:(NSUInteger)index {
    [self removeLayer:[self objectInReversedLayersAtIndex:index]];
}

@end