Merge branch 'ios-unused'

Left in MGLTypes.h, which is now a platform-neutral (iOS + OS X) place for MGLUserTrackingMode.
This commit is contained in:
Minh Nguyễn
2015-03-26 15:12:15 -07:00
13 changed files with 0 additions and 885 deletions

View File

@@ -29,16 +29,7 @@
'../platform/ios/MGLUserLocationAnnotationView.m',
'../include/mbgl/ios/MGLMetricsLocationManager.h',
'../platform/ios/MGLMetricsLocationManager.m',
'../include/mbgl/ios/MGLStyleFunctionValue.h',
'../platform/ios/MGLStyleFunctionValue.m',
'../include/mbgl/ios/MGLTypes.h',
'../platform/ios/MGLTypes.m',
'../include/mbgl/ios/NSArray+MGLAdditions.h',
'../platform/ios/NSArray+MGLAdditions.m',
'../include/mbgl/ios/NSDictionary+MGLAdditions.h',
'../platform/ios/NSDictionary+MGLAdditions.m',
'../include/mbgl/ios/UIColor+MGLAdditions.h',
'../platform/ios/UIColor+MGLAdditions.m',
'../platform/ios/vendor/SMCalloutView/SMCalloutView.h',
'../platform/ios/vendor/SMCalloutView/SMCalloutView.m',
],

View File

@@ -1,23 +0,0 @@
#import <UIKit/UIKit.h>
@interface MGLStyleFunctionValue : NSObject
+ (instancetype)linearFunctionWithBaseZoomLevel:(CGFloat)zBase
initialValue:(CGFloat)val
slope:(CGFloat)slope
minimumValue:(CGFloat)min
maximumValue:(CGFloat)max;
+ (instancetype)exponentialFunctionWithBaseZoomLevel:(CGFloat)zBase
initialValue:(CGFloat)val
slope:(CGFloat)slope
minimumValue:(CGFloat)min
maximumValue:(CGFloat)max;
+ (instancetype)minimumZoomLevelFunction:(CGFloat)minimumZoom;
+ (instancetype)maximumZoomLevelFunction:(CGFloat)maximumZoom;
+ (instancetype)stopsFunctionWithZoomLevelsAndValues:(NSNumber *)firstZoom, ... NS_REQUIRES_NIL_TERMINATION;
@end

View File

@@ -1,21 +1,5 @@
#import <Foundation/Foundation.h>
// style property value types
//
extern NSString *const MGLStyleValueTypeBoolean;
extern NSString *const MGLStyleValueTypeNumber;
extern NSString *const MGLStyleValueTypeNumberPair;
extern NSString *const MGLStyleValueTypeColor;
extern NSString *const MGLStyleValueTypeString;
// style property function types
//
extern NSString *const MGLStyleValueTypeFunctionMinimumZoom;
extern NSString *const MGLStyleValueTypeFunctionMaximumZoom;
extern NSString *const MGLStyleValueTypeFunctionLinear;
extern NSString *const MGLStyleValueTypeFunctionExponential;
extern NSString *const MGLStyleValueTypeFunctionStops;
/// The degree to which the map view tracks the user’s location.
typedef NS_ENUM(NSUInteger, MGLUserTrackingMode)
{

View File

@@ -1,8 +1,4 @@
#import "MGLAnnotation.h"
#import "MGLMapView.h"
#import "MGLStyleFunctionValue.h"
#import "MGLTypes.h"
#import "MGLUserLocation.h"
#import "NSArray+MGLAdditions.h"
#import "NSDictionary+MGLAdditions.h"
#import "UIColor+MGLAdditions.h"

View File

@@ -1,7 +0,0 @@
#import <Foundation/Foundation.h>
@interface NSArray (MGLAdditions)
- (NSMutableArray *)deepMutableCopy;
@end

View File

@@ -1,7 +0,0 @@
#import <Foundation/Foundation.h>
@interface NSDictionary (MGLAdditions)
- (NSMutableDictionary *)deepMutableCopy;
@end

View File

@@ -1,11 +0,0 @@
#import <UIKit/UIKit.h>
@interface UIColor (MGLAdditions)
+ (UIColor *)colorWithRGBAString:(NSString *)rgbaString;
- (NSString *)rgbaStringFromColor;
+ (UIColor *)colorWithHexString:(NSString *)hexString;
- (NSString *)hexStringFromColor;
@end

View File

@@ -15,17 +15,12 @@
#include <mbgl/util/geo.hpp>
#import "MGLTypes.h"
#import "MGLStyleFunctionValue.h"
#import "MGLAnnotation.h"
#import "MGLUserLocationAnnotationView.h"
#import "MGLUserLocation_Private.h"
#import "SMCalloutView.h"
#import "UIColor+MGLAdditions.h"
#import "NSArray+MGLAdditions.h"
#import "NSDictionary+MGLAdditions.h"
#import "MGLMapboxEvents.h"
#import "MGLMetricsLocationManager.h"
@@ -52,17 +47,6 @@ NSString *const MGLDefaultStyleName = @"Emerald";
NSString *const MGLStyleVersion = @"v7";
NSString *const MGLDefaultStyleMarkerSymbolName = @"default_marker";
extern NSString *const MGLStyleKeyGeneric;
extern NSString *const MGLStyleKeyFill;
extern NSString *const MGLStyleKeyLine;
extern NSString *const MGLStyleKeyIcon;
extern NSString *const MGLStyleKeyText;
extern NSString *const MGLStyleKeyRaster;
extern NSString *const MGLStyleKeyComposite;
extern NSString *const MGLStyleKeyBackground;
extern NSString *const MGLStyleValueFunctionAllowed;
NSTimeInterval const MGLAnimationDuration = 0.3;
const CGSize MGLAnnotationUpdateViewportOutset = {150, 150};
@@ -89,7 +73,6 @@ NSString *const MGLAnnotationIDKey = @"MGLAnnotationIDKey";
@property (nonatomic) SMCalloutView *selectedAnnotationCalloutView;
@property (nonatomic) MGLUserLocationAnnotationView *userLocationAnnotationView;
@property (nonatomic) CLLocationManager *locationManager;
@property (nonatomic, readonly) NSDictionary *allowedStyleTypes;
@property (nonatomic) CGPoint centerPoint;
@property (nonatomic) CGFloat scale;
@property (nonatomic) CGFloat angle;
@@ -99,22 +82,6 @@ NSString *const MGLAnnotationIDKey = @"MGLAnnotationIDKey";
@end
@interface MGLStyleFunctionValue (MGLMapViewFriend)
@property (nonatomic) NSString *functionType;
@property (nonatomic) NSDictionary *stops;
@property (nonatomic) CGFloat zBase;
@property (nonatomic) CGFloat val;
@property (nonatomic) CGFloat slope;
@property (nonatomic) CGFloat min;
@property (nonatomic) CGFloat max;
@property (nonatomic) CGFloat minimumZoom;
@property (nonatomic) CGFloat maximumZoom;
- (id)rawStyle;
@end
@implementation MGLMapView
#pragma mark - Setup & Teardown -
@@ -1327,47 +1294,6 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
}
}
- (NSArray *)getStyleOrderedLayerNames
{
return [[self getRawStyle] valueForKeyPath:@"layers.id"];
}
- (void)setStyleOrderedLayerNames:(NSArray *)orderedLayerNames
{
NSMutableDictionary *style = [[self getRawStyle] deepMutableCopy];
NSArray *oldLayers = style[@"layers"];
NSMutableArray *newLayers = [NSMutableArray array];
if ([orderedLayerNames count] != [[oldLayers valueForKeyPath:@"id"] count])
{
[NSException raise:@"invalid layer count"
format:@"new layer count (%lu) should equal existing layer count (%lu)",
(unsigned long)[orderedLayerNames count],
(unsigned long)[[oldLayers valueForKeyPath:@"id"] count]];
}
else
{
for (NSString *newLayerName in orderedLayerNames)
{
if ( ! [[oldLayers valueForKeyPath:@"id"] containsObject:newLayerName])
{
[NSException raise:@"invalid layer name"
format:@"layer name %@ unknown",
newLayerName];
}
else
{
NSDictionary *newLayer = [oldLayers objectAtIndex:[[oldLayers valueForKeyPath:@"id"] indexOfObject:newLayerName]];
[newLayers addObject:newLayer];
}
}
}
[style setValue:newLayers forKey:@"layers"];
[self setRawStyle:style];
}
- (NSArray *)getAppliedStyleClasses
{
NSMutableArray *returnArray = [NSMutableArray array];
@@ -1400,339 +1326,6 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
mbglMap->setClasses(newAppliedClasses);
}
- (NSString *)getKeyTypeForLayer:(NSString *)layerName
{
NSDictionary *style = [self getRawStyle];
NSString *bucketType;
if ([layerName isEqualToString:@"background"])
{
bucketType = @"background";
}
else
{
for (NSDictionary *layer in style[@"structure"])
{
if ([layer[@"name"] isEqualToString:layerName])
{
bucketType = style[@"buckets"][layer[@"bucket"]][@"type"];
break;
}
}
}
NSString *keyType;
if ([bucketType isEqualToString:@"fill"])
{
keyType = MGLStyleKeyFill;
}
else if ([bucketType isEqualToString:@"line"])
{
keyType = MGLStyleKeyLine;
}
else if ([bucketType isEqualToString:@"point"])
{
keyType = MGLStyleKeyIcon;
}
else if ([bucketType isEqualToString:@"text"])
{
keyType = MGLStyleKeyText;
}
else if ([bucketType isEqualToString:@"raster"])
{
keyType = MGLStyleKeyRaster;
}
else if ([bucketType isEqualToString:@"composite"])
{
keyType = MGLStyleKeyComposite;
}
else if ([bucketType isEqualToString:@"background"])
{
keyType = MGLStyleKeyBackground;
}
else
{
[NSException raise:@"invalid bucket type"
format:@"bucket type %@ unknown",
bucketType];
}
return keyType;
}
- (NSDictionary *)getStyleDescriptionForLayer:(NSString *)layerName inClass:(NSString *)className
{
NSDictionary *style = [self getRawStyle];
if ( ! [[style valueForKeyPath:@"classes.name"] containsObject:className])
{
[NSException raise:@"invalid class name"
format:@"class name %@ unknown",
className];
}
NSUInteger classNumber = [[style valueForKeyPath:@"classes.name"] indexOfObject:className];
if ( ! [[style[@"classes"][classNumber][@"layers"] allKeys] containsObject:layerName])
{
// layer specified in structure, but not styled
//
return nil;
}
NSDictionary *layerStyle = style[@"classes"][classNumber][@"layers"][layerName];
NSMutableDictionary *styleDescription = [NSMutableDictionary dictionary];
for (NSString *keyName in [layerStyle allKeys])
{
id value = layerStyle[keyName];
while ([[style[@"constants"] allKeys] containsObject:value])
{
value = style[@"constants"][value];
}
if ([[self.allowedStyleTypes[MGLStyleKeyGeneric] allKeys] containsObject:keyName])
{
[styleDescription setValue:[self typedPropertyForKeyName:keyName
ofType:MGLStyleKeyGeneric
withValue:value]
forKey:keyName];
}
NSString *keyType = [self getKeyTypeForLayer:layerName];
if ([[self.allowedStyleTypes[keyType] allKeys] containsObject:keyName])
{
[styleDescription setValue:[self typedPropertyForKeyName:keyName
ofType:keyType
withValue:value]
forKey:keyName];
}
}
return styleDescription;
}
- (NSDictionary *)typedPropertyForKeyName:(NSString *)keyName ofType:(NSString *)keyType withValue:(id)value
{
if ( ! [[self.allowedStyleTypes[keyType] allKeys] containsObject:keyName])
{
[NSException raise:@"invalid property name"
format:@"property name %@ unknown",
keyName];
}
NSArray *typeInfo = self.allowedStyleTypes[keyType][keyName];
if ([value isKindOfClass:[NSArray class]] && ! [typeInfo containsObject:MGLStyleValueTypeColor])
{
if ([typeInfo containsObject:MGLStyleValueFunctionAllowed])
{
if ([[(NSArray *)value firstObject] isKindOfClass:[NSString class]])
{
NSString *functionType;
if ([[(NSArray *)value firstObject] isEqualToString:@"linear"])
{
functionType = MGLStyleValueTypeFunctionLinear;
}
else if ([[(NSArray *)value firstObject] isEqualToString:@"stops"])
{
functionType = MGLStyleValueTypeFunctionStops;
}
else if ([[(NSArray *)value firstObject] isEqualToString:@"exponential"])
{
functionType = MGLStyleValueTypeFunctionExponential;
}
else if ([[(NSArray *)value firstObject] isEqualToString:@"min"])
{
functionType = MGLStyleValueTypeFunctionMinimumZoom;
}
else if ([[(NSArray *)value firstObject] isEqualToString:@"max"])
{
functionType = MGLStyleValueTypeFunctionMaximumZoom;
}
if (functionType)
{
return @{ @"type" : functionType,
@"value" : value };
}
}
}
else if ([typeInfo containsObject:MGLStyleValueTypeNumberPair])
{
return @{ @"type" : MGLStyleValueTypeNumberPair,
@"value" : value };
}
}
else if ([typeInfo containsObject:MGLStyleValueTypeNumber])
{
return @{ @"type" : MGLStyleValueTypeNumber,
@"value" : value };
}
else if ([typeInfo containsObject:MGLStyleValueTypeBoolean])
{
return @{ @"type" : MGLStyleValueTypeBoolean,
@"value" : @([(NSString *)value boolValue]) };
}
else if ([typeInfo containsObject:MGLStyleValueTypeString])
{
return @{ @"type" : MGLStyleValueTypeString,
@"value" : value };
}
else if ([typeInfo containsObject:MGLStyleValueTypeColor])
{
UIColor *color;
if ([(NSString *)value hasPrefix:@"#"])
{
color = [UIColor colorWithHexString:value];
}
else if ([(NSString *)value hasPrefix:@"rgb"])
{
color = [UIColor colorWithRGBAString:value];
}
else if ([(NSString *)value hasPrefix:@"hsl"])
{
[NSException raise:@"invalid color format"
format:@"HSL color format not yet supported natively"];
}
else if ([value isKindOfClass:[NSArray class]] && [(NSArray *)value count] == 4)
{
color = [UIColor colorWithRed:[value[0] floatValue]
green:[value[1] floatValue]
blue:[value[2] floatValue]
alpha:[value[3] floatValue]];
}
else if ([[UIColor class] respondsToSelector:NSSelectorFromString([NSString stringWithFormat:@"%@Color", [(NSString *)value lowercaseString]])])
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
color = [[UIColor class] performSelector:NSSelectorFromString([NSString stringWithFormat:@"%@Color", [(NSString *)value lowercaseString]])];
#pragma clang diagnostic pop
}
return @{ @"type" : MGLStyleValueTypeColor,
@"value" : color };
}
return nil;
}
- (void)setStyleDescription:(NSDictionary *)styleDescription forLayer:(NSString *)layerName inClass:(NSString *)className
{
#pragma unused(className)
NSMutableDictionary *convertedStyle = [NSMutableDictionary dictionary];
for (NSString *key in [styleDescription allKeys])
{
NSArray *styleParameters = nil;
if ([[self.allowedStyleTypes[MGLStyleKeyGeneric] allKeys] containsObject:key])
{
styleParameters = self.allowedStyleTypes[MGLStyleKeyGeneric][key];
}
else
{
NSString *keyType = [self getKeyTypeForLayer:layerName];
if ([[self.allowedStyleTypes[keyType] allKeys] containsObject:key])
{
styleParameters = self.allowedStyleTypes[keyType][key];
}
}
if (styleParameters)
{
if ([styleDescription[key][@"value"] isKindOfClass:[MGLStyleFunctionValue class]])
{
convertedStyle[key] = [(MGLStyleFunctionValue *)styleDescription[key][@"value"] rawStyle];
}
else if ([styleParameters containsObject:styleDescription[key][@"type"]])
{
NSString *valueType = styleDescription[key][@"type"];
if ([valueType isEqualToString:MGLStyleValueTypeColor])
{
convertedStyle[key] = [@"#" stringByAppendingString:[(UIColor *)styleDescription[key][@"value"] hexStringFromColor]];
}
else
{
// the rest (bool/number/pair/string) are already JSON-convertible types
//
convertedStyle[key] = styleDescription[key][@"value"];
}
}
}
else
{
[NSException raise:@"invalid style description format"
format:@"unable to parse key '%@'",
key];
}
}
// NSMutableDictionary *style = [[self getRawStyle] deepMutableCopy];
//
// NSUInteger classIndex = [[[self getAllStyleClasses] valueForKey:@"name"] indexOfObject:className];
//
// style[@"classes"][classIndex][@"layers"][layerName] = convertedStyle;
//
// [self setRawStyle:style];
}
- (NSDictionary *)allowedStyleTypes
{
static NSDictionary *MGLStyleAllowedTypes = @{
MGLStyleKeyGeneric : @{
@"enabled" : @[ MGLStyleValueTypeBoolean, MGLStyleValueFunctionAllowed ],
@"translate" : @[ MGLStyleValueTypeNumberPair, MGLStyleValueFunctionAllowed ],
@"translate-anchor" : @[ MGLStyleValueTypeString, MGLStyleValueFunctionAllowed ],
@"opacity" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"prerender" : @[ MGLStyleValueTypeBoolean ],
@"prerender-buffer" : MGLStyleValueTypeNumber,
@"prerender-size" : @[ MGLStyleValueTypeNumber ],
@"prerender-blur" : @[ MGLStyleValueTypeNumber ] },
MGLStyleKeyFill : @{
@"color" : @[ MGLStyleValueTypeColor ],
@"stroke" : @[ MGLStyleValueTypeColor ],
@"antialias" : @[ MGLStyleValueTypeBoolean ],
@"image" : @[ MGLStyleValueTypeString ] },
MGLStyleKeyLine : @{
@"color" : @[ MGLStyleValueTypeColor ],
@"width" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"dasharray" : @[ MGLStyleValueTypeNumberPair, MGLStyleValueFunctionAllowed ] },
MGLStyleKeyIcon : @{
@"color" : @[ MGLStyleValueTypeColor ],
@"image" : @[ MGLStyleValueTypeString ],
@"size" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"radius" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed],
@"blur" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ] },
MGLStyleKeyText : @{
@"color" : @[ MGLStyleValueTypeColor ],
@"stroke" : @[ MGLStyleValueTypeColor ],
@"strokeWidth" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"strokeBlur" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"size" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"rotate" : @[ MGLStyleValueTypeNumber, MGLStyleValueFunctionAllowed ],
@"alwaysVisible" : @[ MGLStyleValueTypeBoolean ] },
MGLStyleKeyRaster : @{},
MGLStyleKeyComposite : @{},
MGLStyleKeyBackground : @{
@"color" : @[ MGLStyleValueTypeColor ] }
};
return MGLStyleAllowedTypes;
}
#pragma mark - Annotations -
- (NSArray *)annotations

View File

@@ -1,190 +0,0 @@
#import "MGLStyleFunctionValue.h"
#import "MGLTypes.h"
@interface MGLStyleFunctionValue ()
@property (nonatomic) NSString *functionType;
@property (nonatomic) NSDictionary *stops;
@property (nonatomic) CGFloat zBase;
@property (nonatomic) CGFloat val;
@property (nonatomic) CGFloat slope;
@property (nonatomic) CGFloat min;
@property (nonatomic) CGFloat max;
@property (nonatomic) CGFloat minimumZoom;
@property (nonatomic) CGFloat maximumZoom;
- (NSDictionary *)rawStyle;
@end
@implementation MGLStyleFunctionValue
- (id)initWithFunctionType:(NSString *)functionType
stops:(NSDictionary *)stops
zBase:(CGFloat)zBase
val:(CGFloat)val
slope:(CGFloat)slope
min:(CGFloat)min
max:(CGFloat)max
minimumZoom:(CGFloat)minimumZoom
maximumZoom:(CGFloat)maximumZoom
{
self = [super init];
if (self)
{
_functionType = functionType;
_stops = stops;
_zBase = zBase;
_val = val;
_slope = slope;
_min = min;
_max = max;
_minimumZoom = minimumZoom;
_maximumZoom = maximumZoom;
}
return self;
}
- (id)rawStyle
{
if ([self.functionType isEqualToString:MGLStyleValueTypeFunctionMinimumZoom])
{
return @[ @"min", @(self.minimumZoom) ];
}
else if ([self.functionType isEqualToString:MGLStyleValueTypeFunctionMaximumZoom])
{
return @[ @"max", @(self.maximumZoom) ];
}
else if ([self.functionType isEqualToString:MGLStyleValueTypeFunctionLinear])
{
return @[ @"linear", @(self.zBase), @(self.val), @(self.slope), @(self.min), @(self.max) ];
}
else if ([self.functionType isEqualToString:MGLStyleValueTypeFunctionExponential])
{
return @[ @"exponential", @(self.zBase), @(self.val), @(self.slope), @(self.min), @(self.max) ];
}
else if ([self.functionType isEqualToString:MGLStyleValueTypeFunctionStops])
{
NSMutableArray *returnArray = [NSMutableArray array];
for (NSNumber *z in [self.stops allKeys])
{
[returnArray addObject:@{ @"z" : z, @"val" : self.stops[z] }];
}
[returnArray insertObject:@"stops" atIndex:0];
return returnArray;
}
return nil;
}
+ (instancetype)stopsFunctionWithZoomLevelsAndValues:(NSNumber *)firstZoom, ...
{
NSMutableArray *numbersArray = [NSMutableArray array];
va_list args;
va_start(args, firstZoom);
for (NSNumber *arg = firstZoom; arg != nil; arg = va_arg(args, NSNumber *))
{
[numbersArray addObject:arg];
}
va_end(args);
NSAssert([numbersArray count] % 2 == 0, @"invalid number of arguments");
NSMutableDictionary *stops = [NSMutableDictionary dictionary];
for (NSUInteger i = 0; i < [numbersArray count]; i = i + 2)
{
stops[numbersArray[i]] = stops[numbersArray[i + 1]];
}
return [[self alloc] initWithFunctionType:MGLStyleValueTypeFunctionStops
stops:stops
zBase:0
val:0
slope:0
min:0
max:0
minimumZoom:0
maximumZoom:0];
}
+ (instancetype)linearFunctionWithBaseZoomLevel:(CGFloat)zBase
initialValue:(CGFloat)val
slope:(CGFloat)slope
minimumValue:(CGFloat)min
maximumValue:(CGFloat)max
{
NSAssert(zBase >= 0 && zBase <= 18, @"invalid base zoom level");
NSAssert(min < max, @"minimum value must be less than maximum value");
return [[self alloc] initWithFunctionType:MGLStyleValueTypeFunctionLinear
stops:nil
zBase:zBase
val:val
slope:slope
min:min
max:max
minimumZoom:0
maximumZoom:0];
}
+ (instancetype)exponentialFunctionWithBaseZoomLevel:(CGFloat)zBase
initialValue:(CGFloat)val
slope:(CGFloat)slope
minimumValue:(CGFloat)min
maximumValue:(CGFloat)max
{
NSAssert(zBase >= 0 && zBase <= 18, @"invalid base zoom level");
NSAssert(min < max, @"minimum value must be less than maximum value");
return [[self alloc] initWithFunctionType:MGLStyleValueTypeFunctionExponential
stops:nil
zBase:zBase
val:val
slope:slope
min:min
max:max
minimumZoom:0
maximumZoom:0];
}
+ (instancetype)minimumZoomLevelFunction:(CGFloat)minimumZoom
{
NSAssert(minimumZoom >= 0 && minimumZoom <= 18, @"invalid minimum zoom value");
return [[self alloc] initWithFunctionType:MGLStyleValueTypeFunctionMinimumZoom
stops:nil
zBase:0
val:0
slope:0
min:0
max:0
minimumZoom:minimumZoom
maximumZoom:0];
}
+ (instancetype)maximumZoomLevelFunction:(CGFloat)maximumZoom
{
NSAssert(maximumZoom >= 0 && maximumZoom <= 18, @"invalid maximum zoom value");
return [[self alloc] initWithFunctionType:MGLStyleValueTypeFunctionMaximumZoom
stops:nil
zBase:0
val:0
slope:0
min:0
max:0
minimumZoom:0
maximumZoom:maximumZoom];
}
@end

View File

@@ -1,24 +0,0 @@
#import "MGLTypes.h"
NSString *const MGLStyleKeyGeneric = @"MGLStyleKeyGeneric";
NSString *const MGLStyleKeyFill = @"MGLStyleKeyFill";
NSString *const MGLStyleKeyLine = @"MGLStyleKeyLine";
NSString *const MGLStyleKeyIcon = @"MGLStyleKeyIcon";
NSString *const MGLStyleKeyText = @"MGLStyleKeyText";
NSString *const MGLStyleKeyRaster = @"MGLStyleKeyRaster";
NSString *const MGLStyleKeyComposite = @"MGLStyleKeyComposite";
NSString *const MGLStyleKeyBackground = @"MGLStyleKeyBackground";
NSString *const MGLStyleValueTypeBoolean = @"MGLStyleValueTypeBoolean";
NSString *const MGLStyleValueTypeNumber = @"MGLStyleValueTypeNumber";
NSString *const MGLStyleValueTypeNumberPair = @"MGLStyleValueTypeNumberPair";
NSString *const MGLStyleValueTypeColor = @"MGLStyleValueTypeColor";
NSString *const MGLStyleValueTypeString = @"MGLStyleValueTypeString";
NSString *const MGLStyleValueFunctionAllowed = @"MGLStyleValueFunctionAllowed";
NSString *const MGLStyleValueTypeFunctionMinimumZoom = @"MGLStyleValueTypeFunctionMinimumZoom";
NSString *const MGLStyleValueTypeFunctionMaximumZoom = @"MGLStyleValueTypeFunctionMaximumZoom";
NSString *const MGLStyleValueTypeFunctionLinear = @"MGLStyleValueTypeFunctionLinear";
NSString *const MGLStyleValueTypeFunctionExponential = @"MGLStyleValueTypeFunctionExponential";
NSString *const MGLStyleValueTypeFunctionStops = @"MGLStyleValueTypeFunctionStops";

View File

@@ -1,10 +0,0 @@
#import "NSArray+MGLAdditions.h"
@implementation NSArray (MGLAdditions)
- (NSMutableArray *)deepMutableCopy
{
return (NSMutableArray *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFArrayRef)self, kCFPropertyListMutableContainersAndLeaves));
}
@end

View File

@@ -1,10 +0,0 @@
#import "NSDictionary+MGLAdditions.h"
@implementation NSDictionary (MGLAdditions)
- (NSMutableDictionary *)deepMutableCopy
{
return (NSMutableDictionary *)CFBridgingRelease(CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFDictionaryRef)self, kCFPropertyListMutableContainersAndLeaves));
}
@end

View File

@@ -1,167 +0,0 @@
#import "UIColor+MGLAdditions.h"
/* Portions based on Erica Sadun's uicolor-utilities
https://github.com/erica/uicolor-utilities */
@interface UIColor (MGLAdditionsPrivate)
+ (UIColor *)colorWithRGBHex:(UInt32)hex;
- (CGColorSpaceModel)colorSpaceModel;
- (BOOL)canProvideRGBComponents;
- (BOOL)red:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha;
- (UInt32)rgbHex;
@end
@implementation UIColor (MGLAdditions)
+ (UIColor *)colorWithRGBAString:(NSString *)rgbaString
{
UIColor *color;
NSString *numberString = [rgbaString stringByReplacingOccurrencesOfString:@"rgba("
withString:@""];
numberString = [numberString stringByReplacingOccurrencesOfString:@"rgb("
withString:@""];
numberString = [numberString stringByReplacingOccurrencesOfString:@")"
withString:@""];
NSArray *numbers = [numberString componentsSeparatedByString:@","];
if ([rgbaString hasPrefix:@"rgb("] && [numbers count] == 3)
{
color = [UIColor colorWithRed:[numbers[0] floatValue] / 255
green:[numbers[1] floatValue] / 255
blue:[numbers[2] floatValue] / 255
alpha:1.0];
}
else if ([rgbaString hasPrefix:@"rgba("] && [numbers count] == 4)
{
color = [UIColor colorWithRed:[numbers[0] floatValue] / 255
green:[numbers[1] floatValue] / 255
blue:[numbers[2] floatValue] / 255
alpha:[numbers[3] floatValue]];
}
return color;
}
- (NSString *)rgbaStringFromColor
{
CGFloat r,g,b,a;
[self getRed:&r green:&g blue:&b alpha:&a];
r *= 255;
g *= 255;
b *= 255;
a *= 255;
return [NSString stringWithFormat:@"rgba(%lu,%lu,%lu,%lu)", (unsigned long)r, (unsigned long)g, (unsigned long)b, (unsigned long)a];
}
+ (UIColor *)colorWithRGBHex:(UInt32)hex
{
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:1.0f];
}
- (CGColorSpaceModel)colorSpaceModel
{
return CGColorSpaceGetModel(CGColorGetColorSpace(self.CGColor));
}
- (BOOL)canProvideRGBComponents
{
switch (self.colorSpaceModel)
{
case kCGColorSpaceModelRGB:
case kCGColorSpaceModelMonochrome:
{
return YES;
}
default:
{
return NO;
}
}
}
- (BOOL)red:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha
{
const CGFloat *components = CGColorGetComponents(self.CGColor);
CGFloat r,g,b,a;
switch (self.colorSpaceModel)
{
case kCGColorSpaceModelMonochrome:
{
r = g = b = components[0];
a = components[1];
break;
}
case kCGColorSpaceModelRGB:
{
r = components[0];
g = components[1];
b = components[2];
a = components[3];
break;
}
default:
{
return NO;
}
}
if (red) *red = r;
if (green) *green = g;
if (blue) *blue = b;
if (alpha) *alpha = a;
return YES;
}
- (UInt32)rgbHex
{
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use rgbHex");
CGFloat r, g, b, a;
if ( ! [self red:&r green:&g blue:&b alpha:&a])
return 0;
r = fminf(fmaxf(r, 0.0f), 1.0f);
g = fminf(fmaxf(g, 0.0f), 1.0f);
b = fminf(fmaxf(b, 0.0f), 1.0f);
return (((int)roundf(r * 255)) << 16) | (((int)roundf(g * 255)) << 8) | (((int)roundf(b * 255)));
}
- (NSString *)hexStringFromColor
{
return [NSString stringWithFormat:@"%0.6X", (unsigned int)(self.rgbHex)];
}
+ (UIColor *)colorWithHexString:(NSString *)hexString
{
NSScanner *scanner = [NSScanner scannerWithString:[hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]];
unsigned hexNum;
if ( ! [scanner scanHexInt:&hexNum])
return nil;
return [UIColor colorWithRGBHex:hexNum];
}
@end