diff options
author | Jason Wray <jason@mapbox.com> | 2018-01-02 15:36:37 -0500 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2018-01-02 19:36:31 -0500 |
commit | 637892cd6f0f8953b787b9d727bdf82ed3813c96 (patch) | |
tree | 20341a2b2908cec211b37ead7dab3b6cd2b5d170 /platform/darwin | |
parent | 1dd5e405c113bac4446b5b5175b92ce7ff7467bf (diff) | |
download | qtlocation-mapboxgl-637892cd6f0f8953b787b9d727bdf82ed3813c96.tar.gz |
[ios, macos] Move private categories into explicitly private headers
Instead of creating `MGLAdditions` categories/files for our own classes, this standardizes on the `Private` convention that we had been using elsewhere.
This also fixes build errors where the `MGLAdditions` categories weren't importing their parents.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/src/MGLFeature.mm | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolygon+MGLAdditions.h | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolygon+MGLAdditions.m | 27 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolygon.mm | 26 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolygon_Private.h | 11 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolyline+MGLAdditions.h | 7 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolyline+MGLAdditions.m | 14 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolyline.mm | 13 | ||||
-rw-r--r-- | platform/darwin/src/MGLPolyline_Private.h | 12 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource+MGLAdditions.h | 15 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource+MGLAdditions.m | 53 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource.mm | 53 | ||||
-rw-r--r-- | platform/darwin/src/MGLVectorSource_Private.h | 7 |
14 files changed, 122 insertions, 131 deletions
diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm index 84f1a1ff25..033052bda8 100644 --- a/platform/darwin/src/MGLFeature.mm +++ b/platform/darwin/src/MGLFeature.mm @@ -7,11 +7,11 @@ #import "MGLShape_Private.h" #import "MGLPointCollection_Private.h" -#import "MGLPolyline+MGLAdditions.h" -#import "MGLPolygon+MGLAdditions.h" +#import "MGLPolyline_Private.h" +#import "MGLPolygon_Private.h" + #import "NSDictionary+MGLAdditions.h" #import "NSArray+MGLAdditions.h" - #import "NSExpression+MGLAdditions.h" #import <mbgl/util/geometry.hpp> diff --git a/platform/darwin/src/MGLPolygon+MGLAdditions.h b/platform/darwin/src/MGLPolygon+MGLAdditions.h deleted file mode 100644 index f409fb96ca..0000000000 --- a/platform/darwin/src/MGLPolygon+MGLAdditions.h +++ /dev/null @@ -1,7 +0,0 @@ -#import <Mapbox/Mapbox.h> - -@interface MGLPolygon (MGLAdditions) - -- (NS_ARRAY_OF(id) *)mgl_coordinates; - -@end diff --git a/platform/darwin/src/MGLPolygon+MGLAdditions.m b/platform/darwin/src/MGLPolygon+MGLAdditions.m deleted file mode 100644 index 3e76a37157..0000000000 --- a/platform/darwin/src/MGLPolygon+MGLAdditions.m +++ /dev/null @@ -1,27 +0,0 @@ -#import "MGLPolygon+MGLAdditions.h" - -@implementation MGLPolygon (MGLAdditions) - -- (NS_ARRAY_OF(id) *)mgl_coordinates { - NSMutableArray *coordinates = [NSMutableArray array]; - - NSMutableArray *exteriorRing = [NSMutableArray array]; - for (NSUInteger index = 0; index < self.pointCount; index++) { - CLLocationCoordinate2D coordinate = self.coordinates[index]; - [exteriorRing addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; - } - [coordinates addObject:exteriorRing]; - - for (MGLPolygon *interiorPolygon in self.interiorPolygons) { - NSMutableArray *interiorRing = [NSMutableArray array]; - for (int index = 0; index < interiorPolygon.pointCount; index++) { - CLLocationCoordinate2D coordinate = interiorPolygon.coordinates[index]; - [interiorRing addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; - } - [coordinates addObject:interiorRing]; - } - - return [coordinates copy]; -} - -@end diff --git a/platform/darwin/src/MGLPolygon.mm b/platform/darwin/src/MGLPolygon.mm index e7843224e9..2af768d514 100644 --- a/platform/darwin/src/MGLPolygon.mm +++ b/platform/darwin/src/MGLPolygon.mm @@ -1,9 +1,9 @@ -#import "MGLPolygon.h" +#import "MGLPolygon_Private.h" #import "MGLMultiPoint_Private.h" #import "MGLGeometry_Private.h" -#import "MGLPolygon+MGLAdditions.h" +#import "MGLFeature.h" #import <mbgl/util/geojson.hpp> #import <mapbox/polylabel.hpp> @@ -102,6 +102,28 @@ @"coordinates": self.mgl_coordinates}; } +- (NS_ARRAY_OF(id) *)mgl_coordinates { + NSMutableArray *coordinates = [NSMutableArray array]; + + NSMutableArray *exteriorRing = [NSMutableArray array]; + for (NSUInteger index = 0; index < self.pointCount; index++) { + CLLocationCoordinate2D coordinate = self.coordinates[index]; + [exteriorRing addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; + } + [coordinates addObject:exteriorRing]; + + for (MGLPolygon *interiorPolygon in self.interiorPolygons) { + NSMutableArray *interiorRing = [NSMutableArray array]; + for (int index = 0; index < interiorPolygon.pointCount; index++) { + CLLocationCoordinate2D coordinate = interiorPolygon.coordinates[index]; + [interiorRing addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; + } + [coordinates addObject:interiorRing]; + } + + return [coordinates copy]; +} + @end @interface MGLMultiPolygon () diff --git a/platform/darwin/src/MGLPolygon_Private.h b/platform/darwin/src/MGLPolygon_Private.h new file mode 100644 index 0000000000..75afcd61f6 --- /dev/null +++ b/platform/darwin/src/MGLPolygon_Private.h @@ -0,0 +1,11 @@ +#import "MGLPolygon.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLPolygon (Private) + +- (NS_ARRAY_OF(id) *)mgl_coordinates; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLPolyline+MGLAdditions.h b/platform/darwin/src/MGLPolyline+MGLAdditions.h deleted file mode 100644 index 4cdbbf17f9..0000000000 --- a/platform/darwin/src/MGLPolyline+MGLAdditions.h +++ /dev/null @@ -1,7 +0,0 @@ -#import <Mapbox/Mapbox.h> - -@interface MGLPolyline (MGLAdditions) - -- (NS_ARRAY_OF(id) *)mgl_coordinates; - -@end diff --git a/platform/darwin/src/MGLPolyline+MGLAdditions.m b/platform/darwin/src/MGLPolyline+MGLAdditions.m deleted file mode 100644 index d1db2c58a0..0000000000 --- a/platform/darwin/src/MGLPolyline+MGLAdditions.m +++ /dev/null @@ -1,14 +0,0 @@ -#import "MGLPolyline+MGLAdditions.h" - -@implementation MGLPolyline (MGLAdditions) - -- (NS_ARRAY_OF(id) *)mgl_coordinates { - NSMutableArray *coordinates = [[NSMutableArray alloc] initWithCapacity:self.pointCount]; - for (NSUInteger index = 0; index < self.pointCount; index++) { - CLLocationCoordinate2D coordinate = self.coordinates[index]; - [coordinates addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; - } - return [coordinates copy]; -} - -@end diff --git a/platform/darwin/src/MGLPolyline.mm b/platform/darwin/src/MGLPolyline.mm index 0e371a4dda..e011d09215 100644 --- a/platform/darwin/src/MGLPolyline.mm +++ b/platform/darwin/src/MGLPolyline.mm @@ -1,9 +1,9 @@ -#import "MGLPolyline.h" +#import "MGLPolyline_Private.h" #import "MGLMultiPoint_Private.h" #import "MGLGeometry_Private.h" -#import "MGLPolyline+MGLAdditions.h" +#import "MGLFeature.h" #import <mbgl/util/geojson.hpp> #import <mapbox/polylabel.hpp> @@ -49,6 +49,15 @@ @"coordinates": self.mgl_coordinates}; } +- (NS_ARRAY_OF(id) *)mgl_coordinates { + NSMutableArray *coordinates = [[NSMutableArray alloc] initWithCapacity:self.pointCount]; + for (NSUInteger index = 0; index < self.pointCount; index++) { + CLLocationCoordinate2D coordinate = self.coordinates[index]; + [coordinates addObject:@[@(coordinate.longitude), @(coordinate.latitude)]]; + } + return [coordinates copy]; +} + - (BOOL)isEqual:(id)other { return self == other || ([other isKindOfClass:[MGLPolyline class]] && [super isEqual:other]); } diff --git a/platform/darwin/src/MGLPolyline_Private.h b/platform/darwin/src/MGLPolyline_Private.h new file mode 100644 index 0000000000..405a0c5bc9 --- /dev/null +++ b/platform/darwin/src/MGLPolyline_Private.h @@ -0,0 +1,12 @@ +#import "MGLPolyline.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MGLPolyline (Private) + +- (NS_ARRAY_OF(id) *)mgl_coordinates; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 71f2785a94..f04ae2b104 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -17,7 +17,7 @@ #import "MGLLight_Private.h" #import "MGLTileSource_Private.h" #import "MGLVectorSource.h" -#import "MGLVectorSource+MGLAdditions.h" +#import "MGLVectorSource_Private.h" #import "MGLRasterSource.h" #import "MGLShapeSource.h" #import "MGLImageSource.h" diff --git a/platform/darwin/src/MGLVectorSource+MGLAdditions.h b/platform/darwin/src/MGLVectorSource+MGLAdditions.h deleted file mode 100644 index 43b0aba747..0000000000 --- a/platform/darwin/src/MGLVectorSource+MGLAdditions.h +++ /dev/null @@ -1,15 +0,0 @@ -#import <Mapbox/Mapbox.h> - -NS_ASSUME_NONNULL_BEGIN - -@interface MGLVectorSource (MGLAdditions) - -+ (NSString *)preferredMapboxStreetsLanguage; - -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage; - -@property (nonatomic, readonly, getter=isMapboxStreets) BOOL mapboxStreets; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLVectorSource+MGLAdditions.m b/platform/darwin/src/MGLVectorSource+MGLAdditions.m deleted file mode 100644 index a305388117..0000000000 --- a/platform/darwin/src/MGLVectorSource+MGLAdditions.m +++ /dev/null @@ -1,53 +0,0 @@ -#import "MGLVectorSource+MGLAdditions.h" - -@implementation MGLVectorSource (MGLAdditions) - -+ (NS_SET_OF(NSString *) *)mapboxStreetsLanguages { - // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview - static dispatch_once_t onceToken; - static NS_SET_OF(NSString *) *mapboxStreetsLanguages; - dispatch_once(&onceToken, ^{ - // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview - mapboxStreetsLanguages = [NSSet setWithObjects:@"ar", @"de", @"en", @"es", @"fr", @"pt", @"ru", @"zh", @"zh-Hans", nil]; - }); - return mapboxStreetsLanguages; -} - -+ (NSString *)preferredMapboxStreetsLanguage { - NSArray<NSString *> *supportedLanguages = [MGLVectorSource mapboxStreetsLanguages].allObjects; - NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages - forPreferences:[NSLocale preferredLanguages]]; - NSString *mostSpecificLanguage; - for (NSString *language in preferredLanguages) { - if (language.length > mostSpecificLanguage.length) { - mostSpecificLanguage = language; - } - } - return mostSpecificLanguage ?: @"en"; -} - -- (BOOL)isMapboxStreets { - NSURL *url = self.configurationURL; - if (![url.scheme isEqualToString:@"mapbox"]) { - return NO; - } - NSArray *identifiers = [url.host componentsSeparatedByString:@","]; - return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"]; -} - -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage { - if (!self.mapboxStreets) { - return @{}; - } - - // Replace {name} and {name_*} with the matching localized name tag. - NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name"; - NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"]; - for (NSString *languageCode in [MGLVectorSource mapboxStreetsLanguages]) { - NSString *key = [NSString stringWithFormat:@"name_%@", languageCode]; - localizedKeysByKey[key] = localizedKey; - } - return localizedKeysByKey; -} - -@end diff --git a/platform/darwin/src/MGLVectorSource.mm b/platform/darwin/src/MGLVectorSource.mm index b1bda56f2d..90ffe6f98b 100644 --- a/platform/darwin/src/MGLVectorSource.mm +++ b/platform/darwin/src/MGLVectorSource.mm @@ -5,6 +5,7 @@ #import "MGLTileSource_Private.h" #import "MGLStyle_Private.h" #import "MGLMapView_Private.h" + #import "NSPredicate+MGLAdditions.h" #import "NSURL+MGLAdditions.h" @@ -71,3 +72,55 @@ } @end + +@implementation MGLVectorSource (Private) + ++ (NS_SET_OF(NSString *) *)mapboxStreetsLanguages { + // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview + static dispatch_once_t onceToken; + static NS_SET_OF(NSString *) *mapboxStreetsLanguages; + dispatch_once(&onceToken, ^{ + // https://www.mapbox.com/vector-tiles/mapbox-streets-v7/#overview + mapboxStreetsLanguages = [NSSet setWithObjects:@"ar", @"de", @"en", @"es", @"fr", @"pt", @"ru", @"zh", @"zh-Hans", nil]; + }); + return mapboxStreetsLanguages; +} + ++ (NSString *)preferredMapboxStreetsLanguage { + NSArray<NSString *> *supportedLanguages = [MGLVectorSource mapboxStreetsLanguages].allObjects; + NSArray<NSString *> *preferredLanguages = [NSBundle preferredLocalizationsFromArray:supportedLanguages + forPreferences:[NSLocale preferredLanguages]]; + NSString *mostSpecificLanguage; + for (NSString *language in preferredLanguages) { + if (language.length > mostSpecificLanguage.length) { + mostSpecificLanguage = language; + } + } + return mostSpecificLanguage ?: @"en"; +} + +- (BOOL)isMapboxStreets { + NSURL *url = self.configurationURL; + if (![url.scheme isEqualToString:@"mapbox"]) { + return NO; + } + NSArray *identifiers = [url.host componentsSeparatedByString:@","]; + return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"]; +} + +- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage { + if (!self.mapboxStreets) { + return @{}; + } + + // Replace {name} and {name_*} with the matching localized name tag. + NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name"; + NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"]; + for (NSString *languageCode in [MGLVectorSource mapboxStreetsLanguages]) { + NSString *key = [NSString stringWithFormat:@"name_%@", languageCode]; + localizedKeysByKey[key] = localizedKey; + } + return localizedKeysByKey; +} + +@end diff --git a/platform/darwin/src/MGLVectorSource_Private.h b/platform/darwin/src/MGLVectorSource_Private.h index 335743173e..233809aea2 100644 --- a/platform/darwin/src/MGLVectorSource_Private.h +++ b/platform/darwin/src/MGLVectorSource_Private.h @@ -3,6 +3,13 @@ NS_ASSUME_NONNULL_BEGIN @interface MGLVectorSource (Private) + +@property (nonatomic, readonly, getter=isMapboxStreets) BOOL mapboxStreets; + ++ (NSString *)preferredMapboxStreetsLanguage; + +- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage; + @end NS_ASSUME_NONNULL_END |