From 428c0fdf70d08dfe433058a66a61bf9c4fb93d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 29 Dec 2016 23:24:22 -0800 Subject: [PATCH] [macos] Arrange layers top to bottom in sidebar Implemented a reversedLayers property on MGLStyle based on the layers property. --- platform/macos/app/Base.lproj/MapDocument.xib | 3 +- platform/macos/app/MGLStyle+MBXAdditions.h | 7 ++++ platform/macos/app/MGLStyle+MBXAdditions.m | 42 +++++++++++++++++++ platform/macos/app/MapDocument.m | 7 ++-- .../macos/macos.xcodeproj/project.pbxproj | 6 +++ 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 platform/macos/app/MGLStyle+MBXAdditions.h create mode 100644 platform/macos/app/MGLStyle+MBXAdditions.m diff --git a/platform/macos/app/Base.lproj/MapDocument.xib b/platform/macos/app/Base.lproj/MapDocument.xib index e147ba83d..4ba8f0a3a 100644 --- a/platform/macos/app/Base.lproj/MapDocument.xib +++ b/platform/macos/app/Base.lproj/MapDocument.xib @@ -27,6 +27,7 @@ layers name + reversedLayers @@ -38,7 +39,7 @@ visible - + diff --git a/platform/macos/app/MGLStyle+MBXAdditions.h b/platform/macos/app/MGLStyle+MBXAdditions.h new file mode 100644 index 000000000..dcaf42af2 --- /dev/null +++ b/platform/macos/app/MGLStyle+MBXAdditions.h @@ -0,0 +1,7 @@ +#import + +@interface MGLStyle (MBXAdditions) + +@property (nonatomic, strong) NS_ARRAY_OF(__kindof MGLStyleLayer *) *reversedLayers; + +@end diff --git a/platform/macos/app/MGLStyle+MBXAdditions.m b/platform/macos/app/MGLStyle+MBXAdditions.m new file mode 100644 index 000000000..be571d8b3 --- /dev/null +++ b/platform/macos/app/MGLStyle+MBXAdditions.m @@ -0,0 +1,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 diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 705ebb8a4..f00f773bf 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -4,6 +4,7 @@ #import "LimeGreenStyleLayer.h" #import "DroppedPinAnnotation.h" +#import "MGLStyle+MBXAdditions.h" #import "MGLVectorSource+MBXAdditions.h" #import @@ -256,7 +257,7 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id