diff options
Diffstat (limited to 'platform/darwin/src')
38 files changed, 3304 insertions, 3988 deletions
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h index 659903914c..9d2673c859 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -38,45 +37,28 @@ which it is added. #pragma mark - Accessing the Paint Attributes -#if TARGET_OS_IPHONE /** The color with which the background will be drawn. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `backgroundPattern` is set to `nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *backgroundColor; -#else -/** - The color with which the background will be drawn. + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `backgroundPattern` is set to - `nil`. Otherwise, it is ignored. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *backgroundColor; -#endif +@property (nonatomic, null_resettable) NSExpression *backgroundColor; /** The transition affecting any changes to this layer’s `backgroundColor` property. @@ -88,18 +70,21 @@ which it is added. /** The opacity at which the background will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *backgroundOpacity; +@property (nonatomic, null_resettable) NSExpression *backgroundOpacity; /** The transition affecting any changes to this layer’s `backgroundOpacity` property. @@ -113,13 +98,19 @@ which it is added. seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *backgroundPattern; +@property (nonatomic, null_resettable) NSExpression *backgroundPattern; /** The transition affecting any changes to this layer’s `backgroundPattern` property. diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 47b491fc65..7c4cf79709 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -32,21 +32,21 @@ #pragma mark - Accessing the Paint Attributes -- (void)setBackgroundColor:(MGLStyleValue<MGLColor *> *)backgroundColor { +- (void)setBackgroundColor:(NSExpression *)backgroundColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(backgroundColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(backgroundColor); self.rawLayer->setBackgroundColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)backgroundColor { +- (NSExpression *)backgroundColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getBackgroundColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultBackgroundColor()); + propertyValue = self.rawLayer->getDefaultBackgroundColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setBackgroundColorTransition:(MGLTransition )transition { @@ -67,21 +67,21 @@ return transition; } -- (void)setBackgroundOpacity:(MGLStyleValue<NSNumber *> *)backgroundOpacity { +- (void)setBackgroundOpacity:(NSExpression *)backgroundOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(backgroundOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(backgroundOpacity); self.rawLayer->setBackgroundOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)backgroundOpacity { +- (NSExpression *)backgroundOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getBackgroundOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultBackgroundOpacity()); + propertyValue = self.rawLayer->getDefaultBackgroundOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setBackgroundOpacityTransition:(MGLTransition )transition { @@ -102,21 +102,21 @@ return transition; } -- (void)setBackgroundPattern:(MGLStyleValue<NSString *> *)backgroundPattern { +- (void)setBackgroundPattern:(NSExpression *)backgroundPattern { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(backgroundPattern); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(backgroundPattern); self.rawLayer->setBackgroundPattern(mbglValue); } -- (MGLStyleValue<NSString *> *)backgroundPattern { +- (NSExpression *)backgroundPattern { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getBackgroundPattern(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(self.rawLayer->getDefaultBackgroundPattern()); + propertyValue = self.rawLayer->getDefaultBackgroundPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setBackgroundPatternTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index 86143894b1..caa6d2f6cb 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -83,12 +82,11 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslationAnchor) { ```swift let layer = MGLCircleStyleLayer(identifier: "circles", source: population) layer.sourceLayerIdentifier = "population" - layer.circleColor = MGLStyleValue(rawValue: .green) - layer.circleRadius = MGLStyleValue(interpolationMode: .exponential, - cameraStops: [12: MGLStyleValue(rawValue: 2), - 22: MGLStyleValue(rawValue: 180)], - options: [.interpolationBase: 1.75]) - layer.circleOpacity = MGLStyleValue(rawValue: 0.7) + layer.circleColor = NSExpression(forConstantValue: UIColor.green) + layer.circleRadius = NSExpression(format: "FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'exponential', 1.75, %@)", + [12: 2, + 22: 180]) + layer.circleOpacity = NSExpression(forConstantValue: 0.7) layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married") mapView.style?.addLayer(layer) ``` @@ -117,27 +115,19 @@ MGL_EXPORT Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleBlur; +@property (nonatomic, null_resettable) NSExpression *circleBlur; /** The transition affecting any changes to this layer’s `circleBlur` property. @@ -146,57 +136,23 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition circleBlurTransition; -#if TARGET_OS_IPHONE /** The fill color of the circle. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *circleColor; -#else -/** - The fill color of the circle. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *circleColor; -#endif +@property (nonatomic, null_resettable) NSExpression *circleColor; /** The transition affecting any changes to this layer’s `circleColor` property. @@ -208,27 +164,19 @@ MGL_EXPORT /** The opacity at which the circle will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleOpacity; +@property (nonatomic, null_resettable) NSExpression *circleOpacity; /** The transition affecting any changes to this layer’s `circleOpacity` property. @@ -240,44 +188,44 @@ MGL_EXPORT /** Orientation of circle when map is pitched. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLCirclePitchAlignmentViewport`. Set this - property to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to + `viewport`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLCirclePitchAlignment` values + * Any of the following constant string values: + * `map`: The circle is aligned to the plane of the map. + * `viewport`: The circle is aligned to the plane of the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circlePitchAlignment; +@property (nonatomic, null_resettable) NSExpression *circlePitchAlignment; /** Circle radius. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `5`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `5`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleRadius; +@property (nonatomic, null_resettable) NSExpression *circleRadius; /** The transition affecting any changes to this layer’s `circleRadius` property. @@ -289,75 +237,50 @@ MGL_EXPORT /** Controls the scaling behavior of the circle when the map is pitched. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLCircleScaleAlignmentMap`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-circle-pitch-scale"><code>circle-pitch-scale</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + You can set this property to an expression containing any of the following: + + * Constant `MGLCircleScaleAlignment` values + * Any of the following constant string values: + * `map`: Circles are scaled according to their apparent distance to the + camera. + * `viewport`: Circles are not scaled. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleScaleAlignment; +@property (nonatomic, null_resettable) NSExpression *circleScaleAlignment; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circlePitchScale __attribute__((unavailable("Use circleScaleAlignment instead."))); +@property (nonatomic, null_resettable) NSExpression *circlePitchScale __attribute__((unavailable("Use circleScaleAlignment instead."))); -#if TARGET_OS_IPHONE /** The stroke color of the circle. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *circleStrokeColor; -#else -/** - The stroke color of the circle. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *circleStrokeColor; -#endif +@property (nonatomic, null_resettable) NSExpression *circleStrokeColor; /** The transition affecting any changes to this layer’s `circleStrokeColor` property. @@ -369,27 +292,19 @@ MGL_EXPORT /** The opacity of the circle's stroke. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleStrokeOpacity; +@property (nonatomic, null_resettable) NSExpression *circleStrokeOpacity; /** The transition affecting any changes to this layer’s `circleStrokeOpacity` property. @@ -404,27 +319,19 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleStrokeWidth; +@property (nonatomic, null_resettable) NSExpression *circleStrokeWidth; /** The transition affecting any changes to this layer’s `circleStrokeWidth` property. @@ -439,7 +346,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -447,21 +354,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-circle-translate"><code>circle-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslation; +@property (nonatomic, null_resettable) NSExpression *circleTranslation; #else /** The geometry's offset. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -469,14 +380,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-circle-translate"><code>circle-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslation; +@property (nonatomic, null_resettable) NSExpression *circleTranslation; #endif /** @@ -486,14 +401,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition circleTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslate __attribute__((unavailable("Use circleTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *circleTranslate __attribute__((unavailable("Use circleTranslation instead."))); /** Controls the frame of reference for `circleTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLCircleTranslationAnchorMap`. Set this property - to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `circleTranslation` is non-`nil`. Otherwise, it is ignored. @@ -502,15 +416,24 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-circle-translate-anchor"><code>circle-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLCircleTranslationAnchor` values + * Any of the following constant string values: + * `map`: The circle is translated relative to the map. + * `viewport`: The circle is translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *circleTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslateAnchor __attribute__((unavailable("Use circleTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *circleTranslateAnchor __attribute__((unavailable("Use circleTranslationAnchor instead."))); @end diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 71ae37035e..0be3920987 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -87,21 +87,21 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setCircleBlur:(MGLStyleValue<NSNumber *> *)circleBlur { +- (void)setCircleBlur:(NSExpression *)circleBlur { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(circleBlur); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(circleBlur); self.rawLayer->setCircleBlur(mbglValue); } -- (MGLStyleValue<NSNumber *> *)circleBlur { +- (NSExpression *)circleBlur { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleBlur(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleBlur()); + propertyValue = self.rawLayer->getDefaultCircleBlur(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setCircleBlurTransition:(MGLTransition )transition { @@ -122,21 +122,21 @@ namespace mbgl { return transition; } -- (void)setCircleColor:(MGLStyleValue<MGLColor *> *)circleColor { +- (void)setCircleColor:(NSExpression *)circleColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(circleColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(circleColor); self.rawLayer->setCircleColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)circleColor { +- (NSExpression *)circleColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleColor()); + propertyValue = self.rawLayer->getDefaultCircleColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setCircleColorTransition:(MGLTransition )transition { @@ -157,21 +157,21 @@ namespace mbgl { return transition; } -- (void)setCircleOpacity:(MGLStyleValue<NSNumber *> *)circleOpacity { +- (void)setCircleOpacity:(NSExpression *)circleOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(circleOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(circleOpacity); self.rawLayer->setCircleOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)circleOpacity { +- (NSExpression *)circleOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleOpacity()); + propertyValue = self.rawLayer->getDefaultCircleOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setCircleOpacityTransition:(MGLTransition )transition { @@ -192,38 +192,38 @@ namespace mbgl { return transition; } -- (void)setCirclePitchAlignment:(MGLStyleValue<NSValue *> *)circlePitchAlignment { +- (void)setCirclePitchAlignment:(NSExpression *)circlePitchAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLCirclePitchAlignment>().toEnumPropertyValue(circlePitchAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLCirclePitchAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::AlignmentType>>(circlePitchAlignment); self.rawLayer->setCirclePitchAlignment(mbglValue); } -- (MGLStyleValue<NSValue *> *)circlePitchAlignment { +- (NSExpression *)circlePitchAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCirclePitchAlignment(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLCirclePitchAlignment>().toEnumStyleValue(self.rawLayer->getDefaultCirclePitchAlignment()); + propertyValue = self.rawLayer->getDefaultCirclePitchAlignment(); } - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLCirclePitchAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLCirclePitchAlignment>().toExpression(propertyValue); } -- (void)setCircleRadius:(MGLStyleValue<NSNumber *> *)circleRadius { +- (void)setCircleRadius:(NSExpression *)circleRadius { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(circleRadius); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(circleRadius); self.rawLayer->setCircleRadius(mbglValue); } -- (MGLStyleValue<NSNumber *> *)circleRadius { +- (NSExpression *)circleRadius { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleRadius(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleRadius()); + propertyValue = self.rawLayer->getDefaultCircleRadius(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setCircleRadiusTransition:(MGLTransition )transition { @@ -244,45 +244,45 @@ namespace mbgl { return transition; } -- (void)setCircleScaleAlignment:(MGLStyleValue<NSValue *> *)circleScaleAlignment { +- (void)setCircleScaleAlignment:(NSExpression *)circleScaleAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCircleScaleAlignment>().toEnumPropertyValue(circleScaleAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCircleScaleAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::CirclePitchScaleType>>(circleScaleAlignment); self.rawLayer->setCirclePitchScale(mbglValue); } -- (MGLStyleValue<NSValue *> *)circleScaleAlignment { +- (NSExpression *)circleScaleAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCirclePitchScale(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCircleScaleAlignment>().toEnumStyleValue(self.rawLayer->getDefaultCirclePitchScale()); + propertyValue = self.rawLayer->getDefaultCirclePitchScale(); } - return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCircleScaleAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCircleScaleAlignment>().toExpression(propertyValue); } -- (void)setCirclePitchScale:(MGLStyleValue<NSValue *> *)circlePitchScale { +- (void)setCirclePitchScale:(NSExpression *)circlePitchScale { } -- (MGLStyleValue<NSValue *> *)circlePitchScale { +- (NSExpression *)circlePitchScale { return self.circleScaleAlignment; } -- (void)setCircleStrokeColor:(MGLStyleValue<MGLColor *> *)circleStrokeColor { +- (void)setCircleStrokeColor:(NSExpression *)circleStrokeColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(circleStrokeColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(circleStrokeColor); self.rawLayer->setCircleStrokeColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)circleStrokeColor { +- (NSExpression *)circleStrokeColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleStrokeColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleStrokeColor()); + propertyValue = self.rawLayer->getDefaultCircleStrokeColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setCircleStrokeColorTransition:(MGLTransition )transition { @@ -303,21 +303,21 @@ namespace mbgl { return transition; } -- (void)setCircleStrokeOpacity:(MGLStyleValue<NSNumber *> *)circleStrokeOpacity { +- (void)setCircleStrokeOpacity:(NSExpression *)circleStrokeOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(circleStrokeOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(circleStrokeOpacity); self.rawLayer->setCircleStrokeOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)circleStrokeOpacity { +- (NSExpression *)circleStrokeOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleStrokeOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleStrokeOpacity()); + propertyValue = self.rawLayer->getDefaultCircleStrokeOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setCircleStrokeOpacityTransition:(MGLTransition )transition { @@ -338,21 +338,21 @@ namespace mbgl { return transition; } -- (void)setCircleStrokeWidth:(MGLStyleValue<NSNumber *> *)circleStrokeWidth { +- (void)setCircleStrokeWidth:(NSExpression *)circleStrokeWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(circleStrokeWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(circleStrokeWidth); self.rawLayer->setCircleStrokeWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)circleStrokeWidth { +- (NSExpression *)circleStrokeWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleStrokeWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultCircleStrokeWidth()); + propertyValue = self.rawLayer->getDefaultCircleStrokeWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setCircleStrokeWidthTransition:(MGLTransition )transition { @@ -373,21 +373,21 @@ namespace mbgl { return transition; } -- (void)setCircleTranslation:(MGLStyleValue<NSValue *> *)circleTranslation { +- (void)setCircleTranslation:(NSExpression *)circleTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(circleTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(circleTranslation); self.rawLayer->setCircleTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)circleTranslation { +- (NSExpression *)circleTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultCircleTranslate()); + propertyValue = self.rawLayer->getDefaultCircleTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setCircleTranslationTransition:(MGLTransition )transition { @@ -408,34 +408,34 @@ namespace mbgl { return transition; } -- (void)setCircleTranslate:(MGLStyleValue<NSValue *> *)circleTranslate { +- (void)setCircleTranslate:(NSExpression *)circleTranslate { } -- (MGLStyleValue<NSValue *> *)circleTranslate { +- (NSExpression *)circleTranslate { return self.circleTranslation; } -- (void)setCircleTranslationAnchor:(MGLStyleValue<NSValue *> *)circleTranslationAnchor { +- (void)setCircleTranslationAnchor:(NSExpression *)circleTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslationAnchor>().toEnumPropertyValue(circleTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(circleTranslationAnchor); self.rawLayer->setCircleTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)circleTranslationAnchor { +- (NSExpression *)circleTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getCircleTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultCircleTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultCircleTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslationAnchor>().toExpression(propertyValue); } -- (void)setCircleTranslateAnchor:(MGLStyleValue<NSValue *> *)circleTranslateAnchor { +- (void)setCircleTranslateAnchor:(NSExpression *)circleTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)circleTranslateAnchor { +- (NSExpression *)circleTranslateAnchor { return self.circleTranslationAnchor; } diff --git a/platform/darwin/src/MGLConversion.h b/platform/darwin/src/MGLConversion.h index 0d18d4e716..92a6720e6a 100644 --- a/platform/darwin/src/MGLConversion.h +++ b/platform/darwin/src/MGLConversion.h @@ -62,10 +62,14 @@ public: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" template <class Fn> - static optional<Error> eachMember(const Holder&, Fn&&) { + static optional<Error> eachMember(const Holder& holder, Fn&& visit) { #pragma clang diagnostic pop - // Not implemented (unneeded for MGLStyleFunction conversion). - NSCAssert(NO, @"eachMember not implemented"); + [holder.value enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + auto result = visit(std::string(static_cast<const char *>([key UTF8String])), obj); + if (result) { + *stop = YES; + } + }]; return {}; } diff --git a/platform/darwin/src/MGLFeature.mm b/platform/darwin/src/MGLFeature.mm index 033052bda8..ee2c71be21 100644 --- a/platform/darwin/src/MGLFeature.mm +++ b/platform/darwin/src/MGLFeature.mm @@ -12,7 +12,7 @@ #import "NSDictionary+MGLAdditions.h" #import "NSArray+MGLAdditions.h" -#import "NSExpression+MGLAdditions.h" +#import "NSExpression+MGLPrivateAdditions.h" #import <mbgl/util/geometry.hpp> #import <mbgl/style/conversion/geojson.hpp> diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.h b/platform/darwin/src/MGLFillExtrusionStyleLayer.h index 02d6b2ff88..d1d5af6ba2 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.h +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -45,8 +44,8 @@ typedef NS_ENUM(NSUInteger, MGLFillExtrusionTranslationAnchor) { ```swift let layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: buildings) layer.sourceLayerIdentifier = "building" - layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil) - layer.fillExtrusionBase = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "min_height", options: nil) + layer.fillExtrusionHeight = NSExpression(forKeyPath: "height") + layer.fillExtrusionBase = NSExpression(forKeyPath: "min_height") layer.predicate = NSPredicate(format: "extrude == 'true'") mapView.style?.addLayer(layer) ``` @@ -77,30 +76,22 @@ MGL_EXPORT This property is measured in meters. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillExtrusionHeight` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillExtrusionBase; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionBase; /** The transition affecting any changes to this layer’s `fillExtrusionBase` property. @@ -109,69 +100,29 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition fillExtrusionBaseTransition; -#if TARGET_OS_IPHONE /** The base color of this layer. The extrusion's surfaces will be shaded differently based on this color in combination with the `light` settings. If this color is specified with an alpha component, the alpha component will be ignored; use `fillExtrusionOpacity` to set layer opacityco. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillExtrusionPattern` is set to `nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *fillExtrusionColor; -#else -/** - The base color of this layer. The extrusion's surfaces will be shaded - differently based on this color in combination with the `light` settings. If - this color is specified with an alpha component, the alpha component will be - ignored; use `fillExtrusionOpacity` to set layer opacityco. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `fillExtrusionPattern` is set to - `nil`. Otherwise, it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *fillExtrusionColor; -#endif +@property (nonatomic, null_resettable) NSExpression *fillExtrusionColor; /** The transition affecting any changes to this layer’s `fillExtrusionColor` property. @@ -185,27 +136,19 @@ MGL_EXPORT This property is measured in meters. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillExtrusionHeight; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionHeight; /** The transition affecting any changes to this layer’s `fillExtrusionHeight` property. @@ -218,18 +161,21 @@ MGL_EXPORT The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillExtrusionOpacity; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionOpacity; /** The transition affecting any changes to this layer’s `fillExtrusionOpacity` property. @@ -243,13 +189,19 @@ MGL_EXPORT seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *fillExtrusionPattern; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionPattern; /** The transition affecting any changes to this layer’s `fillExtrusionPattern` property. @@ -264,7 +216,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -272,21 +224,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-extrusion-translate"><code>fill-extrusion-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillExtrusionTranslation; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionTranslation; #else /** The geometry's offset. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -294,14 +250,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-extrusion-translate"><code>fill-extrusion-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillExtrusionTranslation; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionTranslation; #endif /** @@ -311,14 +271,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition fillExtrusionTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillExtrusionTranslate __attribute__((unavailable("Use fillExtrusionTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *fillExtrusionTranslate __attribute__((unavailable("Use fillExtrusionTranslation instead."))); /** Controls the frame of reference for `fillExtrusionTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLFillExtrusionTranslationAnchorMap`. Set this - property to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillExtrusionTranslation` is non-`nil`. Otherwise, it is ignored. @@ -327,15 +286,24 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-extrusion-translate-anchor"><code>fill-extrusion-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLFillExtrusionTranslationAnchor` values + * Any of the following constant string values: + * `map`: The fill extrusion is translated relative to the map. + * `viewport`: The fill extrusion is translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillExtrusionTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *fillExtrusionTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillExtrusionTranslateAnchor __attribute__((unavailable("Use fillExtrusionTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *fillExtrusionTranslateAnchor __attribute__((unavailable("Use fillExtrusionTranslationAnchor instead."))); @end diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm index b00ed8e09f..1baa264689 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm @@ -77,21 +77,21 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setFillExtrusionBase:(MGLStyleValue<NSNumber *> *)fillExtrusionBase { +- (void)setFillExtrusionBase:(NSExpression *)fillExtrusionBase { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(fillExtrusionBase); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(fillExtrusionBase); self.rawLayer->setFillExtrusionBase(mbglValue); } -- (MGLStyleValue<NSNumber *> *)fillExtrusionBase { +- (NSExpression *)fillExtrusionBase { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionBase(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillExtrusionBase()); + propertyValue = self.rawLayer->getDefaultFillExtrusionBase(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setFillExtrusionBaseTransition:(MGLTransition )transition { @@ -112,21 +112,21 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionColor:(MGLStyleValue<MGLColor *> *)fillExtrusionColor { +- (void)setFillExtrusionColor:(NSExpression *)fillExtrusionColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(fillExtrusionColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(fillExtrusionColor); self.rawLayer->setFillExtrusionColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)fillExtrusionColor { +- (NSExpression *)fillExtrusionColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillExtrusionColor()); + propertyValue = self.rawLayer->getDefaultFillExtrusionColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setFillExtrusionColorTransition:(MGLTransition )transition { @@ -147,21 +147,21 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionHeight:(MGLStyleValue<NSNumber *> *)fillExtrusionHeight { +- (void)setFillExtrusionHeight:(NSExpression *)fillExtrusionHeight { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(fillExtrusionHeight); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(fillExtrusionHeight); self.rawLayer->setFillExtrusionHeight(mbglValue); } -- (MGLStyleValue<NSNumber *> *)fillExtrusionHeight { +- (NSExpression *)fillExtrusionHeight { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionHeight(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillExtrusionHeight()); + propertyValue = self.rawLayer->getDefaultFillExtrusionHeight(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setFillExtrusionHeightTransition:(MGLTransition )transition { @@ -182,21 +182,21 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionOpacity:(MGLStyleValue<NSNumber *> *)fillExtrusionOpacity { +- (void)setFillExtrusionOpacity:(NSExpression *)fillExtrusionOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(fillExtrusionOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(fillExtrusionOpacity); self.rawLayer->setFillExtrusionOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)fillExtrusionOpacity { +- (NSExpression *)fillExtrusionOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultFillExtrusionOpacity()); + propertyValue = self.rawLayer->getDefaultFillExtrusionOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setFillExtrusionOpacityTransition:(MGLTransition )transition { @@ -217,21 +217,21 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionPattern:(MGLStyleValue<NSString *> *)fillExtrusionPattern { +- (void)setFillExtrusionPattern:(NSExpression *)fillExtrusionPattern { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(fillExtrusionPattern); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(fillExtrusionPattern); self.rawLayer->setFillExtrusionPattern(mbglValue); } -- (MGLStyleValue<NSString *> *)fillExtrusionPattern { +- (NSExpression *)fillExtrusionPattern { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionPattern(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(self.rawLayer->getDefaultFillExtrusionPattern()); + propertyValue = self.rawLayer->getDefaultFillExtrusionPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setFillExtrusionPatternTransition:(MGLTransition )transition { @@ -252,21 +252,21 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionTranslation:(MGLStyleValue<NSValue *> *)fillExtrusionTranslation { +- (void)setFillExtrusionTranslation:(NSExpression *)fillExtrusionTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(fillExtrusionTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(fillExtrusionTranslation); self.rawLayer->setFillExtrusionTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)fillExtrusionTranslation { +- (NSExpression *)fillExtrusionTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultFillExtrusionTranslate()); + propertyValue = self.rawLayer->getDefaultFillExtrusionTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setFillExtrusionTranslationTransition:(MGLTransition )transition { @@ -287,34 +287,34 @@ namespace mbgl { return transition; } -- (void)setFillExtrusionTranslate:(MGLStyleValue<NSValue *> *)fillExtrusionTranslate { +- (void)setFillExtrusionTranslate:(NSExpression *)fillExtrusionTranslate { } -- (MGLStyleValue<NSValue *> *)fillExtrusionTranslate { +- (NSExpression *)fillExtrusionTranslate { return self.fillExtrusionTranslation; } -- (void)setFillExtrusionTranslationAnchor:(MGLStyleValue<NSValue *> *)fillExtrusionTranslationAnchor { +- (void)setFillExtrusionTranslationAnchor:(NSExpression *)fillExtrusionTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillExtrusionTranslationAnchor>().toEnumPropertyValue(fillExtrusionTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillExtrusionTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(fillExtrusionTranslationAnchor); self.rawLayer->setFillExtrusionTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)fillExtrusionTranslationAnchor { +- (NSExpression *)fillExtrusionTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillExtrusionTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillExtrusionTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultFillExtrusionTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultFillExtrusionTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillExtrusionTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillExtrusionTranslationAnchor>().toExpression(propertyValue); } -- (void)setFillExtrusionTranslateAnchor:(MGLStyleValue<NSValue *> *)fillExtrusionTranslateAnchor { +- (void)setFillExtrusionTranslateAnchor:(NSExpression *)fillExtrusionTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)fillExtrusionTranslateAnchor { +- (NSExpression *)fillExtrusionTranslateAnchor { return self.fillExtrusionTranslationAnchor; } diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h index e385256aae..5caab91b45 100644 --- a/platform/darwin/src/MGLFillStyleLayer.h +++ b/platform/darwin/src/MGLFillStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -44,7 +43,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslationAnchor) { ```swift let layer = MGLFillStyleLayer(identifier: "parks", source: parks) layer.sourceLayerIdentifier = "parks" - layer.fillColor = MGLStyleValue(rawValue: .green) + layer.fillColor = NSExpression(forConstantValue: UIColor.green) layer.predicate = NSPredicate(format: "type == %@", "national-park") mapView.style?.addLayer(layer) ``` @@ -72,81 +71,49 @@ MGL_EXPORT /** Whether or not the fill should be antialiased. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `YES`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `YES`. + Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-antialias"><code>fill-antialias</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable, getter=isFillAntialiased) MGLStyleValue<NSNumber *> *fillAntialiased; +@property (nonatomic, null_resettable, getter=isFillAntialiased) NSExpression *fillAntialiased; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillAntialias __attribute__((unavailable("Use fillAntialiased instead."))); +@property (nonatomic, null_resettable) NSExpression *fillAntialias __attribute__((unavailable("Use fillAntialiased instead."))); -#if TARGET_OS_IPHONE /** The color of the filled part of this layer. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillPattern` is set to `nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *fillColor; -#else -/** - The color of the filled part of this layer. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `fillPattern` is set to `nil`. - Otherwise, it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *fillColor; -#endif +@property (nonatomic, null_resettable) NSExpression *fillColor; /** The transition affecting any changes to this layer’s `fillColor` property. @@ -159,27 +126,19 @@ MGL_EXPORT The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1pt stroke around the fill, if the stroke is used. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillOpacity; +@property (nonatomic, null_resettable) NSExpression *fillOpacity; /** The transition affecting any changes to this layer’s `fillOpacity` property. @@ -188,57 +147,23 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition fillOpacityTransition; -#if TARGET_OS_IPHONE /** The outline color of the fill. Matches the value of `fillColor` if unspecified. This property is only applied to the style if `fillPattern` is set to `nil`, - and `fillAntialiased` is set to an `MGLStyleValue` object containing an - `NSNumber` object containing `YES`. Otherwise, it is ignored. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *fillOutlineColor; -#else -/** - The outline color of the fill. Matches the value of `fillColor` if unspecified. + and `fillAntialiased` is set to an expression that evaluates to `YES`. + Otherwise, it is ignored. - This property is only applied to the style if `fillPattern` is set to `nil`, - and `fillAntialiased` is set to an `MGLStyleValue` object containing an - `NSNumber` object containing `YES`. Otherwise, it is ignored. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + You can set this property to an expression containing any of the following: + + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *fillOutlineColor; -#endif +@property (nonatomic, null_resettable) NSExpression *fillOutlineColor; /** The transition affecting any changes to this layer’s `fillOutlineColor` property. @@ -251,13 +176,19 @@ MGL_EXPORT Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *fillPattern; +@property (nonatomic, null_resettable) NSExpression *fillPattern; /** The transition affecting any changes to this layer’s `fillPattern` property. @@ -272,7 +203,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -280,21 +211,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-translate"><code>fill-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslation; +@property (nonatomic, null_resettable) NSExpression *fillTranslation; #else /** The geometry's offset. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -302,14 +237,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-translate"><code>fill-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslation; +@property (nonatomic, null_resettable) NSExpression *fillTranslation; #endif /** @@ -319,14 +258,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition fillTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslate __attribute__((unavailable("Use fillTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *fillTranslate __attribute__((unavailable("Use fillTranslation instead."))); /** Controls the frame of reference for `fillTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLFillTranslationAnchorMap`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillTranslation` is non-`nil`. Otherwise, it is ignored. @@ -335,15 +273,24 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-fill-translate-anchor"><code>fill-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLFillTranslationAnchor` values + * Any of the following constant string values: + * `map`: The fill is translated relative to the map. + * `viewport`: The fill is translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *fillTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslateAnchor __attribute__((unavailable("Use fillTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *fillTranslateAnchor __attribute__((unavailable("Use fillTranslationAnchor instead."))); @end diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 71b01a6661..ab28b414b5 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -77,45 +77,45 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setFillAntialiased:(MGLStyleValue<NSNumber *> *)fillAntialiased { +- (void)setFillAntialiased:(NSExpression *)fillAntialiased { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(fillAntialiased); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(fillAntialiased); self.rawLayer->setFillAntialias(mbglValue); } -- (MGLStyleValue<NSNumber *> *)isFillAntialiased { +- (NSExpression *)isFillAntialiased { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillAntialias(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultFillAntialias()); + propertyValue = self.rawLayer->getDefaultFillAntialias(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setFillAntialias:(MGLStyleValue<NSNumber *> *)fillAntialias { +- (void)setFillAntialias:(NSExpression *)fillAntialias { } -- (MGLStyleValue<NSNumber *> *)fillAntialias { +- (NSExpression *)fillAntialias { return self.isFillAntialiased; } -- (void)setFillColor:(MGLStyleValue<MGLColor *> *)fillColor { +- (void)setFillColor:(NSExpression *)fillColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(fillColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(fillColor); self.rawLayer->setFillColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)fillColor { +- (NSExpression *)fillColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillColor()); + propertyValue = self.rawLayer->getDefaultFillColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setFillColorTransition:(MGLTransition )transition { @@ -136,21 +136,21 @@ namespace mbgl { return transition; } -- (void)setFillOpacity:(MGLStyleValue<NSNumber *> *)fillOpacity { +- (void)setFillOpacity:(NSExpression *)fillOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(fillOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(fillOpacity); self.rawLayer->setFillOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)fillOpacity { +- (NSExpression *)fillOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillOpacity()); + propertyValue = self.rawLayer->getDefaultFillOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setFillOpacityTransition:(MGLTransition )transition { @@ -171,21 +171,21 @@ namespace mbgl { return transition; } -- (void)setFillOutlineColor:(MGLStyleValue<MGLColor *> *)fillOutlineColor { +- (void)setFillOutlineColor:(NSExpression *)fillOutlineColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(fillOutlineColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(fillOutlineColor); self.rawLayer->setFillOutlineColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)fillOutlineColor { +- (NSExpression *)fillOutlineColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillOutlineColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultFillOutlineColor()); + propertyValue = self.rawLayer->getDefaultFillOutlineColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setFillOutlineColorTransition:(MGLTransition )transition { @@ -206,21 +206,21 @@ namespace mbgl { return transition; } -- (void)setFillPattern:(MGLStyleValue<NSString *> *)fillPattern { +- (void)setFillPattern:(NSExpression *)fillPattern { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(fillPattern); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(fillPattern); self.rawLayer->setFillPattern(mbglValue); } -- (MGLStyleValue<NSString *> *)fillPattern { +- (NSExpression *)fillPattern { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillPattern(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(self.rawLayer->getDefaultFillPattern()); + propertyValue = self.rawLayer->getDefaultFillPattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setFillPatternTransition:(MGLTransition )transition { @@ -241,21 +241,21 @@ namespace mbgl { return transition; } -- (void)setFillTranslation:(MGLStyleValue<NSValue *> *)fillTranslation { +- (void)setFillTranslation:(NSExpression *)fillTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(fillTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(fillTranslation); self.rawLayer->setFillTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)fillTranslation { +- (NSExpression *)fillTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultFillTranslate()); + propertyValue = self.rawLayer->getDefaultFillTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setFillTranslationTransition:(MGLTransition )transition { @@ -276,34 +276,34 @@ namespace mbgl { return transition; } -- (void)setFillTranslate:(MGLStyleValue<NSValue *> *)fillTranslate { +- (void)setFillTranslate:(NSExpression *)fillTranslate { } -- (MGLStyleValue<NSValue *> *)fillTranslate { +- (NSExpression *)fillTranslate { return self.fillTranslation; } -- (void)setFillTranslationAnchor:(MGLStyleValue<NSValue *> *)fillTranslationAnchor { +- (void)setFillTranslationAnchor:(NSExpression *)fillTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslationAnchor>().toEnumPropertyValue(fillTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(fillTranslationAnchor); self.rawLayer->setFillTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)fillTranslationAnchor { +- (NSExpression *)fillTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getFillTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultFillTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultFillTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslationAnchor>().toExpression(propertyValue); } -- (void)setFillTranslateAnchor:(MGLStyleValue<NSValue *> *)fillTranslateAnchor { +- (void)setFillTranslateAnchor:(NSExpression *)fillTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)fillTranslateAnchor { +- (NSExpression *)fillTranslateAnchor { return self.fillTranslationAnchor; } diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.h b/platform/darwin/src/MGLHillshadeStyleLayer.h index 0fe49d510d..c1fa069844 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.h +++ b/platform/darwin/src/MGLHillshadeStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -59,41 +58,26 @@ MGL_EXPORT #pragma mark - Accessing the Paint Attributes -#if TARGET_OS_IPHONE /** The shading color used to accentuate rugged terrain like sharp cliffs and gorges. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeAccentColor; -#else -/** - The shading color used to accentuate rugged terrain like sharp cliffs and - gorges. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeAccentColor; -#endif +@property (nonatomic, null_resettable) NSExpression *hillshadeAccentColor; /** The transition affecting any changes to this layer’s `hillshadeAccentColor` property. @@ -105,18 +89,21 @@ MGL_EXPORT /** Intensity of the hillshade - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0.5`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `0.5`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *hillshadeExaggeration; +@property (nonatomic, null_resettable) NSExpression *hillshadeExaggeration; /** The transition affecting any changes to this layer’s `hillshadeExaggeration` property. @@ -125,39 +112,25 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition hillshadeExaggerationTransition; -#if TARGET_OS_IPHONE /** The shading color of areas that faces towards the light source. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.whiteColor`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeHighlightColor; -#else -/** - The shading color of areas that faces towards the light source. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.whiteColor`. Set this property to `nil` to reset it to the default - value. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeHighlightColor; -#endif +@property (nonatomic, null_resettable) NSExpression *hillshadeHighlightColor; /** The transition affecting any changes to this layer’s `hillshadeHighlightColor` property. @@ -169,17 +142,26 @@ MGL_EXPORT /** Direction of light source when map is rotated. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLHillshadeIlluminationAnchorViewport`. Set this - property to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to + `viewport`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLHillshadeIlluminationAnchor` values + * Any of the following constant string values: + * `map`: The hillshade illumination is relative to the north direction. + * `viewport`: The hillshade illumination is relative to the top of the + viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *hillshadeIlluminationAnchor; +@property (nonatomic, null_resettable) NSExpression *hillshadeIlluminationAnchor; /** The direction of the light source used to generate the hillshading with 0 as @@ -187,18 +169,21 @@ MGL_EXPORT `MGLHillshadeIlluminationAnchorViewport` and due north if `hillshadeIlluminationAnchor` is set to `MGLHillshadeIlluminationAnchorMap`. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `335`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `335`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *hillshadeIlluminationDirection; +@property (nonatomic, null_resettable) NSExpression *hillshadeIlluminationDirection; /** The transition affecting any changes to this layer’s `hillshadeIlluminationDirection` property. @@ -207,39 +192,25 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition hillshadeIlluminationDirectionTransition; -#if TARGET_OS_IPHONE /** The shading color of areas that face away from the light source. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeShadowColor; -#else -/** - The shading color of areas that face away from the light source. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeShadowColor; -#endif +@property (nonatomic, null_resettable) NSExpression *hillshadeShadowColor; /** The transition affecting any changes to this layer’s `hillshadeShadowColor` property. diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm index 3225feb587..ac12b52506 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.mm +++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm @@ -77,21 +77,21 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes -- (void)setHillshadeAccentColor:(MGLStyleValue<MGLColor *> *)hillshadeAccentColor { +- (void)setHillshadeAccentColor:(NSExpression *)hillshadeAccentColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeAccentColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(hillshadeAccentColor); self.rawLayer->setHillshadeAccentColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)hillshadeAccentColor { +- (NSExpression *)hillshadeAccentColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeAccentColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeAccentColor()); + propertyValue = self.rawLayer->getDefaultHillshadeAccentColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setHillshadeAccentColorTransition:(MGLTransition )transition { @@ -112,21 +112,21 @@ namespace mbgl { return transition; } -- (void)setHillshadeExaggeration:(MGLStyleValue<NSNumber *> *)hillshadeExaggeration { +- (void)setHillshadeExaggeration:(NSExpression *)hillshadeExaggeration { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(hillshadeExaggeration); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(hillshadeExaggeration); self.rawLayer->setHillshadeExaggeration(mbglValue); } -- (MGLStyleValue<NSNumber *> *)hillshadeExaggeration { +- (NSExpression *)hillshadeExaggeration { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeExaggeration(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultHillshadeExaggeration()); + propertyValue = self.rawLayer->getDefaultHillshadeExaggeration(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setHillshadeExaggerationTransition:(MGLTransition )transition { @@ -147,21 +147,21 @@ namespace mbgl { return transition; } -- (void)setHillshadeHighlightColor:(MGLStyleValue<MGLColor *> *)hillshadeHighlightColor { +- (void)setHillshadeHighlightColor:(NSExpression *)hillshadeHighlightColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeHighlightColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(hillshadeHighlightColor); self.rawLayer->setHillshadeHighlightColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)hillshadeHighlightColor { +- (NSExpression *)hillshadeHighlightColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeHighlightColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeHighlightColor()); + propertyValue = self.rawLayer->getDefaultHillshadeHighlightColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setHillshadeHighlightColorTransition:(MGLTransition )transition { @@ -182,38 +182,38 @@ namespace mbgl { return transition; } -- (void)setHillshadeIlluminationAnchor:(MGLStyleValue<NSValue *> *)hillshadeIlluminationAnchor { +- (void)setHillshadeIlluminationAnchor:(NSExpression *)hillshadeIlluminationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumPropertyValue(hillshadeIlluminationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::HillshadeIlluminationAnchorType>>(hillshadeIlluminationAnchor); self.rawLayer->setHillshadeIlluminationAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)hillshadeIlluminationAnchor { +- (NSExpression *)hillshadeIlluminationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeIlluminationAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultHillshadeIlluminationAnchor()); + propertyValue = self.rawLayer->getDefaultHillshadeIlluminationAnchor(); } - return MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toExpression(propertyValue); } -- (void)setHillshadeIlluminationDirection:(MGLStyleValue<NSNumber *> *)hillshadeIlluminationDirection { +- (void)setHillshadeIlluminationDirection:(NSExpression *)hillshadeIlluminationDirection { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(hillshadeIlluminationDirection); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(hillshadeIlluminationDirection); self.rawLayer->setHillshadeIlluminationDirection(mbglValue); } -- (MGLStyleValue<NSNumber *> *)hillshadeIlluminationDirection { +- (NSExpression *)hillshadeIlluminationDirection { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeIlluminationDirection(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultHillshadeIlluminationDirection()); + propertyValue = self.rawLayer->getDefaultHillshadeIlluminationDirection(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setHillshadeIlluminationDirectionTransition:(MGLTransition )transition { @@ -234,21 +234,21 @@ namespace mbgl { return transition; } -- (void)setHillshadeShadowColor:(MGLStyleValue<MGLColor *> *)hillshadeShadowColor { +- (void)setHillshadeShadowColor:(NSExpression *)hillshadeShadowColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeShadowColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(hillshadeShadowColor); self.rawLayer->setHillshadeShadowColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)hillshadeShadowColor { +- (NSExpression *)hillshadeShadowColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getHillshadeShadowColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeShadowColor()); + propertyValue = self.rawLayer->getDefaultHillshadeShadowColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setHillshadeShadowColorTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index 55b789f043..d7e64cbfad 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -27,7 +27,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) { A structure containing information about the position of the light source relative to lit geometries. */ -typedef struct MGLSphericalPosition { +typedef struct __attribute__((objc_boxable)) MGLSphericalPosition { /** Distance from the center of the base of an object to its light. */ CGFloat radial; /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds @@ -65,20 +65,31 @@ MGL_EXPORT /** Whether extruded geometries are lit relative to the map or viewport. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLLightAnchorViewport`. + The default value of this property is an expression that evaluates to + `viewport`. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLAnchor` values + * Any of the following constant string values: + * `map`: The position of the light source is aligned to the rotation of the + map. + * `viewport`: The position of the light source is aligned to the rotation of + the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. This property corresponds to the <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-anchor"><code>anchor</code></a> light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue<NSValue *> *anchor; +@property (nonatomic) NSExpression *anchor; /** Position of the `MGLLight` source relative to lit (extruded) geometries, in a @@ -90,21 +101,25 @@ MGL_EXPORT corresponds to due north, and degrees proceed clockwise), and polar indicates the height of the light (from 0°, directly above, to 180°, directly below). - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `MGLSphericalPosition` struct set to 1.15 radial, 210 azimuthal and 30 polar. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLSphericalPosition` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. This property corresponds to the <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-position"><code>position</code></a> light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue<NSValue *> *position; +@property (nonatomic) NSExpression *position; /** The transition affecting any changes to this layer’s `position` property. @@ -113,45 +128,28 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition positionTransition; -#if TARGET_OS_IPHONE /** Color tint for lighting extruded geometries. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.whiteColor`. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - - This property corresponds to the <a - href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a> - light property in the Mapbox Style Specification. - */ -@property (nonatomic) MGLStyleValue<UIColor *> *color; -#else -/** - Color tint for lighting extruded geometries. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.whiteColor`. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. This property corresponds to the <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a> light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue<NSColor *> *color; -#endif +@property (nonatomic) NSExpression *color; /** The transition affecting any changes to this layer’s `color` property. @@ -164,21 +162,25 @@ MGL_EXPORT Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0.5`. + The default value of this property is an expression that evaluates to the float + `0.5`. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. This property corresponds to the <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-intensity"><code>intensity</code></a> light property in the Mapbox Style Specification. */ -@property (nonatomic) MGLStyleValue<NSNumber *> *intensity; +@property (nonatomic) NSExpression *intensity; /** The transition affecting any changes to this layer’s `intensity` property. diff --git a/platform/darwin/src/MGLLight.h.ejs b/platform/darwin/src/MGLLight.h.ejs index 26ecefc3af..56c3312107 100644 --- a/platform/darwin/src/MGLLight.h.ejs +++ b/platform/darwin/src/MGLLight.h.ejs @@ -33,7 +33,7 @@ typedef NS_ENUM(NSUInteger, MGLLight<%- camelize(property.name) %>) { A structure containing information about the position of the light source relative to lit geometries. */ -typedef struct MGLSphericalPosition { +typedef struct __attribute__((objc_boxable)) MGLSphericalPosition { /** Distance from the center of the base of an object to its light. */ CGFloat radial; /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds @@ -77,7 +77,7 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-<%- originalPropertyName(property) %>"><code><%- originalPropertyName(property) %></code></a> light property in the Mapbox Style Specification. */ -@property (nonatomic<% if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>; +@property (nonatomic<% if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) NSExpression *<%- camelizeWithLeadingLowercase(property.name) %>; <% if (property.transition) { -%> /** @@ -89,7 +89,7 @@ MGL_EXPORT <% } -%> <% if (property.original) { -%> -@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) NSExpression *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); <% } -%> <% } -%> diff --git a/platform/darwin/src/MGLLight.mm b/platform/darwin/src/MGLLight.mm index c83ef127a6..db2893ed44 100644 --- a/platform/darwin/src/MGLLight.mm +++ b/platform/darwin/src/MGLLight.mm @@ -44,39 +44,39 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition { if (self = [super init]) { auto anchor = mbglLight->getAnchor(); - MGLStyleValue<NSValue *> *anchorStyleValue; + NSExpression *anchorExpression; if (anchor.isUndefined()) { mbgl::style::PropertyValue<mbgl::style::LightAnchorType> defaultAnchor = mbglLight->getDefaultAnchor(); - anchorStyleValue = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toEnumStyleValue(defaultAnchor); + anchorExpression = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toExpression(defaultAnchor); } else { - anchorStyleValue = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toEnumStyleValue(anchor); + anchorExpression = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toExpression(anchor); } - _anchor = anchorStyleValue; + _anchor = anchorExpression; auto positionValue = mbglLight->getPosition(); if (positionValue.isUndefined()) { - _position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toStyleValue(mbglLight->getDefaultPosition()); + _position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toExpression(mbglLight->getDefaultPosition()); } else { - _position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toStyleValue(positionValue); + _position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toExpression(positionValue); } _positionTransition = MGLTransitionFromOptions(mbglLight->getPositionTransition()); auto colorValue = mbglLight->getColor(); if (colorValue.isUndefined()) { - _color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(mbglLight->getDefaultColor()); + _color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(mbglLight->getDefaultColor()); } else { - _color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(colorValue); + _color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(colorValue); } _colorTransition = MGLTransitionFromOptions(mbglLight->getColorTransition()); auto intensityValue = mbglLight->getIntensity(); if (intensityValue.isUndefined()) { - _intensity = MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(mbglLight->getDefaultIntensity()); + _intensity = MGLStyleValueTransformer<float, NSNumber *>().toExpression(mbglLight->getDefaultIntensity()); } else { - _intensity = MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(intensityValue); + _intensity = MGLStyleValueTransformer<float, NSNumber *>().toExpression(intensityValue); } _intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition()); @@ -89,20 +89,20 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition - (mbgl::style::Light)mbglLight { mbgl::style::Light mbglLight; - auto anchor = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toEnumPropertyValue(self.anchor); + auto anchor = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::LightAnchorType>>(self.anchor); mbglLight.setAnchor(anchor); - auto position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toInterpolatablePropertyValue(self.position); + auto position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::Position>>(self.position); mbglLight.setPosition(position); mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransition)); - auto color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(self.color); + auto color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::PropertyValue<mbgl::Color>>(self.color); mbglLight.setColor(color); mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransition)); - auto intensity = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(self.intensity); + auto intensity = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(self.intensity); mbglLight.setIntensity(intensity); mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition)); diff --git a/platform/darwin/src/MGLLight.mm.ejs b/platform/darwin/src/MGLLight.mm.ejs index 0d0da124c8..b241269519 100644 --- a/platform/darwin/src/MGLLight.mm.ejs +++ b/platform/darwin/src/MGLLight.mm.ejs @@ -55,15 +55,15 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition <% for (const property of properties) { -%> <% if (property.type == "enum") { -%> auto <%- camelizeWithLeadingLowercase(property.name) -%> = mbglLight->get<%- camelize(property.name) -%>(); - MGLStyleValue<NSValue *> *<%- camelizeWithLeadingLowercase(property.name) -%>StyleValue; + NSExpression *<%- camelizeWithLeadingLowercase(property.name) -%>Expression; if (<%- camelizeWithLeadingLowercase(property.name) -%>.isUndefined()) { mbgl::style::PropertyValue<mbgl::style::Light<%- camelize(property.name) -%>Type> default<%- camelize(property.name) -%> = mbglLight->getDefault<%- camelize(property.name) -%>(); - <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(default<%- camelize(property.name) -%>); + <%- camelizeWithLeadingLowercase(property.name) -%>Expression = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toExpression(default<%- camelize(property.name) -%>); } else { - <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>); + <%- camelizeWithLeadingLowercase(property.name) -%>Expression = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toExpression(<%- camelizeWithLeadingLowercase(property.name) -%>); } - _<%- camelizeWithLeadingLowercase(property.name) -%> = <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue; + _<%- camelizeWithLeadingLowercase(property.name) -%> = <%- camelizeWithLeadingLowercase(property.name) -%>Expression; <% if (property.transition) { -%> _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition()); @@ -72,9 +72,9 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition <% } else {-%> auto <%- camelizeWithLeadingLowercase(property.name) -%>Value = mbglLight->get<%- camelize(property.name) -%>(); if (<%- camelizeWithLeadingLowercase(property.name) -%>Value.isUndefined()) { - _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(mbglLight->getDefault<%- camelize(property.name) -%>()); + _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(mbglLight->getDefault<%- camelize(property.name) -%>()); } else { - _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>Value); + _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(<%- camelizeWithLeadingLowercase(property.name) -%>Value); } <% if (property.transition) { -%> _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition()); @@ -93,11 +93,11 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition <% if (properties.length) { -%> <% for (const property of properties) { -%> <% if (property.type == "enum") { -%> - auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumPropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>); + auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(self.<%- camelizeWithLeadingLowercase(property.name) -%>); mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>); <% } else {-%> - auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toInterpolatablePropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>); + auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(self.<%- camelizeWithLeadingLowercase(property.name) -%>); mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>); <% } -%> diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index e48951d97b..003f48ae43 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -94,12 +93,11 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslationAnchor) { ```swift let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails) layer.sourceLayerIdentifier = "trails" - layer.lineWidth = MGLStyleValue(interpolationMode: .exponential, - cameraStops: [14: MGLStyleValue(rawValue: 2), - 18: MGLStyleValue(rawValue: 20)], - options: [.interpolationBase: 1.5]) - layer.lineColor = MGLStyleValue(rawValue: .brown) - layer.lineCap = MGLStyleValue(rawValue: NSValue(mglLineCap: .round)) + layer.lineWidth = NSExpression(format: "FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'exponential', 1.5, %@)", + [14: 2, + 18: 20]) + layer.lineColor = NSExpression(forConstantValue: UIColor.brown) + layer.lineCap = NSExpression(forConstantValue: "round") layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking") mapView.style?.addLayer(layer) ``` @@ -127,82 +125,99 @@ MGL_EXPORT /** The display of line endings. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLLineCapButt`. Set this property to `nil` to - reset it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + The default value of this property is an expression that evaluates to `butt`. + Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant `MGLLineCap` values + * Any of the following constant string values: + * `butt`: A cap with a squared-off end which is drawn to the exact endpoint + of the line. + * `round`: A cap with a rounded end which is drawn beyond the endpoint of the + line at a radius of one-half of the line's width and centered on the endpoint + of the line. + * `square`: A cap with a squared-off end which is drawn beyond the endpoint + of the line at a distance of one-half of the line's width. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineCap; +@property (nonatomic, null_resettable) NSExpression *lineCap; /** The display of lines when joining. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLLineJoinMiter`. Set this property to `nil` to - reset it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to `miter`. + Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant `MGLLineJoin` values + * Any of the following constant string values: + * `bevel`: A join with a squared-off end which is drawn beyond the endpoint + of the line at a distance of one-half of the line's width. + * `round`: A join with a rounded end which is drawn beyond the endpoint of + the line at a radius of one-half of the line's width and centered on the + endpoint of the line. + * `miter`: A join with a sharp, angled corner which is drawn with the outer + sides beyond the endpoint of the path until they meet. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineJoin; +@property (nonatomic, null_resettable) NSExpression *lineJoin; /** Used to automatically convert miter joins to bevel joins for sharp angles. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `2`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `lineJoin` is set to an - `MGLStyleValue` object containing an `NSValue` object containing - `MGLLineJoinMiter`. Otherwise, it is ignored. + expression that evaluates to `miter`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineMiterLimit; +@property (nonatomic, null_resettable) NSExpression *lineMiterLimit; /** Used to automatically convert round joins to miter joins for shallow angles. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1.05`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `1.05`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `lineJoin` is set to an - `MGLStyleValue` object containing an `NSValue` object containing - `MGLLineJoinRound`. Otherwise, it is ignored. + expression that evaluates to `round`. Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineRoundLimit; +@property (nonatomic, null_resettable) NSExpression *lineRoundLimit; #pragma mark - Accessing the Paint Attributes @@ -211,27 +226,19 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineBlur; +@property (nonatomic, null_resettable) NSExpression *lineBlur; /** The transition affecting any changes to this layer’s `lineBlur` property. @@ -240,63 +247,26 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition lineBlurTransition; -#if TARGET_OS_IPHONE /** The color with which the line will be drawn. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `linePattern` is set to `nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *lineColor; -#else -/** - The color with which the line will be drawn. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `linePattern` is set to `nil`. - Otherwise, it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *lineColor; -#endif +@property (nonatomic, null_resettable) NSExpression *lineColor; /** The transition affecting any changes to this layer’s `lineColor` property. @@ -319,13 +289,19 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-line-dasharray"><code>line-dasharray</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant array values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSArray<NSNumber *> *> *lineDashPattern; +@property (nonatomic, null_resettable) NSExpression *lineDashPattern; /** The transition affecting any changes to this layer’s `lineDashPattern` property. @@ -334,7 +310,7 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition lineDashPatternTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSArray<NSNumber *> *> *lineDasharray __attribute__((unavailable("Use lineDashPattern instead."))); +@property (nonatomic, null_resettable) NSExpression *lineDasharray __attribute__((unavailable("Use lineDashPattern instead."))); /** Draws a line casing outside of a line's actual path. Value indicates the width @@ -342,27 +318,19 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineGapWidth; +@property (nonatomic, null_resettable) NSExpression *lineGapWidth; /** The transition affecting any changes to this layer’s `lineGapWidth` property. @@ -379,27 +347,19 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineOffset; +@property (nonatomic, null_resettable) NSExpression *lineOffset; /** The transition affecting any changes to this layer’s `lineOffset` property. @@ -411,27 +371,19 @@ MGL_EXPORT /** The opacity at which the line will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineOpacity; +@property (nonatomic, null_resettable) NSExpression *lineOpacity; /** The transition affecting any changes to this layer’s `lineOpacity` property. @@ -444,13 +396,19 @@ MGL_EXPORT Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *linePattern; +@property (nonatomic, null_resettable) NSExpression *linePattern; /** The transition affecting any changes to this layer’s `linePattern` property. @@ -465,7 +423,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -473,21 +431,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-line-translate"><code>line-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineTranslation; +@property (nonatomic, null_resettable) NSExpression *lineTranslation; #else /** The geometry's offset. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -495,14 +457,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-line-translate"><code>line-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineTranslation; +@property (nonatomic, null_resettable) NSExpression *lineTranslation; #endif /** @@ -512,14 +478,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition lineTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineTranslate __attribute__((unavailable("Use lineTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *lineTranslate __attribute__((unavailable("Use lineTranslation instead."))); /** Controls the frame of reference for `lineTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLLineTranslationAnchorMap`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `lineTranslation` is non-`nil`. Otherwise, it is ignored. @@ -528,42 +493,43 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-line-translate-anchor"><code>line-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLLineTranslationAnchor` values + * Any of the following constant string values: + * `map`: The line is translated relative to the map. + * `viewport`: The line is translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *lineTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *lineTranslateAnchor __attribute__((unavailable("Use lineTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *lineTranslateAnchor __attribute__((unavailable("Use lineTranslationAnchor instead."))); /** Stroke thickness. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. - - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *lineWidth; +@property (nonatomic, null_resettable) NSExpression *lineWidth; /** The transition affecting any changes to this layer’s `lineWidth` property. diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 5b2652cdeb..4e6ff27b39 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -89,91 +89,91 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes -- (void)setLineCap:(MGLStyleValue<NSValue *> *)lineCap { +- (void)setLineCap:(NSExpression *)lineCap { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumPropertyValue(lineCap); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::LineCapType>>(lineCap); self.rawLayer->setLineCap(mbglValue); } -- (MGLStyleValue<NSValue *> *)lineCap { +- (NSExpression *)lineCap { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineCap(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumStyleValue(self.rawLayer->getDefaultLineCap()); + propertyValue = self.rawLayer->getDefaultLineCap(); } - return MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toExpression(propertyValue); } -- (void)setLineJoin:(MGLStyleValue<NSValue *> *)lineJoin { +- (void)setLineJoin:(NSExpression *)lineJoin { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenPropertyValue(lineJoin); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::style::LineJoinType>>(lineJoin); self.rawLayer->setLineJoin(mbglValue); } -- (MGLStyleValue<NSValue *> *)lineJoin { +- (NSExpression *)lineJoin { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineJoin(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineJoin()); + propertyValue = self.rawLayer->getDefaultLineJoin(); } - return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toExpression(propertyValue); } -- (void)setLineMiterLimit:(MGLStyleValue<NSNumber *> *)lineMiterLimit { +- (void)setLineMiterLimit:(NSExpression *)lineMiterLimit { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(lineMiterLimit); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(lineMiterLimit); self.rawLayer->setLineMiterLimit(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineMiterLimit { +- (NSExpression *)lineMiterLimit { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineMiterLimit(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultLineMiterLimit()); + propertyValue = self.rawLayer->getDefaultLineMiterLimit(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setLineRoundLimit:(MGLStyleValue<NSNumber *> *)lineRoundLimit { +- (void)setLineRoundLimit:(NSExpression *)lineRoundLimit { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(lineRoundLimit); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(lineRoundLimit); self.rawLayer->setLineRoundLimit(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineRoundLimit { +- (NSExpression *)lineRoundLimit { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineRoundLimit(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultLineRoundLimit()); + propertyValue = self.rawLayer->getDefaultLineRoundLimit(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } #pragma mark - Accessing the Paint Attributes -- (void)setLineBlur:(MGLStyleValue<NSNumber *> *)lineBlur { +- (void)setLineBlur:(NSExpression *)lineBlur { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineBlur); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(lineBlur); self.rawLayer->setLineBlur(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineBlur { +- (NSExpression *)lineBlur { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineBlur(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineBlur()); + propertyValue = self.rawLayer->getDefaultLineBlur(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setLineBlurTransition:(MGLTransition )transition { @@ -194,21 +194,21 @@ namespace mbgl { return transition; } -- (void)setLineColor:(MGLStyleValue<MGLColor *> *)lineColor { +- (void)setLineColor:(NSExpression *)lineColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(lineColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(lineColor); self.rawLayer->setLineColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)lineColor { +- (NSExpression *)lineColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineColor()); + propertyValue = self.rawLayer->getDefaultLineColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setLineColorTransition:(MGLTransition )transition { @@ -229,21 +229,21 @@ namespace mbgl { return transition; } -- (void)setLineDashPattern:(MGLStyleValue<NSArray<NSNumber *> *> *)lineDashPattern { +- (void)setLineDashPattern:(NSExpression *)lineDashPattern { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toPropertyValue(lineDashPattern); + auto mbglValue = MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toPropertyValue<mbgl::style::PropertyValue<std::vector<float>>>(lineDashPattern); self.rawLayer->setLineDasharray(mbglValue); } -- (MGLStyleValue<NSArray<NSNumber *> *> *)lineDashPattern { +- (NSExpression *)lineDashPattern { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineDasharray(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toStyleValue(self.rawLayer->getDefaultLineDasharray()); + propertyValue = self.rawLayer->getDefaultLineDasharray(); } - return MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::vector<float>, NSArray<NSNumber *> *, float>().toExpression(propertyValue); } - (void)setLineDashPatternTransition:(MGLTransition )transition { @@ -264,28 +264,28 @@ namespace mbgl { return transition; } -- (void)setLineDasharray:(MGLStyleValue<NSArray<NSNumber *> *> *)lineDasharray { +- (void)setLineDasharray:(NSExpression *)lineDasharray { } -- (MGLStyleValue<NSArray<NSNumber *> *> *)lineDasharray { +- (NSExpression *)lineDasharray { return self.lineDashPattern; } -- (void)setLineGapWidth:(MGLStyleValue<NSNumber *> *)lineGapWidth { +- (void)setLineGapWidth:(NSExpression *)lineGapWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineGapWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(lineGapWidth); self.rawLayer->setLineGapWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineGapWidth { +- (NSExpression *)lineGapWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineGapWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineGapWidth()); + propertyValue = self.rawLayer->getDefaultLineGapWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setLineGapWidthTransition:(MGLTransition )transition { @@ -306,21 +306,21 @@ namespace mbgl { return transition; } -- (void)setLineOffset:(MGLStyleValue<NSNumber *> *)lineOffset { +- (void)setLineOffset:(NSExpression *)lineOffset { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineOffset); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(lineOffset); self.rawLayer->setLineOffset(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineOffset { +- (NSExpression *)lineOffset { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineOffset(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineOffset()); + propertyValue = self.rawLayer->getDefaultLineOffset(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setLineOffsetTransition:(MGLTransition )transition { @@ -341,21 +341,21 @@ namespace mbgl { return transition; } -- (void)setLineOpacity:(MGLStyleValue<NSNumber *> *)lineOpacity { +- (void)setLineOpacity:(NSExpression *)lineOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(lineOpacity); self.rawLayer->setLineOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineOpacity { +- (NSExpression *)lineOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineOpacity()); + propertyValue = self.rawLayer->getDefaultLineOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setLineOpacityTransition:(MGLTransition )transition { @@ -376,21 +376,21 @@ namespace mbgl { return transition; } -- (void)setLinePattern:(MGLStyleValue<NSString *> *)linePattern { +- (void)setLinePattern:(NSExpression *)linePattern { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(linePattern); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::PropertyValue<std::string>>(linePattern); self.rawLayer->setLinePattern(mbglValue); } -- (MGLStyleValue<NSString *> *)linePattern { +- (NSExpression *)linePattern { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLinePattern(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(self.rawLayer->getDefaultLinePattern()); + propertyValue = self.rawLayer->getDefaultLinePattern(); } - return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } - (void)setLinePatternTransition:(MGLTransition )transition { @@ -411,21 +411,21 @@ namespace mbgl { return transition; } -- (void)setLineTranslation:(MGLStyleValue<NSValue *> *)lineTranslation { +- (void)setLineTranslation:(NSExpression *)lineTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(lineTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(lineTranslation); self.rawLayer->setLineTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)lineTranslation { +- (NSExpression *)lineTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultLineTranslate()); + propertyValue = self.rawLayer->getDefaultLineTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setLineTranslationTransition:(MGLTransition )transition { @@ -446,52 +446,52 @@ namespace mbgl { return transition; } -- (void)setLineTranslate:(MGLStyleValue<NSValue *> *)lineTranslate { +- (void)setLineTranslate:(NSExpression *)lineTranslate { } -- (MGLStyleValue<NSValue *> *)lineTranslate { +- (NSExpression *)lineTranslate { return self.lineTranslation; } -- (void)setLineTranslationAnchor:(MGLStyleValue<NSValue *> *)lineTranslationAnchor { +- (void)setLineTranslationAnchor:(NSExpression *)lineTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslationAnchor>().toEnumPropertyValue(lineTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(lineTranslationAnchor); self.rawLayer->setLineTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)lineTranslationAnchor { +- (NSExpression *)lineTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultLineTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultLineTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslationAnchor>().toExpression(propertyValue); } -- (void)setLineTranslateAnchor:(MGLStyleValue<NSValue *> *)lineTranslateAnchor { +- (void)setLineTranslateAnchor:(NSExpression *)lineTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)lineTranslateAnchor { +- (NSExpression *)lineTranslateAnchor { return self.lineTranslationAnchor; } -- (void)setLineWidth:(MGLStyleValue<NSNumber *> *)lineWidth { +- (void)setLineWidth:(NSExpression *)lineWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(lineWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(lineWidth); self.rawLayer->setLineWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)lineWidth { +- (NSExpression *)lineWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getLineWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultLineWidth()); + propertyValue = self.rawLayer->getDefaultLineWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setLineWidthTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h index e808bb5242..55d49329c2 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.h +++ b/platform/darwin/src/MGLRasterStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLForegroundStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -29,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN ```swift let layer = MGLRasterStyleLayer(identifier: "clouds", source: source) - layer.rasterOpacity = MGLStyleValue(rawValue: 0.5) + layer.rasterOpacity = NSExpression(forConstantValue: 0.5) mapView.style?.addLayer(layer) ``` */ @@ -57,22 +56,25 @@ MGL_EXPORT Increase or reduce the brightness of the image. The value is the maximum brightness. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-brightness-max"><code>raster-brightness-max</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *maximumRasterBrightness; +@property (nonatomic, null_resettable) NSExpression *maximumRasterBrightness; /** The transition affecting any changes to this layer’s `maximumRasterBrightness` property. @@ -81,28 +83,31 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition maximumRasterBrightnessTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMax __attribute__((unavailable("Use maximumRasterBrightness instead."))); +@property (nonatomic, null_resettable) NSExpression *rasterBrightnessMax __attribute__((unavailable("Use maximumRasterBrightness instead."))); /** Increase or reduce the brightness of the image. The value is the minimum brightness. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-brightness-min"><code>raster-brightness-min</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *minimumRasterBrightness; +@property (nonatomic, null_resettable) NSExpression *minimumRasterBrightness; /** The transition affecting any changes to this layer’s `minimumRasterBrightness` property. @@ -111,23 +116,26 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition minimumRasterBrightnessTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMin __attribute__((unavailable("Use minimumRasterBrightness instead."))); +@property (nonatomic, null_resettable) NSExpression *rasterBrightnessMin __attribute__((unavailable("Use minimumRasterBrightness instead."))); /** Increase or reduce the contrast of the image. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterContrast; +@property (nonatomic, null_resettable) NSExpression *rasterContrast; /** The transition affecting any changes to this layer’s `rasterContrast` property. @@ -141,40 +149,46 @@ MGL_EXPORT This property is measured in milliseconds. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `300`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `300`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterFadeDuration; +@property (nonatomic, null_resettable) NSExpression *rasterFadeDuration; /** Rotates hues around the color wheel. This property is measured in degrees. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-hue-rotate"><code>raster-hue-rotate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterHueRotation; +@property (nonatomic, null_resettable) NSExpression *rasterHueRotation; /** The transition affecting any changes to this layer’s `rasterHueRotation` property. @@ -183,23 +197,26 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition rasterHueRotationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterHueRotate __attribute__((unavailable("Use rasterHueRotation instead."))); +@property (nonatomic, null_resettable) NSExpression *rasterHueRotate __attribute__((unavailable("Use rasterHueRotation instead."))); /** The opacity at which the image will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterOpacity; +@property (nonatomic, null_resettable) NSExpression *rasterOpacity; /** The transition affecting any changes to this layer’s `rasterOpacity` property. @@ -211,18 +228,21 @@ MGL_EXPORT /** Increase or reduce the saturation of the image. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterSaturation; +@property (nonatomic, null_resettable) NSExpression *rasterSaturation; /** The transition affecting any changes to this layer’s `rasterSaturation` property. diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 277b2b82a6..94a58409de 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -39,21 +39,21 @@ #pragma mark - Accessing the Paint Attributes -- (void)setMaximumRasterBrightness:(MGLStyleValue<NSNumber *> *)maximumRasterBrightness { +- (void)setMaximumRasterBrightness:(NSExpression *)maximumRasterBrightness { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(maximumRasterBrightness); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(maximumRasterBrightness); self.rawLayer->setRasterBrightnessMax(mbglValue); } -- (MGLStyleValue<NSNumber *> *)maximumRasterBrightness { +- (NSExpression *)maximumRasterBrightness { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterBrightnessMax(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterBrightnessMax()); + propertyValue = self.rawLayer->getDefaultRasterBrightnessMax(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setMaximumRasterBrightnessTransition:(MGLTransition )transition { @@ -74,28 +74,28 @@ return transition; } -- (void)setRasterBrightnessMax:(MGLStyleValue<NSNumber *> *)rasterBrightnessMax { +- (void)setRasterBrightnessMax:(NSExpression *)rasterBrightnessMax { } -- (MGLStyleValue<NSNumber *> *)rasterBrightnessMax { +- (NSExpression *)rasterBrightnessMax { return self.maximumRasterBrightness; } -- (void)setMinimumRasterBrightness:(MGLStyleValue<NSNumber *> *)minimumRasterBrightness { +- (void)setMinimumRasterBrightness:(NSExpression *)minimumRasterBrightness { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(minimumRasterBrightness); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(minimumRasterBrightness); self.rawLayer->setRasterBrightnessMin(mbglValue); } -- (MGLStyleValue<NSNumber *> *)minimumRasterBrightness { +- (NSExpression *)minimumRasterBrightness { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterBrightnessMin(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterBrightnessMin()); + propertyValue = self.rawLayer->getDefaultRasterBrightnessMin(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setMinimumRasterBrightnessTransition:(MGLTransition )transition { @@ -116,28 +116,28 @@ return transition; } -- (void)setRasterBrightnessMin:(MGLStyleValue<NSNumber *> *)rasterBrightnessMin { +- (void)setRasterBrightnessMin:(NSExpression *)rasterBrightnessMin { } -- (MGLStyleValue<NSNumber *> *)rasterBrightnessMin { +- (NSExpression *)rasterBrightnessMin { return self.minimumRasterBrightness; } -- (void)setRasterContrast:(MGLStyleValue<NSNumber *> *)rasterContrast { +- (void)setRasterContrast:(NSExpression *)rasterContrast { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(rasterContrast); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(rasterContrast); self.rawLayer->setRasterContrast(mbglValue); } -- (MGLStyleValue<NSNumber *> *)rasterContrast { +- (NSExpression *)rasterContrast { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterContrast(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterContrast()); + propertyValue = self.rawLayer->getDefaultRasterContrast(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setRasterContrastTransition:(MGLTransition )transition { @@ -158,38 +158,38 @@ return transition; } -- (void)setRasterFadeDuration:(MGLStyleValue<NSNumber *> *)rasterFadeDuration { +- (void)setRasterFadeDuration:(NSExpression *)rasterFadeDuration { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(rasterFadeDuration); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(rasterFadeDuration); self.rawLayer->setRasterFadeDuration(mbglValue); } -- (MGLStyleValue<NSNumber *> *)rasterFadeDuration { +- (NSExpression *)rasterFadeDuration { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterFadeDuration(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterFadeDuration()); + propertyValue = self.rawLayer->getDefaultRasterFadeDuration(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setRasterHueRotation:(MGLStyleValue<NSNumber *> *)rasterHueRotation { +- (void)setRasterHueRotation:(NSExpression *)rasterHueRotation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(rasterHueRotation); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(rasterHueRotation); self.rawLayer->setRasterHueRotate(mbglValue); } -- (MGLStyleValue<NSNumber *> *)rasterHueRotation { +- (NSExpression *)rasterHueRotation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterHueRotate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterHueRotate()); + propertyValue = self.rawLayer->getDefaultRasterHueRotate(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setRasterHueRotationTransition:(MGLTransition )transition { @@ -210,28 +210,28 @@ return transition; } -- (void)setRasterHueRotate:(MGLStyleValue<NSNumber *> *)rasterHueRotate { +- (void)setRasterHueRotate:(NSExpression *)rasterHueRotate { } -- (MGLStyleValue<NSNumber *> *)rasterHueRotate { +- (NSExpression *)rasterHueRotate { return self.rasterHueRotation; } -- (void)setRasterOpacity:(MGLStyleValue<NSNumber *> *)rasterOpacity { +- (void)setRasterOpacity:(NSExpression *)rasterOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(rasterOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(rasterOpacity); self.rawLayer->setRasterOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)rasterOpacity { +- (NSExpression *)rasterOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterOpacity()); + propertyValue = self.rawLayer->getDefaultRasterOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setRasterOpacityTransition:(MGLTransition )transition { @@ -252,21 +252,21 @@ return transition; } -- (void)setRasterSaturation:(MGLStyleValue<NSNumber *> *)rasterSaturation { +- (void)setRasterSaturation:(NSExpression *)rasterSaturation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(rasterSaturation); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(rasterSaturation); self.rawLayer->setRasterSaturation(mbglValue); } -- (MGLStyleValue<NSNumber *> *)rasterSaturation { +- (NSExpression *)rasterSaturation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getRasterSaturation(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultRasterSaturation()); + propertyValue = self.rawLayer->getDefaultRasterSaturation(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setRasterSaturationTransition:(MGLTransition )transition { diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 5221e838f8..fefd8fcf37 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -677,70 +677,31 @@ static NSURL *MGLStyleURL_trafficNight; return localizedString; }; - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - NSString *textField = [(MGLConstantStyleValue<NSString *> *)layer.text rawValue]; + if (layer.text.expressionType == NSConstantValueExpressionType) { + NSString *textField = layer.text.constantValue; NSString *localizingString = stringByLocalizingString(textField); if (![textField isEqualToString:localizingString]) { MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField updatedTextField:localizingString]; [self.localizedLayersByIdentifier setObject:@{ textField : textLanguage } forKey:layer.identifier]; - layer.text = [MGLStyleValue<NSString *> valueWithRawValue:localizingString]; + layer.text = [NSExpression expressionForConstantValue:localizingString]; } } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction<NSString *> *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - NSMutableDictionary *cameraStops = [NSMutableDictionary dictionary]; - [stops enumerateKeysAndObjectsUsingBlock:^(NSNumber *zoomLevel, MGLConstantStyleValue<NSString *> *stop, BOOL *done) { - NSString *textField = stop.rawValue; - NSString *localizingString = stringByLocalizingString(textField); - if (![textField isEqualToString:localizingString]) { - MGLTextLanguage *textLanguage = [[MGLTextLanguage alloc] initWithTextLanguage:textField - updatedTextField:localizingString]; - [cameraStops setObject:textLanguage forKey:zoomLevel]; - stops[zoomLevel] = [MGLStyleValue<NSString *> valueWithRawValue:localizingString]; - } - - }]; - if (cameraStops.count > 0) { - [self.localizedLayersByIdentifier setObject:cameraStops forKey:layer.identifier]; - } - function.stops = stops; - layer.text = function; - } } } else { [self.localizedLayersByIdentifier enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSDictionary<NSObject *, MGLTextLanguage *> *textFields, BOOL *done) { MGLSymbolStyleLayer *layer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:identifier]; - if ([layer.text isKindOfClass:[MGLConstantStyleValue class]]) { - NSString *textField = [(MGLConstantStyleValue<NSString *> *)layer.text rawValue]; + if (layer.text.expressionType == NSConstantValueExpressionType) { + NSString *textField = layer.text.constantValue; [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *originalLanguage, MGLTextLanguage *textLanguage, BOOL *done) { if ([textLanguage.updatedTextField isEqualToString:textField]) { - layer.text = [MGLStyleValue<NSString *> valueWithRawValue:textLanguage.originalTextField]; + layer.text = [NSExpression expressionForConstantValue:textLanguage.originalTextField]; } }]; } - else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction *function = (MGLCameraStyleFunction<NSString *> *)layer.text; - NSMutableDictionary *stops = function.stops.mutableCopy; - [textFields enumerateKeysAndObjectsUsingBlock:^(NSObject *zoomKey, MGLTextLanguage *textLanguage, BOOL *done) { - if ([zoomKey isKindOfClass:[NSNumber class]]) { - NSNumber *zoomLevel = (NSNumber*)zoomKey; - MGLConstantStyleValue<NSString *> *stop = [stops objectForKey:zoomLevel]; - NSString *textField = stop.rawValue; - if ([textLanguage.updatedTextField isEqualToString:textField]) { - stops[zoomLevel] = [MGLStyleValue<NSString *> valueWithRawValue:textLanguage.originalTextField]; - } - } - }]; - - function.stops = stops; - layer.text = function; - } - }]; self.localizedLayersByIdentifier = [NSMutableDictionary dictionary]; diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs index df42621c6d..db16df3de5 100644 --- a/platform/darwin/src/MGLStyleLayer.h.ejs +++ b/platform/darwin/src/MGLStyleLayer.h.ejs @@ -9,7 +9,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGL<%- (type === 'background' ? '' : (type === 'raster' ? 'Foreground' : @@ -120,10 +119,10 @@ which it is added. /** <%- propertyDoc(property.name, property, type, 'layout').wrap(80, 1) %> */ -@property (nonatomic<% if (!property.required) { %>, null_resettable<% } if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>; +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) NSExpression *<%- camelizeWithLeadingLowercase(property.name) %>; <% if (property.original) { %> -@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) NSExpression *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); <% } -%> <% } -%> @@ -135,7 +134,7 @@ which it is added. /** <%- propertyDoc(property.name, property, type, 'paint').wrap(80, 1) %> */ -@property (nonatomic<% if (!property.required) { %>, null_resettable<% } if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>; +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) NSExpression *<%- camelizeWithLeadingLowercase(property.name) %>; <% if (property["transition"]) { -%> /** @@ -147,7 +146,7 @@ which it is added. <% } -%> <% if (property.original) { -%> -@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); +@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) NSExpression *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead."))); <% } -%> <% } -%> diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index da67cbd633..8101c1f463 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -118,52 +118,32 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes <% for (const property of layoutProperties) { -%> -- (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { +- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> { MGLAssertStyleLayerIsValid(); <% if (property["property-function"]) { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenPropertyValue(<%- objCName(property) %>); + auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>); <% } else { -%> -<% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toEnumPropertyValue(<%- objCName(property) %>); -<% } else if (property.function == "piecewise-constant") { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); -<% } else { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toInterpolatablePropertyValue(<%- objCName(property) %>); -<% } -%> + auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>); <% } -%> self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); } -- (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCGetter(property) %> { +- (NSExpression *)<%- objCGetter(property) %> { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>(); -<% if (property["property-function"]) { -%> if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); + propertyValue = self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); } - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenStyleValue(propertyValue); -<% } else { -%> -<% if (property.type == "enum") { -%> - if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- mbglType(property) %>, NSValue *, <%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); - } - return MGLStyleValueTransformer<<%- mbglType(property) %>, NSValue *, <%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); -<% } else { -%> - if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); - } - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); -<% } -%> -<% } -%> + return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(propertyValue); } <% if (property.original) { -%> -- (void)set<%- camelize(originalPropertyName(property)) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { +- (void)set<%- camelize(originalPropertyName(property)) %>:(NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { } -- (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { +- (NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { return self.<%- objCGetter(property) %>; } @@ -174,45 +154,25 @@ namespace mbgl { #pragma mark - Accessing the Paint Attributes <% for (const property of paintProperties) { -%> -- (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { +- (void)set<%- camelize(property.name) %>:(NSExpression *)<%- objCName(property) %> { MGLAssertStyleLayerIsValid(); <% if (property["property-function"]) { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenPropertyValue(<%- objCName(property) %>); + auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>); <% } else { -%> -<% if (property.type == "enum") { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toEnumPropertyValue(<%- objCName(property) %>); -<% } else if (property.function == "piecewise-constant") { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); -<% } else { -%> - auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toInterpolatablePropertyValue(<%- objCName(property) %>); -<% } -%> + auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue<mbgl::style::PropertyValue<<%- valueTransformerArguments(property)[0] %>>>(<%- objCName(property) %>); <% } -%> self.rawLayer->set<%- camelize(originalPropertyName(property)) %>(mbglValue); } -- (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCGetter(property) %> { +- (NSExpression *)<%- objCGetter(property) %> { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->get<%- camelize(originalPropertyName(property)) %>(); -<% if (property["property-function"]) { -%> if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); + propertyValue = self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>(); } - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toDataDrivenStyleValue(propertyValue); -<% } else { -%> -<% if (property.type == "enum") { -%> - if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- mbglType(property) %>, NSValue *, <%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); - } - return MGLStyleValueTransformer<<%- mbglType(property) %>, NSValue *, <%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); -<% } else { -%> - if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(self.rawLayer->getDefault<%- camelize(originalPropertyName(property)) %>()); - } - return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); -<% } -%> -<% } -%> + return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toExpression(propertyValue); } <% if (property["transition"]) { -%> @@ -236,10 +196,10 @@ namespace mbgl { <% } -%> <% if (property.original) { -%> -- (void)set<%- camelize(originalPropertyName(property)) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { +- (void)set<%- camelize(originalPropertyName(property)) %>:(NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { } -- (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { +- (NSExpression *)<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> { return self.<%- objCGetter(property) %>; } <% } -%> diff --git a/platform/darwin/src/MGLStyleValue.h b/platform/darwin/src/MGLStyleValue.h index 9c9b1dc4d1..f6e9c51729 100644 --- a/platform/darwin/src/MGLStyleValue.h +++ b/platform/darwin/src/MGLStyleValue.h @@ -6,485 +6,43 @@ NS_ASSUME_NONNULL_BEGIN -/** - Options for `MGLStyleFunction` objects. - */ -typedef NSString *MGLStyleFunctionOption NS_STRING_ENUM; +typedef NSString *MGLStyleFunctionOption NS_STRING_ENUM NS_UNAVAILABLE; -/** - An `NSNumber` object containing an integer that determines the style function's - exponential interpolation base. - - The exponential interpolation base controls the rate at which the function’s - output values increase. A value of 1 causes the function to increase linearly - based on zoom level or attribute value. A higher exponential interpolation base - causes the function’s output values to vary exponentially, increasing more rapidly - towards the high end of the function’s range. The default value of this property - is 1, for a linear curve. +extern MGL_EXPORT const MGLStyleFunctionOption MGLStyleFunctionOptionInterpolationBase __attribute__((unavailable("Use NSExpression instead, applying the mgl_interpolateWithCurveType:parameters:stops: function with a curve type of “exponential” and a non-nil parameter."))); - This attribute corresponds to the - <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#function-base"><code>base</code></a> - function property in the Mapbox Style Specification. +extern MGL_EXPORT const MGLStyleFunctionOption MGLStyleFunctionOptionDefaultValue __attribute__((unavailable("Use +[NSExpression expressionForConditional:trueExpression:falseExpression:] instead."))); - This option only applies to functions that use an - `MGLInterpolationModeExponential` interpolation mode that are assigned to - interpolatable style layer properties. - */ -extern MGL_EXPORT const MGLStyleFunctionOption MGLStyleFunctionOptionInterpolationBase; - -/** - An `MGLConstantStyleValue` object that specifies a default value that a style - function can use when it can't otherwise determine a value. - - A default value can be used to set the value of a style layer property that - is not otherwise set by a function. For example, a source function with a - `MGLInterpolationModeCategorical` interpolation mode with stops that specify - color values to use based on a feature's attributes would set any feature - that does not have attributes that match the stop key values to this - default value. - - This option only applies to `MGLSourceStyleFunction` and - `MGLCompositeStyleFunction` functions. - */ -extern MGL_EXPORT const MGLStyleFunctionOption MGLStyleFunctionOptionDefaultValue; - -/** - The modes used to interpolate property values between map zoom level changes - or over a range of feature attribute values. - */ typedef NS_ENUM(NSUInteger, MGLInterpolationMode) { - /** - Values between two stops are interpolated linearly, or exponentially based on - the `MGLStyleFunctionOptionInterpolationBase`. A higher interpolation base - causes the function’s output values to vary exponentially, increasing more rapidly - towards the high end of the function’s range. The default interpolation base of 1 - creates a linear interpolation. Use exponential interpolation mode to show values - relative to stop keys. - */ - MGLInterpolationModeExponential = 0, - /** - Values between two stops are not interpolated. Instead, properties are set - to the value of the stop just less than the function input. Use interval - interpolation mode to show values that fall within a range. - */ - MGLInterpolationModeInterval, - /** - Values between two stops are not interpolated. Instead, properties are set - to the value of the stop equal to the function input's key value. Use - categorical interpolation mode to show values that fit into categories. - */ - MGLInterpolationModeCategorical, - /** - Values between two stops are not interpolated. Instead, for any given feature, the - style value matches a value in that feature’s attributes dictionary. Use identity - interpolation mode to show attribute values that can be used as style values. - */ - MGLInterpolationModeIdentity -}; - -/** - An `MGLStyleValue` object is a generic container for a style attribute value. - The layout and paint attribute properties of `MGLStyleLayer` can be set to - `MGLStyleValue` objects. - - The `MGLStyleValue` class itself represents a class cluster. Under the hood, a - particular `MGLStyleValue` object may be either an `MGLConstantStyleValue` to - represent a constant value or one of the concrete subclasses of - `MGLStyleFunction` to represent a value function. Do not initialize an - `MGLStyleValue` object directly; instead, use one of the class factory methods - to create an `MGLStyleValue` object. + MGLInterpolationModeExponential __attribute__((unavailable("Use NSExpression instead, applying the mgl_interpolateWithCurveType:parameters:stops: function with a curve type of “exponential”."))) = 0, + MGLInterpolationModeInterval __attribute__((unavailable("Use NSExpression instead, calling the mgl_stepWithMinimum:stops: function."))), + MGLInterpolationModeCategorical __attribute__((unavailable("Use NSExpression instead."))), + MGLInterpolationModeIdentity __attribute__((unavailable("Use +[NSExpression expressionForKeyPath:] instead."))) +} __attribute__((unavailable("Use NSExpression instead."))); - The `MGLStyleValue` class takes a generic parameter `T` that indicates the - Foundation class being wrapped by this class. Common values for `T` include: - - <ul> - <li><code>NSNumber</code> (for Boolean values and floating-point numbers)</li> - <li><code>NSValue</code> (for <code>CGVector</code>, <code>NSEdgeInsets</code>, <code>UIEdgeInsets</code>, and enumerations)</li> - <li><code>NSString</code></li> - <li><code>NSColor</code> or <code>UIColor</code></li> - <li><code>NSArray</code></li> - </ul> - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use NSExpression instead."))) @interface MGLStyleValue<T> : NSObject - -#pragma mark Creating a Style Value - -/** - Creates and returns an `MGLConstantStyleValue` object containing a raw value. - - @param rawValue The constant value contained by the object. - @return An `MGLConstantStyleValue` object containing `rawValue`, which is - treated as a constant value. - */ -+ (instancetype)valueWithRawValue:(T)rawValue; - -#pragma mark Function values - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a linear camera - function with one or more stops. - - @param stops A dictionary associating zoom levels with style values. - @return An `MGLCameraStyleFunction` object with the given stops. - */ -+ (instancetype)valueWithStops:(NS_DICTIONARY_OF(NSNumber *, MGLStyleValue<T> *) *)stops __attribute__((deprecated("Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:]"))); - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a camera - function with an exponential interpolation base and one or more stops. - - @param interpolationBase The exponential base of the interpolation curve. - @param stops A dictionary associating zoom levels with style values. - @return An `MGLCameraStyleFunction` object with the given interpolation base and stops. - */ -+ (instancetype)valueWithInterpolationBase:(CGFloat)interpolationBase stops:(NS_DICTIONARY_OF(NSNumber *, MGLStyleValue<T> *) *)stops __attribute__((deprecated("Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:]"))); - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a camera function - with one or more stops. - - @param interpolationMode The mode used to interpolate property values between - map zoom level changes. - @param cameraStops A dictionary associating zoom levels with style values. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLCameraStyleFunction` object with the given interpolation mode, - camera stops, and options. - */ -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode cameraStops:(NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *)cameraStops options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - -/** - Creates and returns an `MGLSourceStyleFunction` object representing a source function. - - @param interpolationMode The mode used to interpolate property values over a - range of feature attribute values. - @param sourceStops A dictionary associating feature attributes with style values. - @param attributeName Specifies the feature attribute to take as the function - input. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLSourceStyleFunction` object with the given interpolation mode, - source stops, attribute name, and options. - */ -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode sourceStops:(nullable NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *)sourceStops attributeName:(NSString *)attributeName options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - -/** - Creates and returns an `MGLCompositeStyleFunction` object representing a composite - function. - - @param interpolationMode The mode used to interpolate property values over a - range of feature attribute values for each outer zoom level. - @param compositeStops A dictionary associating feature attributes with style - values. - @param attributeName Specifies the feature attribute to take as the function - input. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLCompositeStyleFunction` object with the given interpolation mode, - composite stops, attribute name, and options. - */ -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode compositeStops:(NS_DICTIONARY_OF(id, NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *) *)compositeStops attributeName:(NSString *)attributeName options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - @end -/** - An `MGLConstantStyleValue` object is a generic container for a style attribute - value that remains constant as the zoom level changes. The layout and paint - attribute properties of `MGLStyleLayer` objects can be set to - `MGLConstantStyleValue` objects. - - The `MGLConstantStyleValue` class takes a generic parameter `T` that indicates - the Foundation class being wrapped by this class. - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use +[NSExpression expressionForConstantValue:] instead."))) @interface MGLConstantStyleValue<T> : MGLStyleValue<T> - -#pragma mark Creating a Style Constant Value - -/** - Creates and returns an `MGLConstantStyleValue` object containing a raw value. - - @param rawValue The constant value contained by the object. - @return An `MGLConstantStyleValue` object containing `rawValue`, which is - treated as a constant value. - */ -+ (instancetype)valueWithRawValue:(T)rawValue; - -#pragma mark Initializing a Style Constant Value - -- (instancetype)init NS_UNAVAILABLE; - -/** - Returns an `MGLConstantStyleValue` object containing a raw value. - - @param rawValue The value contained by the receiver. - @return An `MGLConstantStyleValue` object containing `rawValue`. - */ -- (instancetype)initWithRawValue:(T)rawValue NS_DESIGNATED_INITIALIZER; - -#pragma mark Accessing the Underlying Value - -/** - The raw value contained by the receiver. - */ -@property (nonatomic) T rawValue; - @end @compatibility_alias MGLStyleConstantValue MGLConstantStyleValue; -/** - An `MGLStyleFunction` is a is an abstract superclass for functions that are - defined by an `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, or - `MGLCompositeStyleFunction` object. - - Create instances of `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, and - `MGLCompositeStyleFunction` in order to use `MGLStyleFunction`'s methods. Do - not create instances of `MGLStyleFunction` directly, and do not create your - own subclasses of this class. - - The `MGLStyleFunction` class takes a generic parameter `T` that indicates the - Foundation class being wrapped by this class. - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use NSExpression instead, calling the mgl_stepWithMinimum:stops: or mgl_interpolateWithCurveType:parameters:stops: function."))) @interface MGLStyleFunction<T> : MGLStyleValue<T> - -#pragma mark Creating a Style Function - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a camera - function with a linear interpolation curve. - - @note Do not create function instances using this method unless it is required - for backwards compatiblity with your application code. - - @param stops A dictionary associating zoom levels with style values. - @return An `MGLCameraStyleFunction` object with the given stops. - */ -+ (instancetype)functionWithStops:(NS_DICTIONARY_OF(NSNumber *, MGLStyleValue<T> *) *)stops __attribute__((deprecated("Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:]"))); - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a camera - function with an interpolation curve controlled by the provided interpolation - base. - - @note Do not create function instances using this method unless it is required - for backwards compatiblity with your application code. - - @param interpolationBase The exponential base of the interpolation curve. - @param stops A dictionary associating zoom levels with style values. - @return An `MGLCameraStyleFunction` object with the given interpolation base and stops. - */ -+ (instancetype)functionWithInterpolationBase:(CGFloat)interpolationBase stops:(NS_DICTIONARY_OF(NSNumber *, MGLStyleValue<T> *) *)stops __attribute__((deprecated("Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:]"))); - -#pragma mark Initializing a Style Function - -/** - Returns an `MGLStyleFunction` object representing a camera function. If the - function is set as a style layer property value, it will be interpreted - as a camera function with an interpolation curve controlled by the provided - interpolation base. - - @note Do not create instances of `MGLStyleFunction` unless it is required for - backwards compatiblity with your application code. You should create and use - instances of `MGLCameraStyleFunction` to specify how properties will - be visualized at different zoom levels. - - @param interpolationBase The exponential base of the interpolation curve. - @param stops A dictionary associating zoom levels with style values. - @return An `MGLStyleFunction` object with the given interpolation base and stops. - */ -- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NS_DICTIONARY_OF(NSNumber *, MGLStyleValue<T> *) *)stops __attribute__((deprecated("Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:]"))); - -#pragma mark Accessing the Parameters of a Function - -/** - The modes used to interpolate property values between map zoom level changes or - over a range of feature attribute values. - */ -@property (nonatomic) MGLInterpolationMode interpolationMode; - -/** - A dictionary associating zoom levels with style values. - */ -@property (nonatomic, copy, nullable) NSDictionary *stops; - -/** - The exponential interpolation base of the function’s interpolation curve. - - @note This property specifies the exponential base of the interpolation curve - of `MGLCameraStyleFunction` and `MGLSourceStyleFunction` functions that use - a `MGLInterpolationModeExponential` `interpolationMode`. Otherwise, it is - ignored. - */ -@property (nonatomic) CGFloat interpolationBase; - @end -/** - An `MGLCameraStyleFunction` is a value function defining a style value that changes - as the zoom level changes. The layout and paint attribute properties of an - `MGLStyleLayer` object can be set to `MGLCameraStyleFunction` objects. Use a camera - function to create the illusion of depth and control data density. - - The `MGLCameraStyleFunction` class takes a generic parameter `T` that indicates the - Foundation class being wrapped by this class. - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use NSExpression instead, applying the mgl_stepWithMinimum:stops: or mgl_interpolateWithCurveType:parameters:stops: function to the $zoomLevel variable."))) @interface MGLCameraStyleFunction<T> : MGLStyleFunction<T> - -#pragma mark Creating a Camera Function - -/** - Creates and returns an `MGLCameraStyleFunction` object representing a camera - function with one or more stops. - - @param interpolationMode The mode used to interpolate property values between - map zoom level changes. - @param stops A dictionary associating zoom levels with style values. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLCameraStyleFunction` object with the given interpolation mode, - camera stops, and options. - */ -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *)stops options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - -#pragma mark Accessing the Parameters of a Camera Function - -/** - A dictionary associating zoom levels with style values. - - Each of the function’s stops is represented by one key-value pair in the - dictionary. Each key in the dictionary is an `NSNumber` object containing a - floating-point zoom level. Each value in the dictionary is an `MGLStyleValue` - object containing the value of the style attribute when the map is at the - associated zoom level. An `MGLStyleFunction` object may not be used recursively - as a stop value. - */ -@property (nonatomic, copy) NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *stops; - @end -/** - An `MGLSourceStyleFunction` is a value function defining a style value that - changes with its properties. The layout and paint attribute properties of an - `MGLStyleLayer` object can be set to `MGLSourceStyleFunction` objects. - Use source functions to visually differentate types of features within the same - layer or create data visualizations. - - The `MGLSourceStyleFunction` class takes a generic parameter `T` that indicates the - Foundation class being wrapped by this class. - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use NSExpression instead, applying the mgl_stepWithMinimum:stops: or mgl_interpolateWithCurveType:parameters:stops: function to a key path expression."))) @interface MGLSourceStyleFunction<T> : MGLStyleFunction<T> - -#pragma mark Creating a Source Function - -/** - Creates and returns an `MGLSourceStyleFunction` object representing a source - function. - - @param interpolationMode The mode used to interpolate property values over a - range of feature attribute values. - @param stops A dictionary associating feature attributes with style values. - @param attributeName Specifies the feature attribute to take as the function - input. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLSourceStyleFunction` object with the given interpolation mode, - source stops, attribute name, and options. -*/ -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(nullable NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *)stops attributeName:(NSString *)attributeName options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - -#pragma mark Accessing the Parameters of a Source Function - -/** - A string that specifies the feature attribute key whose value be used as the function - input. -*/ -@property (nonatomic, copy) NSString *attributeName; - -/** - A dictionary associating attribute values with style values. - - Each of the function’s stops is represented by one key-value pair in the - dictionary. Each key in the dictionary is an object representing a feature - attribute key or interpolation stop. Each value in the dictionary is an - `MGLStyleValue` object containing the value to use when the function is given - the associated attribute key. An `MGLStyleFunction` object may not be used - recursively as a stop value. - */ -@property (nonatomic, copy, nullable) NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *stops; - -/** - An `MGLStyleValue` object containing the default value to use when there is - no input to provide to the function. - */ -@property (nonatomic, nullable) MGLStyleValue<T> *defaultValue; - @end -/** - An `MGLCompositeStyleFunction` is a value function defining a style value that - changes with the feature attributes at each map zoom level. The layout and paint - attribute properties of an `MGLStyleLayer` object can be set to - `MGLCompositeStyleFunction` objects. Use composite functions to allow the - appearance of a map feature to change with both its attributes and the map zoom - level. - - The `MGLCompositeStyleFunction` class takes a generic parameter `T` that indicates the - Foundation class being wrapped by this class. - */ -MGL_EXPORT +MGL_EXPORT __attribute__((unavailable("Use a NSExpression instead with nested mgl_stepWithMinimum:stops: or mgl_interpolateWithCurveType:parameters:stops: function calls."))) @interface MGLCompositeStyleFunction<T> : MGLStyleFunction<T> - -#pragma mark Creating a Composite Function - -/** - Creates and returns an `MGLCompositeStyleFunction` object representing a composite - function. - - @param interpolationMode The mode used to interpolate property values over a - range of feature attribute values for each outer zoom level. - @param stops A dictionary associating feature attributes with style values. - @param attributeName Specifies the feature attribute to take as the function - input. - @param options A dictionary containing `MGLStyleFunctionOption` values that - specify how a function is applied. - @return An `MGLCompositeStyleFunction` object with the given interpolation mode, - composite stops, attribute name, and options. - */ -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NS_DICTIONARY_OF(id, NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *) *)stops attributeName:(NSString *)attributeName options:(nullable NS_DICTIONARY_OF(MGLStyleFunctionOption, id) *)options; - -#pragma mark Accessing the Parameters of a Composite Function - -/** - A string that specifies the feature attribute key whose value be used as the function - input. - */ -@property (nonatomic, copy) NSString *attributeName; - -/** - A dictionary associating attribute values with style values. - - Each of the function’s stops is represented by one key-value pair in the - dictionary. Each key in the dictionary is an `NSNumber` object containing a - floating-point zoom level. Each value in the dictionary is an inner nested - dictionary. Each key in the nested dictionary is an object representing a feature - attribute key or interpolation stop. Each value in the nested dictionary is an - `MGLStyleValue` object containing the value to use when the function is given - the associated attribute key. An `MGLStyleFunction` object may not be used - recursively as a value inside the nested dictionary. - */ -@property (nonatomic, copy) NS_DICTIONARY_OF(id, NS_DICTIONARY_OF(id, MGLStyleValue<T> *) *) *stops; - -/** - An `MGLStyleValue` object containing the default value to use when there is - no input to provide to the function. - */ -@property (nonatomic, nullable) MGLStyleValue<T> *defaultValue; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyleValue.mm b/platform/darwin/src/MGLStyleValue.mm index 4dd6b550d8..74e1926f79 100644 --- a/platform/darwin/src/MGLStyleValue.mm +++ b/platform/darwin/src/MGLStyleValue.mm @@ -1,308 +1,121 @@ #import "MGLStyleValue_Private.h" +#include <mbgl/style/expression/expression.hpp> + const MGLStyleFunctionOption MGLStyleFunctionOptionInterpolationBase = @"MGLStyleFunctionOptionInterpolationBase"; const MGLStyleFunctionOption MGLStyleFunctionOptionDefaultValue = @"MGLStyleFunctionOptionDefaultValue"; -@implementation MGLStyleValue - -+ (instancetype)valueWithRawValue:(id)rawValue { - return [MGLConstantStyleValue valueWithRawValue:rawValue]; -} - -+ (instancetype)valueWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential stops:stops options:@{MGLStyleFunctionOptionInterpolationBase: @(interpolationBase)}]; -} - -+ (instancetype)valueWithStops:(NSDictionary *)stops { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential stops:stops options:nil]; -} - -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode cameraStops:(NSDictionary *)cameraStops options:(NSDictionary *)options { - return [MGLCameraStyleFunction functionWithInterpolationMode:interpolationMode stops:cameraStops options:options]; -} - -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode sourceStops:(NSDictionary *)sourceStops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - return [MGLSourceStyleFunction functionWithInterpolationMode:interpolationMode stops:sourceStops attributeName:attributeName options:options]; -} - -+ (instancetype)valueWithInterpolationMode:(MGLInterpolationMode)interpolationMode compositeStops:(NSDictionary *)compositeStops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - return [MGLCompositeStyleFunction functionWithInterpolationMode:interpolationMode stops:compositeStops attributeName:attributeName options:options]; -} - -@end - -@implementation MGLConstantStyleValue - -+ (instancetype)valueWithRawValue:(id)rawValue { - return [[self alloc] initWithRawValue:rawValue]; +id MGLJSONObjectFromMBGLValue(const mbgl::style::expression::Value &value) { + return value.match([](const mbgl::NullValue) -> id { + return [NSNull null]; + }, [](const bool value) { + return @(value); + }, [](const float value) { + return @(value); + }, [](const int64_t value) { + return @(value); + }, [](const double value) { + return @(value); + }, [](const std::string &value) { + return @(value.c_str()); + }, [](const mbgl::Color &value) { + return [MGLColor mgl_colorWithColor:value]; + }, [](const mbgl::style::Position &value) { + std::array<float, 3> spherical = value.getSpherical(); + MGLSphericalPosition position = MGLSphericalPositionMake(spherical[0], spherical[1], spherical[2]); + return [NSValue valueWithMGLSphericalPosition:position]; + }, [&](const std::vector<mbgl::style::expression::Value> &vector) { + NSMutableArray *array = [NSMutableArray arrayWithCapacity:vector.size()]; + for (auto value : vector) { + [array addObject:MGLJSONObjectFromMBGLValue(value)]; + } + return @[@"literal", array]; + }, [&](const std::unordered_map<std::string, mbgl::style::expression::Value> &map) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:map.size()]; + for (auto &item : map) { + dictionary[@(item.first.c_str())] = MGLJSONObjectFromMBGLValue(item.second); + } + return @[@"literal", dictionary]; + }, [](const auto &) -> id { + return nil; + }); } -- (instancetype)initWithRawValue:(id)rawValue { - if (self = [super init]) { - _rawValue = rawValue; +id MGLJSONObjectFromMBGLExpression(const mbgl::style::expression::Expression &mbglExpression) { + using namespace mbgl::style::expression; + if (auto literalExpression = dynamic_cast<const Literal *>(&mbglExpression)) { + auto result = literalExpression->evaluate({ nullptr }); + return result ? MGLJSONObjectFromMBGLValue(*result) : nil; } - return self; -} - -- (NSString *)description { - return [self.rawValue description]; -} - -- (NSString *)debugDescription { - return [self.rawValue debugDescription]; -} - -- (BOOL)isEqual:(MGLConstantStyleValue *)other { - return [other isKindOfClass:[self class]] && [other.rawValue isEqual:self.rawValue]; -} - -- (NSUInteger)hash { - return [self.rawValue hash]; -} - -@end - -@implementation MGLStyleFunction - -+ (instancetype)functionWithStops:(NSDictionary *)stops { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential stops:stops options:nil]; -} - -+ (instancetype)functionWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential stops:stops options:@{MGLStyleFunctionOptionInterpolationBase: @(interpolationBase)}]; -} - -- (instancetype)init { - if (self = [super init]) { - self.interpolationBase = 1.0; - self.stops = @{}; + if (auto assertExpression = dynamic_cast<const ArrayAssertion *>(&mbglExpression)) { + NSMutableArray *inputs = [NSMutableArray array]; + assertExpression->eachChild([&](const Expression &child) { + [inputs addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + return @[@"literal", inputs.lastObject]; } - return self; -} - -- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - if (self = [super init]) { - self.interpolationBase = interpolationBase; - self.stops = stops; + if (auto assertExpression = dynamic_cast<const Assertion *>(&mbglExpression)) { + NSMutableArray *inputs = [NSMutableArray array]; + assertExpression->eachChild([&](const Expression &child) { + [inputs addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + return inputs.firstObject; } - return self; -} - -- (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p, \ - stops = %@, \ - interpolationBase = %f>", - NSStringFromClass([self class]), (void *)self, - self.stops, - self.interpolationBase]; -} - -- (BOOL)isEqual:(MGLStyleFunction *)other { - return ([other isKindOfClass:[self class]] - && [other.stops isEqualToDictionary:self.stops] - && other.interpolationBase == self.interpolationBase); -} - -- (NSUInteger)hash { - return self.stops.hash + @(self.interpolationBase).hash; -} - -@end - -@implementation MGLCameraStyleFunction - -@dynamic stops; - -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops options:(NSDictionary *)options { - return [[self alloc] initWithInterpolationMode:interpolationMode stops:stops options:options]; -} - -- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - return [self initWithInterpolationMode:MGLInterpolationModeExponential stops:stops options:@{MGLStyleFunctionOptionInterpolationBase: @(interpolationBase)}]; -} - -- (instancetype)initWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops options:(NSDictionary *)options { - if (![stops count]) { - [NSException raise:NSInvalidArgumentException - format:@"Camera functions must have at least one stop."]; - return {}; + if (auto compoundExpression = dynamic_cast<const CompoundExpressionBase *>(&mbglExpression)) { + const std::string name = compoundExpression->getName(); + mbgl::optional<std::size_t> parameterCount = compoundExpression->getParameterCount(); + NSMutableArray *expressionObject = parameterCount ? [NSMutableArray arrayWithCapacity:*parameterCount + 1] : [NSMutableArray array]; + [expressionObject addObject:@(name.c_str())]; + compoundExpression->eachChild([&](const Expression &child) { + [expressionObject addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + return expressionObject; } - - if (self = [super init]) { - self.interpolationMode = interpolationMode; - self.stops = stops; - - if ([options.allKeys containsObject:MGLStyleFunctionOptionInterpolationBase]) { - if ([options[MGLStyleFunctionOptionInterpolationBase] isKindOfClass:[NSNumber class]]) { - NSNumber *value = (NSNumber *)options[MGLStyleFunctionOptionInterpolationBase]; - self.interpolationBase = [value floatValue]; - } else { - [NSException raise:NSInvalidArgumentException format:@"Interpolation base must be an NSNumber that represents a CGFloat."]; - } + if (auto stepExpression = dynamic_cast<const Step *>(&mbglExpression)) { + auto &input = stepExpression->getInput(); + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", MGLJSONObjectFromMBGLExpression(*input.get()), nil]; + stepExpression->eachStop([&](double stop, const Expression &child) { + [expressionObject addObject:@(stop)]; + [expressionObject addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + if ([expressionObject[2] isEqual:@(-INFINITY)]) { + [expressionObject removeObjectAtIndex:2]; } + return expressionObject; } - return self; -} - -- (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p, \ - interpolationMode = %lu, \ - stops = %@, \ - interpolationBase = %f>", - NSStringFromClass([self class]), (void *)self, - (unsigned long)self.interpolationMode, - self.stops, - self.interpolationBase]; -} - -- (BOOL)isEqual:(MGLCameraStyleFunction *)other { - return ([other isKindOfClass:[self class]] - && other.interpolationMode == self.interpolationMode - && [other.stops isEqualToDictionary:self.stops] - && other.interpolationBase == self.interpolationBase); -} - -- (NSUInteger)hash { - return @(self.interpolationMode).hash + self.stops.hash + @(self.interpolationBase).hash; -} - -@end - -@implementation MGLSourceStyleFunction - -@dynamic stops; - -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - return [[self alloc] initWithInterpolationMode:interpolationMode stops:stops attributeName:attributeName options:options]; -} - -- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - return [self initWithInterpolationMode:MGLInterpolationModeExponential stops:stops attributeName:@"" options:@{MGLStyleFunctionOptionInterpolationBase: @(interpolationBase)}]; -} - -- (instancetype)initWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - if (self = [super init]) { - self.interpolationMode = interpolationMode; - self.stops = stops; - _attributeName = attributeName; - - if ([options.allKeys containsObject:MGLStyleFunctionOptionDefaultValue]) { - if ([options[MGLStyleFunctionOptionDefaultValue] isKindOfClass:[MGLStyleValue class]]) { - MGLStyleValue *value = (MGLStyleValue *)options[MGLStyleFunctionOptionDefaultValue]; - _defaultValue = value; - } else { - [NSException raise:NSInvalidArgumentException format:@"Default value must be an MGLStyleValue"]; - } - } - - if ([options.allKeys containsObject:MGLStyleFunctionOptionInterpolationBase]) { - if ([options[MGLStyleFunctionOptionInterpolationBase] isKindOfClass:[NSNumber class]]) { - NSNumber *value = (NSNumber *)options[MGLStyleFunctionOptionInterpolationBase]; - self.interpolationBase = [value floatValue]; - } else { - [NSException raise:NSInvalidArgumentException format:@"Interpolation base must be an NSNumber that represents a CGFloat."]; - } + if (auto interpolateExpression = dynamic_cast<const InterpolateBase *>(&mbglExpression)) { + auto &interpolator = interpolateExpression->getInterpolator(); + auto &input = interpolateExpression->getInput(); + NSArray *interpolatorObject; + if (interpolator.is<ExponentialInterpolator>()) { + auto exponentialInterpolator = interpolator.get<ExponentialInterpolator>(); + interpolatorObject = exponentialInterpolator.base == 1 ? @[@"linear"] : @[@"exponential", @(exponentialInterpolator.base)]; + } else if (interpolator.is<CubicBezierInterpolator>()) { + auto cubicBezierInterpolator = interpolator.get<CubicBezierInterpolator>(); + auto bezier = cubicBezierInterpolator.ub; + interpolatorObject = @[ + @"cubic-bezier", + @(bezier.getP1().first), @(bezier.getP1().second), + @(bezier.getP2().first), @(bezier.getP2().second), + ]; + } else { + NSCAssert(NO, @"Unrecognized interpolator type."); } + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"interpolate", interpolatorObject, MGLJSONObjectFromMBGLExpression(*input.get()), nil]; + interpolateExpression->eachStop([&](double stop, const Expression &child) { + [expressionObject addObject:@(stop)]; + [expressionObject addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + return expressionObject; } - return self; -} - -- (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p, \ - interpolationMode = %lu, \ - stops = %@, \ - attributeName = %@, \ - defaultValue = %@, \ - interpolationBase = %f>", - NSStringFromClass([self class]), - (void *)self, - (unsigned long)self.interpolationMode, - self.stops, - self.attributeName, - self.defaultValue, - self.interpolationBase]; -} - -- (BOOL)isEqual:(MGLSourceStyleFunction *)other { - return ([other isKindOfClass:[self class]] - && other.interpolationMode == self.interpolationMode - && ((self.stops && [other.stops isEqualToDictionary:self.stops]) || (!self.stops && !other.stops)) - && [other.attributeName isEqual:self.attributeName] - && ((self.defaultValue && [other.defaultValue isEqual:self.defaultValue]) || (!self.defaultValue && !other.defaultValue)) - && other.interpolationBase == self.interpolationBase); -} - -- (NSUInteger)hash { - return @(self.interpolationMode).hash + self.stops.hash + self.attributeName.hash + self.defaultValue.hash + @(self.interpolationBase).hash; -} - -@end - -@implementation MGLCompositeStyleFunction - -@dynamic stops; - -+ (instancetype)functionWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - return [[self alloc] initWithInterpolationMode:interpolationMode stops:stops attributeName:attributeName options:options]; -} - -- (instancetype)initWithInterpolationBase:(CGFloat)interpolationBase stops:(NSDictionary *)stops { - return [self initWithInterpolationMode:MGLInterpolationModeExponential stops:stops attributeName:@"" options:@{MGLStyleFunctionOptionInterpolationBase: @(interpolationBase)}]; -} - -- (instancetype)initWithInterpolationMode:(MGLInterpolationMode)interpolationMode stops:(NSDictionary *)stops attributeName:(NSString *)attributeName options:(NSDictionary *)options { - if (self = [super init]) { - self.interpolationMode = interpolationMode; - self.stops = stops; - _attributeName = attributeName; - - if ([options.allKeys containsObject:MGLStyleFunctionOptionDefaultValue]) { - if ([options[MGLStyleFunctionOptionDefaultValue] isKindOfClass:[MGLStyleValue class]]) { - MGLStyleValue *value = (MGLStyleValue *)options[MGLStyleFunctionOptionDefaultValue]; - _defaultValue = value; - } else { - [NSException raise:NSInvalidArgumentException format:@"Default value must be an MGLStyleValue"]; - } - } - - if ([options.allKeys containsObject:MGLStyleFunctionOptionInterpolationBase]) { - if ([options[MGLStyleFunctionOptionInterpolationBase] isKindOfClass:[NSNumber class]]) { - NSNumber *value = (NSNumber *)options[MGLStyleFunctionOptionInterpolationBase]; - self.interpolationBase = [value floatValue]; - } else { - [NSException raise:NSInvalidArgumentException format:@"Interpolation base must be an NSNumber that represents a CGFloat."]; - } - } + if (auto caseExpression = dynamic_cast<const Case *>(&mbglExpression)) { + NSMutableArray *expressionObject = [NSMutableArray arrayWithObject:@"case"]; + caseExpression->eachChild([&](const Expression &child) { + [expressionObject addObject:MGLJSONObjectFromMBGLExpression(child)]; + }); + return expressionObject; } - return self; -} - -- (NSString *)description { - return [NSString stringWithFormat:@"<%@: %p, \ - interpolationMode = %lu, \ - stops = %@, \ - attributeName = %@, \ - defaultValue = %@, \ - interpolationBase = %f>", - NSStringFromClass([self class]), (void *)self, - (unsigned long)self.interpolationMode, - self.stops, - self.attributeName, - self.defaultValue, - self.interpolationBase]; -} - -- (BOOL)isEqual:(MGLCompositeStyleFunction *)other { - return ([other isKindOfClass:[self class]] - && other.interpolationMode == self.interpolationMode - && [other.stops isEqualToDictionary:self.stops] - && [other.attributeName isEqual:self.attributeName] - && ((self.defaultValue && [other.defaultValue isEqual:self.defaultValue]) || (!self.defaultValue && !other.defaultValue)) - && other.interpolationBase == self.interpolationBase); -} - -- (NSUInteger)hash { - return @(self.interpolationMode).hash + self.stops.hash + self.attributeName.hash + @(self.interpolationBase).hash; + NSCAssert(NO, @"Unrecognized expression type."); + return nil; } -@end diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 5914e0a2aa..ba4b413a3c 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -4,11 +4,13 @@ #import "NSValue+MGLStyleAttributeAdditions.h" #import "NSValue+MGLAdditions.h" +#import "NSExpression+MGLPrivateAdditions.h" #import "MGLTypes.h" #import "MGLConversion.h" +#include <mbgl/style/conversion/property_value.hpp> #include <mbgl/style/conversion/data_driven_property_value.hpp> -#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/position.hpp> #import <mbgl/style/types.hpp> #import <mbgl/util/enum.hpp> @@ -23,166 +25,68 @@ #import "NSColor+MGLAdditions.h" #endif +namespace mbgl { + namespace style { + namespace expression { + class Expression; + } + } +} + +id MGLJSONObjectFromMBGLExpression(const mbgl::style::expression::Expression &mbglExpression); + template <typename MBGLType, typename ObjCType, typename MBGLElement = MBGLType, typename ObjCEnum = ObjCType> class MGLStyleValueTransformer { public: - - // Convert an mbgl property value into an mgl style value - MGLStyleValue<ObjCType> *toStyleValue(const mbgl::style::PropertyValue<MBGLType> &mbglValue) { - PropertyValueEvaluator evaluator; - return mbglValue.evaluate(evaluator); - } - - // Convert an mbgl data driven property value into an mgl style value - MGLStyleValue<ObjCType> *toDataDrivenStyleValue(const mbgl::style::DataDrivenPropertyValue<MBGLType> &mbglValue) { - PropertyValueEvaluator evaluator; + + /// Convert an mbgl property value into an mgl style value + NSExpression *toExpression(const mbgl::style::PropertyValue<MBGLType> &mbglValue) { + PropertyExpressionEvaluator evaluator; return mbglValue.evaluate(evaluator); } - - // Convert an mbgl property value containing an enum into an mgl style value - template <typename MBGLEnum = MBGLType, - class = typename std::enable_if<std::is_enum<MBGLEnum>::value>::type, - typename MGLEnum = ObjCEnum, - class = typename std::enable_if<std::is_enum<MGLEnum>::value>::type> - MGLStyleValue<ObjCType> *toEnumStyleValue(const mbgl::style::PropertyValue<MBGLEnum> &mbglValue) { - EnumPropertyValueEvaluator<MBGLEnum, ObjCEnum> evaluator; + + /// Convert an mbgl data driven property value into an mgl style value + template <typename MBGLEnum = MBGLType, typename MGLEnum = ObjCEnum> + NSExpression *toExpression(const mbgl::style::DataDrivenPropertyValue<MBGLEnum> &mbglValue) { + PropertyExpressionEvaluator evaluator; return mbglValue.evaluate(evaluator); } - - // Convert an mgl style value into a non interpolatable (camera with interval stops) mbgl property value - mbgl::style::PropertyValue<MBGLType> toPropertyValue(MGLStyleValue<ObjCType> *value) { - if ([value isKindOfClass:[MGLSourceStyleFunction class]] || [value isKindOfClass:[MGLCompositeStyleFunction class]]) { - [NSException raise:NSInvalidArgumentException - format:@"This property can only be set to camera functions. Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:] instead."]; - return {}; - } - - if ([value isKindOfClass:[MGLConstantStyleValue class]]) { - return toMBGLConstantValue((MGLConstantStyleValue<ObjCType> *)value); - } else if ([value isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction<ObjCType> *cameraStyleFunction = (MGLCameraStyleFunction<ObjCType> *)value; - // Intentionally ignore the stop type set by the developer becuase non interpolatable property values - // can only have interval stops. This also allows for backwards compatiblity when the developer uses - // a deprecated MGLStyleValue method (that used to create an MGLStyleFunction) to create a function - // for properties that are piecewise-constant (i.e. enum, bool, string) - return toMBGLIntervalCameraFunction(cameraStyleFunction); - } else if ([value isMemberOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction<ObjCType> *styleFunction = (MGLStyleFunction<ObjCType> *)value; - return toMBGLIntervalCameraFunction(styleFunction); - } else if (value) { - [NSException raise:@"MGLAbstractClassException" format: - @"The style value %@ cannot be applied to the style. " - @"Make sure the style value was created as a member of a concrete subclass of MGLStyleValue.", - NSStringFromClass([value class])]; - return {}; - } else { - return {}; - } - } - - // Convert an mgl style value into a non interpolatable (camera with exponential or interval stops) mbgl property value - mbgl::style::PropertyValue<MBGLType> toInterpolatablePropertyValue(MGLStyleValue<ObjCType> *value) { - if ([value isKindOfClass:[MGLSourceStyleFunction class]] || [value isKindOfClass:[MGLCompositeStyleFunction class]]) { - [NSException raise:NSInvalidArgumentException - format:@"This property can only be set to camera functions. Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:] instead."]; + + /** + Converts an NSExpression to an mbgl property value. + */ + template <typename MBGLValue> + MBGLValue toPropertyValue(NSExpression *expression) { + if (!expression) { return {}; } - - if ([value isKindOfClass:[MGLConstantStyleValue class]]) { - return toMBGLConstantValue((MGLConstantStyleValue<ObjCType> *)value); - } else if ([value isMemberOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction<ObjCType> *styleFunction = (MGLStyleFunction<ObjCType> *)value; - return toMBGLExponentialCameraFunction(styleFunction); - } else if ([value isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction<ObjCType> *cameraStyleFunction = (MGLCameraStyleFunction<ObjCType> *)value; - switch (cameraStyleFunction.interpolationMode) { - case MGLInterpolationModeExponential: - return toMBGLExponentialCameraFunction(cameraStyleFunction); - break; - case MGLInterpolationModeInterval: - return toMBGLIntervalCameraFunction(cameraStyleFunction); - break; - default: - [NSException raise:NSInvalidArgumentException - format:@"A camera function must use either exponential or interval stops."]; - break; - } - return {}; - } else if (value) { - [NSException raise:@"MGLAbstractClassException" format: - @"The style value %@ cannot be applied to the style. " - @"Make sure the style value was created as a member of a concrete subclass of MGLStyleValue.", - NSStringFromClass([value class])]; - return {}; - } else { - return {}; + + if (expression.expressionType == NSConstantValueExpressionType) { + MBGLType mbglValue; + getMBGLValue(expression.constantValue, mbglValue); + return mbglValue; } - } - - // Convert an mgl style value into a mbgl data driven property value - mbgl::style::DataDrivenPropertyValue<MBGLType> toDataDrivenPropertyValue(MGLStyleValue<ObjCType> *value) { - if ([value isKindOfClass:[MGLConstantStyleValue class]]) { - return toMBGLConstantValue((MGLConstantStyleValue<ObjCType> *)value); - } else if ([value isKindOfClass:[MGLStyleFunction class]]) { - mbgl::style::conversion::Error error; - auto result = mbgl::style::conversion::convert<mbgl::style::DataDrivenPropertyValue<MBGLType>>( - mbgl::style::conversion::makeConvertible(toRawStyleSpecValue((MGLStyleFunction<ObjCType> *) value)), error); - NSCAssert(result, @(error.message.c_str())); - return *result; - } else { - return {}; + if (expression.expressionType == NSAggregateExpressionType) { + MBGLType mbglValue; + getMBGLValue(expression.collection, mbglValue); + return mbglValue; } - } - - // Convert an mgl style value containing an enum into a mbgl property value containing an enum - template <typename MBGLEnum = MBGLType, - class = typename std::enable_if<std::is_enum<MBGLEnum>::value>::type, - typename MGLEnum = ObjCEnum, - class = typename std::enable_if<std::is_enum<MGLEnum>::value>::type> - mbgl::style::PropertyValue<MBGLEnum> toEnumPropertyValue(MGLStyleValue<ObjCType> *value) { - if ([value isKindOfClass:[MGLSourceStyleFunction class]] || [value isKindOfClass:[MGLCompositeStyleFunction class]]) { + + NSArray *jsonExpression = expression.mgl_jsonExpressionObject; + + mbgl::style::conversion::Error valueError; + auto value = mbgl::style::conversion::convert<MBGLValue>( + mbgl::style::conversion::makeConvertible(jsonExpression), valueError); + if (!value) { [NSException raise:NSInvalidArgumentException - format:@"This property can only be set to camera functions. Use +[MGLStyleValue valueWithInterpolationMode:cameraStops:options:] instead."]; - return {}; - } - - if ([value isKindOfClass:[MGLConstantStyleValue class]]) { - MBGLEnum mbglValue; - getMBGLValue([(MGLConstantStyleValue<ObjCType> *)value rawValue], mbglValue); - return mbglValue; - } else if ([value isKindOfClass:[MGLCameraStyleFunction class]]) { - MGLCameraStyleFunction<NSValue *> *cameraStyleFunction = (MGLCameraStyleFunction<NSValue *> *)value; - __block std::map<float, MBGLType> stops = {}; - [cameraStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) { - NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); - auto mbglStopValue = toEnumPropertyValue(stopValue); - NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); - stops[zoomKey.floatValue] = mbglStopValue.asConstant(); - }]; - - // Enumerations can only ever use interval stops. - mbgl::style::IntervalStops<MBGLType> intervalStops = {stops}; - - mbgl::style::CameraFunction<MBGLType> cameraFunction = {intervalStops}; - return cameraFunction; - } else if (value) { - [NSException raise:@"MGLAbstractClassException" format: - @"The style value %@ cannot be applied to the style. " - @"Make sure the style value was created as a member of a concrete subclass of MGLStyleValue.", - NSStringFromClass([value class])]; - return {}; - } else { + format:@"Invalid property value: %@", @(valueError.message.c_str())]; return {}; } + + return *value; } private: // Private utilities for converting from mgl to mbgl values - - MBGLType toMBGLConstantValue(MGLConstantStyleValue<ObjCType> *value) { - MBGLType mbglValue; - getMBGLValue(value.rawValue, mbglValue); - return mbglValue; - } /** As hack to allow converting enum => string values, we accept a second, dummy parameter in @@ -220,164 +124,6 @@ private: // Private utilities for converting from mgl to mbgl values return @(color.mgl_color.stringify().c_str()); } - - NSObject* toRawStyleSpecValue(MGLStyleFunction<ObjCType>* styleFunction) { - NSMutableDictionary * rawFunction = [NSMutableDictionary new]; - // interpolationMode => type - switch (styleFunction.interpolationMode) { - case MGLInterpolationModeExponential: - rawFunction[@"type"] = @"exponential"; - break; - case MGLInterpolationModeInterval: - rawFunction[@"type"] = @"interval"; - break; - case MGLInterpolationModeCategorical: - rawFunction[@"type"] = @"categorical"; - break; - case MGLInterpolationModeIdentity: - rawFunction[@"type"] = @"identity"; - break; - } - - // interpolationBase => base - if (styleFunction.interpolationBase) { - rawFunction[@"base"] = @(styleFunction.interpolationBase); - } - - // stops and default value - if ([styleFunction isKindOfClass:[MGLCameraStyleFunction class]]) { - // zoom-only function (no default value) - __block NSMutableArray *stops = [[NSMutableArray alloc] init]; - [styleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLConstantStyleValue<ObjCType> * _Nonnull outputValue, BOOL * _Nonnull stop) { - MBGLType dummyMbglValue; - NSArray *rawStop = @[zoomKey, toRawStyleSpecValue([outputValue rawValue], dummyMbglValue)]; - [stops addObject:rawStop]; - }]; - rawFunction[@"stops"] = stops; - - } else if ([styleFunction isKindOfClass:[MGLSourceStyleFunction class]]) { - auto sourceStyleFunction = (MGLSourceStyleFunction<ObjCType> *)styleFunction; - rawFunction[@"property"] = sourceStyleFunction.attributeName; - // property-only function - __block NSMutableArray *stops = [[NSMutableArray alloc] init]; - [styleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSObject * _Nonnull propertyKey, MGLConstantStyleValue<ObjCType> * _Nonnull outputValue, BOOL * _Nonnull stop) { - MBGLType dummyMbglValue; - NSArray *rawStop = @[propertyKey, toRawStyleSpecValue([outputValue rawValue], dummyMbglValue)]; - [stops addObject:rawStop]; - }]; - rawFunction[@"stops"] = stops; - - // defaultValue => default - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLConstantStyleValue class]], @"Default value must be constant"); - MBGLType dummyMbglValue; - rawFunction[@"default"] = toRawStyleSpecValue([(MGLConstantStyleValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue], dummyMbglValue); - } - } else if ([styleFunction isKindOfClass:[MGLCompositeStyleFunction class]]) { - // zoom-and-property function - auto compositeStyleFunction = (MGLCompositeStyleFunction<ObjCType> *)styleFunction; - rawFunction[@"property"] = compositeStyleFunction.attributeName; - - __block NSMutableArray *stops = [[NSMutableArray alloc] init]; - [compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) { - for (NSObject *valueKey in stopValue.allKeys) { - NSDictionary *stopKey = @{ - @"zoom": zoomKey, - @"value": valueKey - }; - MGLConstantStyleValue<ObjCType> *outputValue = stopValue[valueKey]; - NSCAssert([outputValue isKindOfClass:[MGLConstantStyleValue<ObjCType> class]], @"Stop outputs should be MGLConstantStyleValues"); - MBGLType dummyMbglValue; - NSArray *rawStop = @[stopKey, toRawStyleSpecValue([outputValue rawValue], dummyMbglValue)]; - [stops addObject:rawStop]; - } - }]; - rawFunction[@"stops"] = stops; - - // defaultValue => default - if (compositeStyleFunction.defaultValue) { - NSCAssert([compositeStyleFunction.defaultValue isKindOfClass:[MGLConstantStyleValue class]], @"Default value must be constant"); - MBGLType dummyMbglValue; - rawFunction[@"default"] = toRawStyleSpecValue([(MGLConstantStyleValue<ObjCType> *)compositeStyleFunction.defaultValue rawValue], dummyMbglValue); - } - } - - return rawFunction; - } - - mbgl::style::CameraFunction<MBGLType> toMBGLExponentialCameraFunction(MGLStyleFunction<ObjCType> *styleFunction) { - __block std::map<float, MBGLType> stops = {}; - [styleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<ObjCType> * _Nonnull stopValue, BOOL * _Nonnull stop) { - NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); - auto mbglStopValue = toPropertyValue(stopValue); - NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); - stops[zoomKey.floatValue] = mbglStopValue.asConstant(); - }]; - - // Camera function with Exponential stops - mbgl::style::ExponentialStops<MBGLType> exponentialStops = {stops, (float)styleFunction.interpolationBase}; - mbgl::style::CameraFunction<MBGLType> cameraFunction = {exponentialStops}; - - return cameraFunction; - } - - mbgl::style::CameraFunction<MBGLType> toMBGLIntervalCameraFunction(MGLStyleFunction<ObjCType> *styleFunction) { - __block std::map<float, MBGLType> stops = {}; - [styleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<ObjCType> * _Nonnull stopValue, BOOL * _Nonnull stop) { - NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); - auto mbglStopValue = toPropertyValue(stopValue); - NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); - stops[zoomKey.floatValue] = mbglStopValue.asConstant(); - }]; - - // Camera function with Interval stops - mbgl::style::IntervalStops<MBGLType> intervalStops = {stops}; - mbgl::style::CameraFunction<MBGLType> cameraFunction = {intervalStops}; - - return cameraFunction; - } - - mbgl::style::SourceFunction<MBGLType> toMBGLCategoricalSourceFunction(MGLSourceStyleFunction<ObjCType> *sourceStyleFunction) { - __block std::map<mbgl::style::CategoricalValue, MBGLType> stops = {}; - [sourceStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(id categoryKey, MGLStyleValue<ObjCType> *stopValue, BOOL *stop) { - NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); - auto mbglStopValue = toPropertyValue(stopValue); - NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); - - if ([categoryKey isKindOfClass:[NSString class]]) { - const std::string& convertedValueKey = [((NSString *)categoryKey) UTF8String]; - stops[mbgl::style::CategoricalValue(convertedValueKey)] = mbglStopValue.asConstant(); - } else if ([categoryKey isKindOfClass:[NSNumber class]]) { - NSNumber *key = (NSNumber *)categoryKey; - if ((strcmp([key objCType], @encode(char)) == 0) || - (strcmp([key objCType], @encode(BOOL)) == 0)) { - stops[mbgl::style::CategoricalValue((bool)[key boolValue])] = mbglStopValue.asConstant(); - } else if (strcmp([key objCType], @encode(double)) == 0 || - strcmp([key objCType], @encode(float)) == 0) { - NSCAssert(mbglStopValue.isConstant(), @"Categorical stop keys must be strings, booleans, or integers"); - } else if ([key compare:@(0)] == NSOrderedDescending || - [key compare:@(0)] == NSOrderedSame || - [key compare:@(0)] == NSOrderedAscending) { - stops[mbgl::style::CategoricalValue((int64_t)[key integerValue])] = mbglStopValue.asConstant(); - } - } - }]; - mbgl::style::CategoricalStops<MBGLType> categoricalStops = {stops}; - mbgl::style::SourceFunction<MBGLType> sourceFunction = {sourceStyleFunction.attributeName.UTF8String, categoricalStops}; - setDefaultMBGLValue(sourceStyleFunction, sourceFunction); - return sourceFunction; - } - - void setDefaultMBGLValue(MGLSourceStyleFunction<ObjCType> *sourceStyleFunction, mbgl::style::SourceFunction<MBGLType> &sourceFunction) { - if (sourceStyleFunction.defaultValue) { - NSCAssert([sourceStyleFunction.defaultValue isKindOfClass:[MGLConstantStyleValue class]], @"Default value must be constant"); - MBGLType mbglValue; - id mglValue = [(MGLConstantStyleValue<ObjCType> *)sourceStyleFunction.defaultValue rawValue]; - getMBGLValue(mglValue, mbglValue); - sourceFunction.defaultValue = mbglValue; - } - } - // Bool void getMBGLValue(NSNumber *rawValue, bool &mbglValue) { mbglValue = !!rawValue.boolValue; @@ -394,13 +140,28 @@ private: // Private utilities for converting from mgl to mbgl values } // Offsets - void getMBGLValue(NSValue *rawValue, std::array<float, 2> &mbglValue) { - mbglValue = rawValue.mgl_offsetArrayValue; + void getMBGLValue(id rawValue, std::array<float, 2> &mbglValue) { + if ([rawValue isKindOfClass:[NSValue class]]) { + mbglValue = [rawValue mgl_offsetArrayValue]; + } else if ([rawValue isKindOfClass:[NSArray class]]) { + NSArray *array = (NSArray *)rawValue; + getMBGLValue(array[0], mbglValue[0]); + getMBGLValue(array[1], mbglValue[1]); + } } // Padding - void getMBGLValue(NSValue *rawValue, std::array<float, 4> &mbglValue) { - mbglValue = rawValue.mgl_paddingArrayValue; + void getMBGLValue(id rawValue, std::array<float, 4> &mbglValue) { + if ([rawValue isKindOfClass:[NSValue class]]) { + mbglValue = [rawValue mgl_paddingArrayValue]; + } else if ([rawValue isKindOfClass:[NSArray class]]) { + NSArray *array = (NSArray *)rawValue; + getMBGLValue(array[0], mbglValue[0]); + getMBGLValue(array[1], mbglValue[1]); + getMBGLValue(array[2], mbglValue[2]); + getMBGLValue(array[3], mbglValue[3]); + getMBGLValue(array[4], mbglValue[4]); + } } // Color @@ -412,8 +173,12 @@ private: // Private utilities for converting from mgl to mbgl values void getMBGLValue(ObjCType rawValue, std::vector<MBGLElement> &mbglValue) { mbglValue.reserve(rawValue.count); for (id obj in rawValue) { + id constantObject = obj; + if ([obj isKindOfClass:[NSExpression class]] && [obj expressionType] == NSConstantValueExpressionType) { + constantObject = [constantObject constantValue]; + } MBGLElement mbglElement; - getMBGLValue(obj, mbglElement); + getMBGLValue(constantObject, mbglElement); mbglValue.push_back(mbglElement); } } @@ -429,11 +194,15 @@ private: // Private utilities for converting from mgl to mbgl values class = typename std::enable_if<std::is_enum<MBGLEnum>::value>::type, typename MGLEnum = ObjCEnum, class = typename std::enable_if<std::is_enum<MGLEnum>::value>::type> - void getMBGLValue(ObjCType rawValue, MBGLEnum &mbglValue) { - MGLEnum mglEnum; - [rawValue getValue:&mglEnum]; - auto str = mbgl::Enum<MGLEnum>::toString(mglEnum); - mbglValue = *mbgl::Enum<MBGLEnum>::toEnum(str); + void getMBGLValue(id rawValue, MBGLEnum &mbglValue) { + if ([rawValue isKindOfClass:[NSString class]]) { + mbglValue = *mbgl::Enum<MBGLEnum>::toEnum([(NSString *)rawValue UTF8String]); + } else { + MGLEnum mglEnum; + [(NSValue *)rawValue getValue:&mglEnum]; + auto str = mbgl::Enum<MGLEnum>::toString(mglEnum); + mbglValue = *mbgl::Enum<MBGLEnum>::toEnum(str); + } } private: // Private utilities for converting from mbgl to mgl values @@ -477,7 +246,7 @@ private: // Private utilities for converting from mbgl to mgl values static ObjCType toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) { NSMutableArray *array = [NSMutableArray arrayWithCapacity:mbglStopValue.size()]; for (const auto &mbglElement: mbglStopValue) { - [array addObject:toMGLRawStyleValue(mbglElement)]; + [array addObject:[NSExpression expressionForConstantValue:toMGLRawStyleValue(mbglElement)]]; } return array; } @@ -496,212 +265,49 @@ private: // Private utilities for converting from mbgl to mgl values return [NSValue value:&mglType withObjCType:@encode(MGLEnum)]; } - // Converts mbgl stops to an equivilent NSDictionary for mgl - static NSMutableDictionary *toConvertedStops(const std::map<float, MBGLType> &mbglStops) { - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()]; - for (const auto &mbglStop : mbglStops) { - auto rawValue = toMGLRawStyleValue(mbglStop.second); - stops[@(mbglStop.first)] = [MGLStyleValue valueWithRawValue:rawValue]; - } - return stops; - } - - // Converts mbgl interval stop categorical values to an equivilant object for mgl - class CategoricalValueVisitor { - public: - id operator()(const bool value) { - return toMGLRawStyleValue(value); - } - - id operator()(const int64_t value) { - return toMGLRawStyleValue(value); - } - - id operator()(const std::string value) { - return toMGLRawStyleValue(value); - } - }; - - // Converts all types of mbgl property values containing enumerations into an equivilant mgl style value - template <typename MBGLEnum = MBGLType, typename MGLEnum = ObjCEnum> - class EnumPropertyValueEvaluator { + /// Converts all types of mbgl property values into an equivalent NSExpression. + class PropertyExpressionEvaluator { public: - id operator()(const mbgl::style::Undefined) const { + NSExpression *operator()(const mbgl::style::Undefined) const { return nil; } - id operator()(const MBGLEnum &value) const { - auto str = mbgl::Enum<MBGLEnum>::toString(value); - MGLEnum mglType = *mbgl::Enum<MGLEnum>::toEnum(str); - return [MGLConstantStyleValue<ObjCType> valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(MGLEnum)]]; - } - - id operator()(const mbgl::style::CameraFunction<MBGLEnum> &mbglValue) const { - CameraFunctionStopsVisitor visitor; - return apply_visitor(visitor, mbglValue.stops); - } - }; - - // Converts all possible mbgl camera function stops into an equivilant mgl style value - class CameraFunctionStopsVisitor { - public: - id operator()(const mbgl::style::ExponentialStops<MBGLType> &mbglStops) { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential - stops:toConvertedStops(mbglStops.stops) - options:@{MGLStyleFunctionOptionInterpolationBase: @(mbglStops.base)}]; - } - - id operator()(const mbgl::style::IntervalStops<MBGLType> &mbglStops) { - return [MGLCameraStyleFunction functionWithInterpolationMode:MGLInterpolationModeInterval - stops:toConvertedStops(mbglStops.stops) - options:nil]; - } - }; - - // Converts a source function and all possible mbgl source function stops into an equivilant mgl style value - class SourceFunctionStopsVisitor { - public: - id operator()(const mbgl::style::ExponentialStops<MBGLType> &mbglStops) { - MGLSourceStyleFunction *sourceFunction = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential - stops:toConvertedStops(mbglStops.stops) - attributeName:@(mbglFunction.property.c_str()) - options:@{MGLStyleFunctionOptionInterpolationBase: @(mbglStops.base)}]; - if (mbglFunction.defaultValue) { - sourceFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; + /** + As hack to allow converting enum => string values, we accept a second, dummy parameter in + the toRawStyleSpecValue() methods for converting 'atomic' (non-style-function) values. + This allows us to use `std::enable_if` to test (at compile time) whether or not MBGLType is an Enum. + */ + template <typename MBGLEnum = MBGLType, + class = typename std::enable_if<!std::is_enum<MBGLEnum>::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if<!std::is_enum<MGLEnum>::value>::type> + NSExpression *operator()(const MBGLType &value) const { + id constantValue = toMGLRawStyleValue(value); + if ([constantValue isKindOfClass:[NSArray class]]) { + return [NSExpression expressionForAggregate:constantValue]; } - return sourceFunction; + return [NSExpression expressionForConstantValue:constantValue]; } - - id operator()(const mbgl::style::IntervalStops<MBGLType> &mbglStops) { - MGLSourceStyleFunction *sourceFunction = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeInterval - stops:toConvertedStops(mbglStops.stops) - attributeName:@(mbglFunction.property.c_str()) - options:nil]; - if (mbglFunction.defaultValue) { - sourceFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return sourceFunction; - } - - id operator()(const mbgl::style::CategoricalStops<MBGLType> &mbglStops) { - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()]; - for (const auto &mbglStop : mbglStops.stops) { - auto categoricalValue = mbglStop.first; - auto rawValue = toMGLRawStyleValue(mbglStop.second); - CategoricalValueVisitor categoricalValueVisitor; - id stopKey = apply_visitor(categoricalValueVisitor, categoricalValue); - stops[stopKey] = [MGLStyleValue valueWithRawValue:rawValue]; - } - - MGLSourceStyleFunction *sourceFunction = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeCategorical - stops:stops - attributeName:@(mbglFunction.property.c_str()) - options:nil]; - if (mbglFunction.defaultValue) { - sourceFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return sourceFunction; - - } - - id operator()(const mbgl::style::IdentityStops<MBGLType> &mbglStops) { - MGLSourceStyleFunction *sourceFunction = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeIdentity - stops:nil - attributeName:@(mbglFunction.property.c_str()) options:nil]; - if (mbglFunction.defaultValue) { - sourceFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return sourceFunction; - } - - const mbgl::style::SourceFunction<MBGLType> &mbglFunction; - }; - - // Converts a composite function and all possible mbgl stops into an equivilant mgl style value - class CompositeFunctionStopsVisitor { - public: - id operator()(const mbgl::style::CompositeExponentialStops<MBGLType> &mbglStops) { - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()]; - for (auto const& outerStop: mbglStops.stops) { - stops[@(outerStop.first)] = toConvertedStops(outerStop.second); - } - MGLCompositeStyleFunction *compositeFunction = [MGLCompositeStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential - stops:stops - attributeName:@(mbglFunction.property.c_str()) - options:@{MGLStyleFunctionOptionInterpolationBase: @(mbglStops.base)}]; - if (mbglFunction.defaultValue) { - compositeFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return compositeFunction; - } - - id operator()(const mbgl::style::CompositeIntervalStops<MBGLType> &mbglStops) { - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()]; - for (auto const& outerStop: mbglStops.stops) { - stops[@(outerStop.first)] = toConvertedStops(outerStop.second); - } - MGLCompositeStyleFunction *compositeFunction = [MGLCompositeStyleFunction functionWithInterpolationMode:MGLInterpolationModeInterval - stops:stops - attributeName:@(mbglFunction.property.c_str()) - options:nil]; - if (mbglFunction.defaultValue) { - compositeFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return compositeFunction; - } - - id operator()(const mbgl::style::CompositeCategoricalStops<MBGLType> &mbglStops) { - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()]; - for (auto const& outerStop: mbglStops.stops) { - NSMutableDictionary *innerStops = [NSMutableDictionary dictionaryWithCapacity:outerStop.second.size()]; - for (const auto &mbglStop : outerStop.second) { - auto categoricalValue = mbglStop.first; - auto rawValue = toMGLRawStyleValue(mbglStop.second); - CategoricalValueVisitor categoricalValueVisitor; - id stopKey = apply_visitor(categoricalValueVisitor, categoricalValue); - innerStops[stopKey] = [MGLStyleValue valueWithRawValue:rawValue]; - } - stops[@(outerStop.first)] = innerStops; - } - - MGLCompositeStyleFunction *compositeFunction = [MGLCompositeStyleFunction functionWithInterpolationMode:MGLInterpolationModeCategorical - stops:stops attributeName:@(mbglFunction.property.c_str()) - options:nil]; - if (mbglFunction.defaultValue) { - compositeFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)]; - } - return compositeFunction; - } - - const mbgl::style::CompositeFunction<MBGLType> &mbglFunction; - }; - - - // Converts all types of mbgl property values that don't contain enumerations into an equivilant mgl style value - class PropertyValueEvaluator { - public: - id operator()(const mbgl::style::Undefined) const { - return nil; - } - - id operator()(const MBGLType &value) const { - auto rawValue = toMGLRawStyleValue(value); - return [MGLConstantStyleValue<ObjCType> valueWithRawValue:rawValue]; + + template <typename MBGLEnum = MBGLType, + class = typename std::enable_if<std::is_enum<MBGLEnum>::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if<std::is_enum<MGLEnum>::value>::type> + NSExpression *operator()(const MBGLEnum &value) const { + NSString *constantValue = @(mbgl::Enum<MBGLEnum>::toString(value)); + return [NSExpression expressionForConstantValue:constantValue]; } - id operator()(const mbgl::style::CameraFunction<MBGLType> &mbglValue) const { - CameraFunctionStopsVisitor visitor; - return apply_visitor(visitor, mbglValue.stops); + NSExpression *operator()(const mbgl::style::CameraFunction<MBGLType> &mbglValue) const { + return [NSExpression mgl_expressionWithJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; } - id operator()(const mbgl::style::SourceFunction<MBGLType> &mbglValue) const { - SourceFunctionStopsVisitor visitor { mbglValue }; - return apply_visitor(visitor, mbglValue.stops); + NSExpression *operator()(const mbgl::style::SourceFunction<MBGLType> &mbglValue) const { + return [NSExpression mgl_expressionWithJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; } - MGLCompositeStyleFunction<ObjCType> * operator()(const mbgl::style::CompositeFunction<MBGLType> &mbglValue) const { - CompositeFunctionStopsVisitor visitor { mbglValue }; - return apply_visitor(visitor, mbglValue.stops); + NSExpression *operator()(const mbgl::style::CompositeFunction<MBGLType> &mbglValue) const { + return [NSExpression mgl_expressionWithJSONObject:MGLJSONObjectFromMBGLExpression(mbglValue.getExpression())]; } }; }; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index 84d32cd0b1..1017db5442 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -2,7 +2,6 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLFoundation.h" -#import "MGLStyleValue.h" #import "MGLVectorStyleLayer.h" NS_ASSUME_NONNULL_BEGIN @@ -335,12 +334,12 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) { ```swift let layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois) layer.sourceLayerIdentifier = "pois" - layer.iconImageName = MGLStyleValue(rawValue: "coffee") - layer.iconScale = MGLStyleValue(rawValue: 0.5) - layer.text = MGLStyleValue(rawValue: "{name}") - layer.textTranslation = MGLStyleValue(rawValue: NSValue(cgVector: CGVector(dx: 10, dy: 0))) - layer.textJustification = MGLStyleValue(rawValue: NSValue(mglTextJustification: .left)) - layer.textAnchor = MGLStyleValue(rawValue: NSValue(mglTextAnchor: .left)) + layer.iconImageName = NSExpression(forConstantValue: "coffee") + layer.iconScale = NSExpression(forConstantValue: 0.5) + layer.text = NSExpression(forKeyPath: "name") + layer.textTranslation = NSExpression(forConstantValue: NSValue(cgVector: CGVector(dx: 10, dy: 0))) + layer.textJustification = NSExpression(forConstantValue: "left") + layer.textAnchor = NSExpression(forConstantValue: "left") layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee") mapView.style?.addLayer(layer) ``` @@ -369,9 +368,8 @@ MGL_EXPORT If true, the icon will be visible even if it collides with other previously drawn symbols. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -380,51 +378,62 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-allow-overlap"><code>icon-allow-overlap</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconAllowsOverlap; +@property (nonatomic, null_resettable) NSExpression *iconAllowsOverlap; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconAllowOverlap __attribute__((unavailable("Use iconAllowsOverlap instead."))); +@property (nonatomic, null_resettable) NSExpression *iconAllowOverlap __attribute__((unavailable("Use iconAllowsOverlap instead."))); /** Part of the icon placed closest to the anchor. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconAnchorCenter`. Set this property to `nil` - to reset it to the default value. + The default value of this property is an expression that evaluates to `center`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconAnchor; + You can set this property to an expression containing any of the following: + + * Constant `MGLIconAnchor` values + * Any of the following constant string values: + * `center`: The center of the icon is placed closest to the anchor. + * `left`: The left side of the icon is placed closest to the anchor. + * `right`: The right side of the icon is placed closest to the anchor. + * `top`: The top of the icon is placed closest to the anchor. + * `bottom`: The bottom of the icon is placed closest to the anchor. + * `top-left`: The top left corner of the icon is placed closest to the + anchor. + * `top-right`: The top right corner of the icon is placed closest to the + anchor. + * `bottom-left`: The bottom left corner of the icon is placed closest to the + anchor. + * `bottom-right`: The bottom right corner of the icon is placed closest to + the anchor. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *iconAnchor; /** If true, other symbols can be visible even if they collide with the icon. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -433,16 +442,22 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-ignore-placement"><code>icon-ignore-placement</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconIgnoresPlacement; +@property (nonatomic, null_resettable) NSExpression *iconIgnoresPlacement; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconIgnorePlacement __attribute__((unavailable("Use iconIgnoresPlacement instead."))); +@property (nonatomic, null_resettable) NSExpression *iconIgnorePlacement __attribute__((unavailable("Use iconIgnoresPlacement instead."))); /** Name of image in sprite to use for drawing an image background. Within literal @@ -455,103 +470,87 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-image"><code>icon-image</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *iconImageName; +@property (nonatomic, null_resettable) NSExpression *iconImageName; -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *iconImage __attribute__((unavailable("Use iconImageName instead."))); +@property (nonatomic, null_resettable) NSExpression *iconImage __attribute__((unavailable("Use iconImageName instead."))); #if TARGET_OS_IPHONE /** Offset distance of icon from its anchor. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 rightward and 0 downward. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconOffset; + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *iconOffset; #else /** Offset distance of icon from its anchor. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 rightward and 0 upward. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconOffset; + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *iconOffset; #endif /** If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable, getter=isIconOptional) MGLStyleValue<NSNumber *> *iconOptional; +@property (nonatomic, null_resettable, getter=isIconOptional) NSExpression *iconOptional; /** Size of the additional area around the icon bounding box used for detecting @@ -559,48 +558,59 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `2`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconPadding; +@property (nonatomic, null_resettable) NSExpression *iconPadding; /** Orientation of icon when map is pitched. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconPitchAlignmentAuto`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `auto`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLIconPitchAlignment` values + * Any of the following constant string values: + * `map`: The icon is aligned to the plane of the map. + * `viewport`: The icon is aligned to the plane of the viewport. + * `auto`: Automatically matches the value of `icon-rotation-alignment`. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconPitchAlignment; +@property (nonatomic, null_resettable) NSExpression *iconPitchAlignment; /** Rotates the icon clockwise. This property is measured in degrees. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -609,45 +619,51 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-rotate"><code>icon-rotate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconRotation; +@property (nonatomic, null_resettable) NSExpression *iconRotation; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconRotate __attribute__((unavailable("Use iconRotation instead."))); +@property (nonatomic, null_resettable) NSExpression *iconRotate __attribute__((unavailable("Use iconRotation instead."))); /** In combination with `symbolPlacement`, determines the rotation behavior of icons. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconRotationAlignmentAuto`. Set this property - to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `auto`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLIconRotationAlignment` values + * Any of the following constant string values: + * `map`: When `symbol-placement` is set to `point`, aligns icons east-west. + When `symbol-placement` is set to `line`, aligns icon x-axes with the line. + * `viewport`: Produces icons whose x-axes are aligned with the x-axis of the + viewport, regardless of the value of `symbol-placement`. + * `auto`: When `symbol-placement` is set to `point`, this is equivalent to + `viewport`. When `symbol-placement` is set to `line`, this is equivalent to + `map`. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconRotationAlignment; +@property (nonatomic, null_resettable) NSExpression *iconRotationAlignment; /** Scales the original size of the icon by the provided factor. The new point size @@ -656,9 +672,8 @@ MGL_EXPORT This property is measured in factor of the original icon sizes. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -667,44 +682,49 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-size"><code>icon-size</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconScale; +@property (nonatomic, null_resettable) NSExpression *iconScale; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconSize __attribute__((unavailable("Use iconScale instead."))); +@property (nonatomic, null_resettable) NSExpression *iconSize __attribute__((unavailable("Use iconScale instead."))); /** Scales the icon to fit around the associated text. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconTextFitNone`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to `none`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant `MGLIconTextFit` values + * Any of the following constant string values: + * `none`: The icon is displayed at its intrinsic aspect ratio. + * `width`: The icon is scaled in the x-dimension to fit the width of the + text. + * `height`: The icon is scaled in the y-dimension to fit the height of the + text. + * `both`: The icon is scaled in both x- and y-dimensions. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFit; +@property (nonatomic, null_resettable) NSExpression *iconTextFit; #if TARGET_OS_IPHONE /** @@ -712,142 +732,160 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing `UIEdgeInsetsZero`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and - `text` is non-`nil`, and `iconTextFit` is set to an `MGLStyleValue` object - containing an `NSValue` object containing `MGLIconTextFitBoth`, - `MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. Otherwise, it is ignored. + `text` is non-`nil`, and `iconTextFit` is set to an expression that evaluates + to `MGLIconTextFitBoth`, `MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. + Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `UIEdgeInsets` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFitPadding; +@property (nonatomic, null_resettable) NSExpression *iconTextFitPadding; #else /** Size of the additional area added to dimensions determined by `iconTextFit`. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing `NSEdgeInsetsZero`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and - `text` is non-`nil`, and `iconTextFit` is set to an `MGLStyleValue` object - containing an `NSValue` object containing `MGLIconTextFitBoth`, - `MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. Otherwise, it is ignored. + `text` is non-`nil`, and `iconTextFit` is set to an expression that evaluates + to `MGLIconTextFitBoth`, `MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. + Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `NSEdgeInsets` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFitPadding; +@property (nonatomic, null_resettable) NSExpression *iconTextFitPadding; #endif /** If true, the icon may be flipped to prevent it from being rendered upside-down. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and - `iconRotationAlignment` is set to an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconRotationAlignmentMap`, and - `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` - object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. + `iconRotationAlignment` is set to an expression that evaluates to `map`, and + `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, + it is ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-icon-keep-upright"><code>icon-keep-upright</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *keepsIconUpright; +@property (nonatomic, null_resettable) NSExpression *keepsIconUpright; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconKeepUpright __attribute__((unavailable("Use keepsIconUpright instead."))); +@property (nonatomic, null_resettable) NSExpression *iconKeepUpright __attribute__((unavailable("Use keepsIconUpright instead."))); /** If true, the text may be flipped vertically to prevent it from being rendered upside-down. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `YES`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `YES`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and - `textRotationAlignment` is set to an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextRotationAlignmentMap`, and - `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` - object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. + `textRotationAlignment` is set to an expression that evaluates to `map`, and + `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, + it is ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-keep-upright"><code>text-keep-upright</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *keepsTextUpright; +@property (nonatomic, null_resettable) NSExpression *keepsTextUpright; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textKeepUpright __attribute__((unavailable("Use keepsTextUpright instead."))); +@property (nonatomic, null_resettable) NSExpression *textKeepUpright __attribute__((unavailable("Use keepsTextUpright instead."))); /** Maximum angle change between adjacent characters. This property is measured in degrees. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `45`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `45`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and - `symbolPlacement` is set to an `MGLStyleValue` object containing an `NSValue` - object containing `MGLSymbolPlacementLine`. Otherwise, it is ignored. + `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, + it is ignored. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-max-angle"><code>text-max-angle</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *maximumTextAngle; +@property (nonatomic, null_resettable) NSExpression *maximumTextAngle; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textMaxAngle __attribute__((unavailable("Use maximumTextAngle instead."))); +@property (nonatomic, null_resettable) NSExpression *textMaxAngle __attribute__((unavailable("Use maximumTextAngle instead."))); /** The maximum line width for text wrapping. This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `10`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `10`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -856,26 +894,19 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-max-width"><code>text-max-width</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *maximumTextWidth; +@property (nonatomic, null_resettable) NSExpression *maximumTextWidth; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textMaxWidth __attribute__((unavailable("Use maximumTextWidth instead."))); +@property (nonatomic, null_resettable) NSExpression *textMaxWidth __attribute__((unavailable("Use maximumTextWidth instead."))); /** If true, the symbols will not cross tile edges to avoid mutual collisions. @@ -883,61 +914,77 @@ MGL_EXPORT prevent collisions, or if it is a point symbol layer placed after a line symbol layer. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-symbol-avoid-edges"><code>symbol-avoid-edges</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *symbolAvoidsEdges; +@property (nonatomic, null_resettable) NSExpression *symbolAvoidsEdges; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *symbolAvoidEdges __attribute__((unavailable("Use symbolAvoidsEdges instead."))); +@property (nonatomic, null_resettable) NSExpression *symbolAvoidEdges __attribute__((unavailable("Use symbolAvoidsEdges instead."))); /** Label placement relative to its geometry. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLSymbolPlacementPoint`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `point`. + Set this property to `nil` to reset it to the default value. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant `MGLSymbolPlacement` values + * Any of the following constant string values: + * `point`: The label is placed at the point where the geometry is located. + * `line`: The label is placed along the line of the geometry. Can only be + used on `LineString` and `Polygon` geometries. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *symbolPlacement; +@property (nonatomic, null_resettable) NSExpression *symbolPlacement; /** Distance between two symbol anchors. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `250`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `250`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `symbolPlacement` is set to an - `MGLStyleValue` object containing an `NSValue` object containing - `MGLSymbolPlacementLine`. Otherwise, it is ignored. + expression that evaluates to `line`. Otherwise, it is ignored. + + You can set this property to an expression containing any of the following: - You can set this property to an instance of: + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *symbolSpacing; +@property (nonatomic, null_resettable) NSExpression *symbolSpacing; /** Value to use for a text label. Within literal values, attribute names enclosed @@ -945,41 +992,33 @@ MGL_EXPORT attribute. Expressions do not support this syntax; for equivalent functionality in expressions, use `stringByAppendingString:` and key path expressions. - The default value of this property is an `MGLStyleValue` object containing the - empty string. Set this property to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to the empty + string. Set this property to `nil` to reset it to the default value. This attribute corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-field"><code>text-field</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant string values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *text; +@property (nonatomic, null_resettable) NSExpression *text; -@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *textField __attribute__((unavailable("Use text instead."))); +@property (nonatomic, null_resettable) NSExpression *textField __attribute__((unavailable("Use text instead."))); /** If true, the text will be visible even if it collides with other previously drawn symbols. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -988,44 +1027,56 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-allow-overlap"><code>text-allow-overlap</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textAllowsOverlap; +@property (nonatomic, null_resettable) NSExpression *textAllowsOverlap; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textAllowOverlap __attribute__((unavailable("Use textAllowsOverlap instead."))); +@property (nonatomic, null_resettable) NSExpression *textAllowOverlap __attribute__((unavailable("Use textAllowsOverlap instead."))); /** Part of the text placed closest to the anchor. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextAnchorCenter`. Set this property to `nil` - to reset it to the default value. + The default value of this property is an expression that evaluates to `center`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textAnchor; + You can set this property to an expression containing any of the following: + + * Constant `MGLTextAnchor` values + * Any of the following constant string values: + * `center`: The center of the text is placed closest to the anchor. + * `left`: The left side of the text is placed closest to the anchor. + * `right`: The right side of the text is placed closest to the anchor. + * `top`: The top of the text is placed closest to the anchor. + * `bottom`: The bottom of the text is placed closest to the anchor. + * `top-left`: The top left corner of the text is placed closest to the + anchor. + * `top-right`: The top right corner of the text is placed closest to the + anchor. + * `bottom-left`: The bottom left corner of the text is placed closest to the + anchor. + * `bottom-right`: The bottom right corner of the text is placed closest to + the anchor. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *textAnchor; /** An array of font face names used to display the text. @@ -1040,9 +1091,9 @@ MGL_EXPORT the text, if the first font lacks a glyph for the character, the next font is applied as a fallback, and so on. - The default value of this property is an `MGLStyleValue` object containing the - array `Open Sans Regular`, `Arial Unicode MS Regular`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to the array + `Open Sans Regular`, `Arial Unicode MS Regular`. Set this property to `nil` to + reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1051,35 +1102,27 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-font"><code>text-font</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant array values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSArray<NSString *> *> *textFontNames; +@property (nonatomic, null_resettable) NSExpression *textFontNames; -@property (nonatomic, null_resettable) MGLStyleValue<NSArray<NSString *> *> *textFont __attribute__((unavailable("Use textFontNames instead."))); +@property (nonatomic, null_resettable) NSExpression *textFont __attribute__((unavailable("Use textFontNames instead."))); /** Font size. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `16`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `16`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1088,33 +1131,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-size"><code>text-size</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textFontSize; +@property (nonatomic, null_resettable) NSExpression *textFontSize; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textSize __attribute__((unavailable("Use textFontSize instead."))); +@property (nonatomic, null_resettable) NSExpression *textSize __attribute__((unavailable("Use textFontSize instead."))); /** If true, other symbols can be visible even if they collide with the text. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1123,23 +1158,28 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-ignore-placement"><code>text-ignore-placement</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textIgnoresPlacement; +@property (nonatomic, null_resettable) NSExpression *textIgnoresPlacement; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textIgnorePlacement __attribute__((unavailable("Use textIgnoresPlacement instead."))); +@property (nonatomic, null_resettable) NSExpression *textIgnorePlacement __attribute__((unavailable("Use textIgnoresPlacement instead."))); /** Text justification options. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextJustificationCenter`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `center`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1148,77 +1188,69 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-justify"><code>text-justify</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `MGLTextJustification` values + * Any of the following constant string values: + * `left`: The text is aligned to the left. + * `center`: The text is centered. + * `right`: The text is aligned to the right. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textJustification; +@property (nonatomic, null_resettable) NSExpression *textJustification; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textJustify __attribute__((unavailable("Use textJustification instead."))); +@property (nonatomic, null_resettable) NSExpression *textJustify __attribute__((unavailable("Use textJustification instead."))); /** Text tracking amount. This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textLetterSpacing; +@property (nonatomic, null_resettable) NSExpression *textLetterSpacing; /** Text leading value for multi-line text. This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1.2`. Set this property to `nil` to - reset it to the default value. + The default value of this property is an expression that evaluates to the float + `1.2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textLineHeight; +@property (nonatomic, null_resettable) NSExpression *textLineHeight; #if TARGET_OS_IPHONE /** @@ -1226,80 +1258,71 @@ MGL_EXPORT This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 ems rightward and 0 ems downward. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textOffset; + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *textOffset; #else /** Offset distance of text from its anchor. This property is measured in ems. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 ems rightward and 0 ems upward. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textOffset; + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *textOffset; #endif /** If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing `NO`. Set this property to `nil` to reset it to - the default value. + The default value of this property is an expression that evaluates to `NO`. Set + this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant Boolean values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable, getter=isTextOptional) MGLStyleValue<NSNumber *> *textOptional; +@property (nonatomic, null_resettable, getter=isTextOptional) NSExpression *textOptional; /** Size of the additional area around the text bounding box used for detecting @@ -1307,48 +1330,59 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `2`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textPadding; +@property (nonatomic, null_resettable) NSExpression *textPadding; /** Orientation of text when map is pitched. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextPitchAlignmentAuto`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `auto`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLTextPitchAlignment` values + * Any of the following constant string values: + * `map`: The text is aligned to the plane of the map. + * `viewport`: The text is aligned to the plane of the viewport. + * `auto`: Automatically matches the value of `text-rotation-alignment`. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textPitchAlignment; +@property (nonatomic, null_resettable) NSExpression *textPitchAlignment; /** Rotates the text clockwise. This property is measured in degrees. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1357,135 +1391,99 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#layout-symbol-text-rotate"><code>text-rotate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textRotation; +@property (nonatomic, null_resettable) NSExpression *textRotation; -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textRotate __attribute__((unavailable("Use textRotation instead."))); +@property (nonatomic, null_resettable) NSExpression *textRotate __attribute__((unavailable("Use textRotation instead."))); /** In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextRotationAlignmentAuto`. Set this property - to `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `auto`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLTextRotationAlignment` values + * Any of the following constant string values: + * `map`: When `symbol-placement` is set to `point`, aligns text east-west. + When `symbol-placement` is set to `line`, aligns text x-axes with the line. + * `viewport`: Produces glyphs whose x-axes are aligned with the x-axis of the + viewport, regardless of the value of `symbol-placement`. + * `auto`: When `symbol-placement` is set to `point`, this is equivalent to + `viewport`. When `symbol-placement` is set to `line`, this is equivalent to + `map`. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textRotationAlignment; +@property (nonatomic, null_resettable) NSExpression *textRotationAlignment; /** Specifies how to capitalize text. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextTransformNone`. Set this property to `nil` - to reset it to the default value. + The default value of this property is an expression that evaluates to `none`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant `MGLTextTransform` values + * Any of the following constant string values: + * `none`: The text is not altered. + * `uppercase`: Forces all letters to be displayed in uppercase. + * `lowercase`: Forces all letters to be displayed in lowercase. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTransform; +@property (nonatomic, null_resettable) NSExpression *textTransform; #pragma mark - Accessing the Paint Attributes -#if TARGET_OS_IPHONE /** The tint color to apply to the icon. The `iconImageName` property must be set to a template image. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *iconColor; -#else -/** - The tint color to apply to the icon. The `iconImageName` property must be set - to a template image. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `iconImageName` is non-`nil`. - Otherwise, it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *iconColor; -#endif + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *iconColor; /** The transition affecting any changes to this layer’s `iconColor` property. @@ -1499,30 +1497,22 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconHaloBlur; +@property (nonatomic, null_resettable) NSExpression *iconHaloBlur; /** The transition affecting any changes to this layer’s `iconHaloBlur` property. @@ -1531,65 +1521,27 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition iconHaloBlurTransition; -#if TARGET_OS_IPHONE /** The color of the icon’s halo. The `iconImageName` property must be set to a template image. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.clearColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *iconHaloColor; -#else -/** - The color of the icon’s halo. The `iconImageName` property must be set to a - template image. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.clearColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `iconImageName` is non-`nil`. - Otherwise, it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *iconHaloColor; -#endif + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *iconHaloColor; /** The transition affecting any changes to this layer’s `iconHaloColor` property. @@ -1603,30 +1555,22 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconHaloWidth; +@property (nonatomic, null_resettable) NSExpression *iconHaloWidth; /** The transition affecting any changes to this layer’s `iconHaloWidth` property. @@ -1638,30 +1582,22 @@ MGL_EXPORT /** The opacity at which the icon will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *iconOpacity; +@property (nonatomic, null_resettable) NSExpression *iconOpacity; /** The transition affecting any changes to this layer’s `iconOpacity` property. @@ -1676,7 +1612,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -1687,21 +1623,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-icon-translate"><code>icon-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTranslation; +@property (nonatomic, null_resettable) NSExpression *iconTranslation; #else /** Distance that the icon's anchor is moved from its original placement. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -1712,14 +1652,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-icon-translate"><code>icon-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTranslation; +@property (nonatomic, null_resettable) NSExpression *iconTranslation; #endif /** @@ -1729,14 +1673,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition iconTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTranslate __attribute__((unavailable("Use iconTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *iconTranslate __attribute__((unavailable("Use iconTranslation instead."))); /** Controls the frame of reference for `iconTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLIconTranslationAnchorMap`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`, and `iconTranslation` is non-`nil`. Otherwise, it is ignored. @@ -1745,73 +1688,45 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-icon-translate-anchor"><code>icon-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLIconTranslationAnchor` values + * Any of the following constant string values: + * `map`: Icons are translated relative to the map. + * `viewport`: Icons are translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *iconTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTranslateAnchor __attribute__((unavailable("Use iconTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *iconTranslateAnchor __attribute__((unavailable("Use iconTranslationAnchor instead."))); -#if TARGET_OS_IPHONE /** The color with which the text will be drawn. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.blackColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *textColor; -#else -/** - The color with which the text will be drawn. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.blackColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `text` is non-`nil`. Otherwise, - it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *textColor; -#endif + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *textColor; /** The transition affecting any changes to this layer’s `textColor` property. @@ -1825,30 +1740,22 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textHaloBlur; +@property (nonatomic, null_resettable) NSExpression *textHaloBlur; /** The transition affecting any changes to this layer’s `textHaloBlur` property. @@ -1857,63 +1764,26 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition textHaloBlurTransition; -#if TARGET_OS_IPHONE /** The color of the text's halo, which helps it stand out from backgrounds. - The default value of this property is an `MGLStyleValue` object containing + The default value of this property is an expression that evaluates to `UIColor.clearColor`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *textHaloColor; -#else -/** - The color of the text's halo, which helps it stand out from backgrounds. - - The default value of this property is an `MGLStyleValue` object containing - `NSColor.clearColor`. Set this property to `nil` to reset it to the default - value. - - This property is only applied to the style if `text` is non-`nil`. Otherwise, - it is ignored. + You can set this property to an expression containing any of the following: - You can set this property to an instance of: - - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - */ -@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *textHaloColor; -#endif + * Constant `UIColor` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes + */ +@property (nonatomic, null_resettable) NSExpression *textHaloColor; /** The transition affecting any changes to this layer’s `textHaloColor` property. @@ -1928,30 +1798,22 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `0`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textHaloWidth; +@property (nonatomic, null_resettable) NSExpression *textHaloWidth; /** The transition affecting any changes to this layer’s `textHaloWidth` property. @@ -1963,30 +1825,22 @@ MGL_EXPORT /** The opacity at which the text will be drawn. - The default value of this property is an `MGLStyleValue` object containing an - `NSNumber` object containing the float `1`. Set this property to `nil` to reset - it to the default value. + The default value of this property is an expression that evaluates to the float + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLSourceStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` - * `MGLInterpolationModeIdentity` - * `MGLCompositeStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` - * `MGLInterpolationModeCategorical` + * Constant numeric values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable and/or + feature attributes */ -@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textOpacity; +@property (nonatomic, null_resettable) NSExpression *textOpacity; /** The transition affecting any changes to this layer’s `textOpacity` property. @@ -2001,7 +1855,7 @@ MGL_EXPORT This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points downward. Set this property to `nil` to reset it to the default value. @@ -2012,21 +1866,25 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-text-translate"><code>text-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable + + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTranslation; +@property (nonatomic, null_resettable) NSExpression *textTranslation; #else /** Distance that the text's anchor is moved from its original placement. This property is measured in points. - The default value of this property is an `MGLStyleValue` object containing an + The default value of this property is an expression that evaluates to an `NSValue` object containing a `CGVector` struct set to 0 points rightward and 0 points upward. Set this property to `nil` to reset it to the default value. @@ -2037,14 +1895,18 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-text-translate"><code>text-translate</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `CGVector` values + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Interpolation and step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of: - * `MGLInterpolationModeExponential` - * `MGLInterpolationModeInterval` + This property does not support applying interpolation or step functions to + feature attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTranslation; +@property (nonatomic, null_resettable) NSExpression *textTranslation; #endif /** @@ -2054,14 +1916,13 @@ MGL_EXPORT */ @property (nonatomic) MGLTransition textTranslationTransition; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTranslate __attribute__((unavailable("Use textTranslation instead."))); +@property (nonatomic, null_resettable) NSExpression *textTranslate __attribute__((unavailable("Use textTranslation instead."))); /** Controls the frame of reference for `textTranslation`. - The default value of this property is an `MGLStyleValue` object containing an - `NSValue` object containing `MGLTextTranslationAnchorMap`. Set this property to - `nil` to reset it to the default value. + The default value of this property is an expression that evaluates to `map`. + Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and `textTranslation` is non-`nil`. Otherwise, it is ignored. @@ -2070,15 +1931,24 @@ MGL_EXPORT href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-text-translate-anchor"><code>text-translate-anchor</code></a> layout property in the Mapbox Style Specification. - You can set this property to an instance of: + You can set this property to an expression containing any of the following: + + * Constant `MGLTextTranslationAnchor` values + * Any of the following constant string values: + * `map`: The text is translated relative to the map. + * `viewport`: The text is translated relative to the viewport. + * Predefined functions, including mathematical and string operators + * Conditional expressions + * Variable assignments and references to assigned variables + * Step functions applied to the `$zoomLevel` variable - * `MGLConstantStyleValue` - * `MGLCameraStyleFunction` with an interpolation mode of - `MGLInterpolationModeInterval` + This property does not support applying interpolation functions to the + `$zoomLevel` variable or applying interpolation or step functions to feature + attributes. */ -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTranslationAnchor; +@property (nonatomic, null_resettable) NSExpression *textTranslationAnchor; -@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textTranslateAnchor __attribute__((unavailable("Use textTranslationAnchor instead."))); +@property (nonatomic, null_resettable) NSExpression *textTranslateAnchor __attribute__((unavailable("Use textTranslationAnchor instead."))); @end diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 3f206aac19..24d6643e6c 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -154,754 +154,754 @@ namespace mbgl { #pragma mark - Accessing the Layout Attributes -- (void)setIconAllowsOverlap:(MGLStyleValue<NSNumber *> *)iconAllowsOverlap { +- (void)setIconAllowsOverlap:(NSExpression *)iconAllowsOverlap { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconAllowsOverlap); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(iconAllowsOverlap); self.rawLayer->setIconAllowOverlap(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconAllowsOverlap { +- (NSExpression *)iconAllowsOverlap { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconAllowOverlap(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultIconAllowOverlap()); + propertyValue = self.rawLayer->getDefaultIconAllowOverlap(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setIconAllowOverlap:(MGLStyleValue<NSNumber *> *)iconAllowOverlap { +- (void)setIconAllowOverlap:(NSExpression *)iconAllowOverlap { } -- (MGLStyleValue<NSNumber *> *)iconAllowOverlap { +- (NSExpression *)iconAllowOverlap { return self.iconAllowsOverlap; } -- (void)setIconAnchor:(MGLStyleValue<NSValue *> *)iconAnchor { +- (void)setIconAnchor:(NSExpression *)iconAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLIconAnchor>().toDataDrivenPropertyValue(iconAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLIconAnchor>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::style::SymbolAnchorType>>(iconAnchor); self.rawLayer->setIconAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconAnchor { +- (NSExpression *)iconAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLIconAnchor>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconAnchor()); + propertyValue = self.rawLayer->getDefaultIconAnchor(); } - return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLIconAnchor>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLIconAnchor>().toExpression(propertyValue); } -- (void)setIconIgnoresPlacement:(MGLStyleValue<NSNumber *> *)iconIgnoresPlacement { +- (void)setIconIgnoresPlacement:(NSExpression *)iconIgnoresPlacement { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconIgnoresPlacement); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(iconIgnoresPlacement); self.rawLayer->setIconIgnorePlacement(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconIgnoresPlacement { +- (NSExpression *)iconIgnoresPlacement { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconIgnorePlacement(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultIconIgnorePlacement()); + propertyValue = self.rawLayer->getDefaultIconIgnorePlacement(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setIconIgnorePlacement:(MGLStyleValue<NSNumber *> *)iconIgnorePlacement { +- (void)setIconIgnorePlacement:(NSExpression *)iconIgnorePlacement { } -- (MGLStyleValue<NSNumber *> *)iconIgnorePlacement { +- (NSExpression *)iconIgnorePlacement { return self.iconIgnoresPlacement; } -- (void)setIconImageName:(MGLStyleValue<NSString *> *)iconImageName { +- (void)setIconImageName:(NSExpression *)iconImageName { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenPropertyValue(iconImageName); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::string>>(iconImageName); self.rawLayer->setIconImage(mbglValue); } -- (MGLStyleValue<NSString *> *)iconImageName { +- (NSExpression *)iconImageName { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconImage(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconImage()); + propertyValue = self.rawLayer->getDefaultIconImage(); } - return MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } -- (void)setIconImage:(MGLStyleValue<NSString *> *)iconImage { +- (void)setIconImage:(NSExpression *)iconImage { } -- (MGLStyleValue<NSString *> *)iconImage { +- (NSExpression *)iconImage { return self.iconImageName; } -- (void)setIconOffset:(MGLStyleValue<NSValue *> *)iconOffset { +- (void)setIconOffset:(NSExpression *)iconOffset { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenPropertyValue(iconOffset); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::array<float, 2>>>(iconOffset); self.rawLayer->setIconOffset(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconOffset { +- (NSExpression *)iconOffset { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconOffset(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconOffset()); + propertyValue = self.rawLayer->getDefaultIconOffset(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } -- (void)setIconOptional:(MGLStyleValue<NSNumber *> *)iconOptional { +- (void)setIconOptional:(NSExpression *)iconOptional { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(iconOptional); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(iconOptional); self.rawLayer->setIconOptional(mbglValue); } -- (MGLStyleValue<NSNumber *> *)isIconOptional { +- (NSExpression *)isIconOptional { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconOptional(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultIconOptional()); + propertyValue = self.rawLayer->getDefaultIconOptional(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setIconPadding:(MGLStyleValue<NSNumber *> *)iconPadding { +- (void)setIconPadding:(NSExpression *)iconPadding { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(iconPadding); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(iconPadding); self.rawLayer->setIconPadding(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconPadding { +- (NSExpression *)iconPadding { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconPadding(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultIconPadding()); + propertyValue = self.rawLayer->getDefaultIconPadding(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setIconPitchAlignment:(MGLStyleValue<NSValue *> *)iconPitchAlignment { +- (void)setIconPitchAlignment:(NSExpression *)iconPitchAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconPitchAlignment>().toEnumPropertyValue(iconPitchAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconPitchAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::AlignmentType>>(iconPitchAlignment); self.rawLayer->setIconPitchAlignment(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconPitchAlignment { +- (NSExpression *)iconPitchAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconPitchAlignment(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconPitchAlignment>().toEnumStyleValue(self.rawLayer->getDefaultIconPitchAlignment()); + propertyValue = self.rawLayer->getDefaultIconPitchAlignment(); } - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconPitchAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconPitchAlignment>().toExpression(propertyValue); } -- (void)setIconRotation:(MGLStyleValue<NSNumber *> *)iconRotation { +- (void)setIconRotation:(NSExpression *)iconRotation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(iconRotation); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(iconRotation); self.rawLayer->setIconRotate(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconRotation { +- (NSExpression *)iconRotation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconRotate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconRotate()); + propertyValue = self.rawLayer->getDefaultIconRotate(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setIconRotate:(MGLStyleValue<NSNumber *> *)iconRotate { +- (void)setIconRotate:(NSExpression *)iconRotate { } -- (MGLStyleValue<NSNumber *> *)iconRotate { +- (NSExpression *)iconRotate { return self.iconRotation; } -- (void)setIconRotationAlignment:(MGLStyleValue<NSValue *> *)iconRotationAlignment { +- (void)setIconRotationAlignment:(NSExpression *)iconRotationAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toEnumPropertyValue(iconRotationAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::AlignmentType>>(iconRotationAlignment); self.rawLayer->setIconRotationAlignment(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconRotationAlignment { +- (NSExpression *)iconRotationAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconRotationAlignment(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toEnumStyleValue(self.rawLayer->getDefaultIconRotationAlignment()); + propertyValue = self.rawLayer->getDefaultIconRotationAlignment(); } - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLIconRotationAlignment>().toExpression(propertyValue); } -- (void)setIconScale:(MGLStyleValue<NSNumber *> *)iconScale { +- (void)setIconScale:(NSExpression *)iconScale { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(iconScale); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(iconScale); self.rawLayer->setIconSize(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconScale { +- (NSExpression *)iconScale { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconSize(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconSize()); + propertyValue = self.rawLayer->getDefaultIconSize(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setIconSize:(MGLStyleValue<NSNumber *> *)iconSize { +- (void)setIconSize:(NSExpression *)iconSize { } -- (MGLStyleValue<NSNumber *> *)iconSize { +- (NSExpression *)iconSize { return self.iconScale; } -- (void)setIconTextFit:(MGLStyleValue<NSValue *> *)iconTextFit { +- (void)setIconTextFit:(NSExpression *)iconTextFit { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toEnumPropertyValue(iconTextFit); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::IconTextFitType>>(iconTextFit); self.rawLayer->setIconTextFit(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconTextFit { +- (NSExpression *)iconTextFit { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconTextFit(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toEnumStyleValue(self.rawLayer->getDefaultIconTextFit()); + propertyValue = self.rawLayer->getDefaultIconTextFit(); } - return MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::IconTextFitType, NSValue *, mbgl::style::IconTextFitType, MGLIconTextFit>().toExpression(propertyValue); } -- (void)setIconTextFitPadding:(MGLStyleValue<NSValue *> *)iconTextFitPadding { +- (void)setIconTextFitPadding:(NSExpression *)iconTextFitPadding { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toInterpolatablePropertyValue(iconTextFitPadding); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 4>>>(iconTextFitPadding); self.rawLayer->setIconTextFitPadding(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconTextFitPadding { +- (NSExpression *)iconTextFitPadding { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconTextFitPadding(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toStyleValue(self.rawLayer->getDefaultIconTextFitPadding()); + propertyValue = self.rawLayer->getDefaultIconTextFitPadding(); } - return MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toExpression(propertyValue); } -- (void)setKeepsIconUpright:(MGLStyleValue<NSNumber *> *)keepsIconUpright { +- (void)setKeepsIconUpright:(NSExpression *)keepsIconUpright { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(keepsIconUpright); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(keepsIconUpright); self.rawLayer->setIconKeepUpright(mbglValue); } -- (MGLStyleValue<NSNumber *> *)keepsIconUpright { +- (NSExpression *)keepsIconUpright { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconKeepUpright(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultIconKeepUpright()); + propertyValue = self.rawLayer->getDefaultIconKeepUpright(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setIconKeepUpright:(MGLStyleValue<NSNumber *> *)iconKeepUpright { +- (void)setIconKeepUpright:(NSExpression *)iconKeepUpright { } -- (MGLStyleValue<NSNumber *> *)iconKeepUpright { +- (NSExpression *)iconKeepUpright { return self.keepsIconUpright; } -- (void)setKeepsTextUpright:(MGLStyleValue<NSNumber *> *)keepsTextUpright { +- (void)setKeepsTextUpright:(NSExpression *)keepsTextUpright { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(keepsTextUpright); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(keepsTextUpright); self.rawLayer->setTextKeepUpright(mbglValue); } -- (MGLStyleValue<NSNumber *> *)keepsTextUpright { +- (NSExpression *)keepsTextUpright { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextKeepUpright(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextKeepUpright()); + propertyValue = self.rawLayer->getDefaultTextKeepUpright(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setTextKeepUpright:(MGLStyleValue<NSNumber *> *)textKeepUpright { +- (void)setTextKeepUpright:(NSExpression *)textKeepUpright { } -- (MGLStyleValue<NSNumber *> *)textKeepUpright { +- (NSExpression *)textKeepUpright { return self.keepsTextUpright; } -- (void)setMaximumTextAngle:(MGLStyleValue<NSNumber *> *)maximumTextAngle { +- (void)setMaximumTextAngle:(NSExpression *)maximumTextAngle { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(maximumTextAngle); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(maximumTextAngle); self.rawLayer->setTextMaxAngle(mbglValue); } -- (MGLStyleValue<NSNumber *> *)maximumTextAngle { +- (NSExpression *)maximumTextAngle { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextMaxAngle(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextMaxAngle()); + propertyValue = self.rawLayer->getDefaultTextMaxAngle(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextMaxAngle:(MGLStyleValue<NSNumber *> *)textMaxAngle { +- (void)setTextMaxAngle:(NSExpression *)textMaxAngle { } -- (MGLStyleValue<NSNumber *> *)textMaxAngle { +- (NSExpression *)textMaxAngle { return self.maximumTextAngle; } -- (void)setMaximumTextWidth:(MGLStyleValue<NSNumber *> *)maximumTextWidth { +- (void)setMaximumTextWidth:(NSExpression *)maximumTextWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(maximumTextWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(maximumTextWidth); self.rawLayer->setTextMaxWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)maximumTextWidth { +- (NSExpression *)maximumTextWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextMaxWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextMaxWidth()); + propertyValue = self.rawLayer->getDefaultTextMaxWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextMaxWidth:(MGLStyleValue<NSNumber *> *)textMaxWidth { +- (void)setTextMaxWidth:(NSExpression *)textMaxWidth { } -- (MGLStyleValue<NSNumber *> *)textMaxWidth { +- (NSExpression *)textMaxWidth { return self.maximumTextWidth; } -- (void)setSymbolAvoidsEdges:(MGLStyleValue<NSNumber *> *)symbolAvoidsEdges { +- (void)setSymbolAvoidsEdges:(NSExpression *)symbolAvoidsEdges { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(symbolAvoidsEdges); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(symbolAvoidsEdges); self.rawLayer->setSymbolAvoidEdges(mbglValue); } -- (MGLStyleValue<NSNumber *> *)symbolAvoidsEdges { +- (NSExpression *)symbolAvoidsEdges { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getSymbolAvoidEdges(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultSymbolAvoidEdges()); + propertyValue = self.rawLayer->getDefaultSymbolAvoidEdges(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setSymbolAvoidEdges:(MGLStyleValue<NSNumber *> *)symbolAvoidEdges { +- (void)setSymbolAvoidEdges:(NSExpression *)symbolAvoidEdges { } -- (MGLStyleValue<NSNumber *> *)symbolAvoidEdges { +- (NSExpression *)symbolAvoidEdges { return self.symbolAvoidsEdges; } -- (void)setSymbolPlacement:(MGLStyleValue<NSValue *> *)symbolPlacement { +- (void)setSymbolPlacement:(NSExpression *)symbolPlacement { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toEnumPropertyValue(symbolPlacement); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::SymbolPlacementType>>(symbolPlacement); self.rawLayer->setSymbolPlacement(mbglValue); } -- (MGLStyleValue<NSValue *> *)symbolPlacement { +- (NSExpression *)symbolPlacement { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getSymbolPlacement(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toEnumStyleValue(self.rawLayer->getDefaultSymbolPlacement()); + propertyValue = self.rawLayer->getDefaultSymbolPlacement(); } - return MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::SymbolPlacementType, NSValue *, mbgl::style::SymbolPlacementType, MGLSymbolPlacement>().toExpression(propertyValue); } -- (void)setSymbolSpacing:(MGLStyleValue<NSNumber *> *)symbolSpacing { +- (void)setSymbolSpacing:(NSExpression *)symbolSpacing { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(symbolSpacing); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(symbolSpacing); self.rawLayer->setSymbolSpacing(mbglValue); } -- (MGLStyleValue<NSNumber *> *)symbolSpacing { +- (NSExpression *)symbolSpacing { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getSymbolSpacing(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultSymbolSpacing()); + propertyValue = self.rawLayer->getDefaultSymbolSpacing(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setText:(MGLStyleValue<NSString *> *)text { +- (void)setText:(NSExpression *)text { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenPropertyValue(text); + auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::string>>(text); self.rawLayer->setTextField(mbglValue); } -- (MGLStyleValue<NSString *> *)text { +- (NSExpression *)text { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextField(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextField()); + propertyValue = self.rawLayer->getDefaultTextField(); } - return MGLStyleValueTransformer<std::string, NSString *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<std::string, NSString *>().toExpression(propertyValue); } -- (void)setTextField:(MGLStyleValue<NSString *> *)textField { +- (void)setTextField:(NSExpression *)textField { } -- (MGLStyleValue<NSString *> *)textField { +- (NSExpression *)textField { return self.text; } -- (void)setTextAllowsOverlap:(MGLStyleValue<NSNumber *> *)textAllowsOverlap { +- (void)setTextAllowsOverlap:(NSExpression *)textAllowsOverlap { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textAllowsOverlap); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(textAllowsOverlap); self.rawLayer->setTextAllowOverlap(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textAllowsOverlap { +- (NSExpression *)textAllowsOverlap { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextAllowOverlap(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextAllowOverlap()); + propertyValue = self.rawLayer->getDefaultTextAllowOverlap(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setTextAllowOverlap:(MGLStyleValue<NSNumber *> *)textAllowOverlap { +- (void)setTextAllowOverlap:(NSExpression *)textAllowOverlap { } -- (MGLStyleValue<NSNumber *> *)textAllowOverlap { +- (NSExpression *)textAllowOverlap { return self.textAllowsOverlap; } -- (void)setTextAnchor:(MGLStyleValue<NSValue *> *)textAnchor { +- (void)setTextAnchor:(NSExpression *)textAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toDataDrivenPropertyValue(textAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::style::SymbolAnchorType>>(textAnchor); self.rawLayer->setTextAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)textAnchor { +- (NSExpression *)textAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextAnchor()); + propertyValue = self.rawLayer->getDefaultTextAnchor(); } - return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::SymbolAnchorType, NSValue *, mbgl::style::SymbolAnchorType, MGLTextAnchor>().toExpression(propertyValue); } -- (void)setTextFontNames:(MGLStyleValue<NSArray<NSString *> *> *)textFontNames { +- (void)setTextFontNames:(NSExpression *)textFontNames { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toDataDrivenPropertyValue(textFontNames); + auto mbglValue = MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::vector<std::string>>>(textFontNames); self.rawLayer->setTextFont(mbglValue); } -- (MGLStyleValue<NSArray<NSString *> *> *)textFontNames { +- (NSExpression *)textFontNames { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextFont(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextFont()); + propertyValue = self.rawLayer->getDefaultTextFont(); } - return MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<std::vector<std::string>, NSArray<NSString *> *, std::string>().toExpression(propertyValue); } -- (void)setTextFont:(MGLStyleValue<NSArray<NSString *> *> *)textFont { +- (void)setTextFont:(NSExpression *)textFont { } -- (MGLStyleValue<NSArray<NSString *> *> *)textFont { +- (NSExpression *)textFont { return self.textFontNames; } -- (void)setTextFontSize:(MGLStyleValue<NSNumber *> *)textFontSize { +- (void)setTextFontSize:(NSExpression *)textFontSize { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textFontSize); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textFontSize); self.rawLayer->setTextSize(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textFontSize { +- (NSExpression *)textFontSize { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextSize(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextSize()); + propertyValue = self.rawLayer->getDefaultTextSize(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextSize:(MGLStyleValue<NSNumber *> *)textSize { +- (void)setTextSize:(NSExpression *)textSize { } -- (MGLStyleValue<NSNumber *> *)textSize { +- (NSExpression *)textSize { return self.textFontSize; } -- (void)setTextIgnoresPlacement:(MGLStyleValue<NSNumber *> *)textIgnoresPlacement { +- (void)setTextIgnoresPlacement:(NSExpression *)textIgnoresPlacement { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textIgnoresPlacement); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(textIgnoresPlacement); self.rawLayer->setTextIgnorePlacement(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textIgnoresPlacement { +- (NSExpression *)textIgnoresPlacement { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextIgnorePlacement(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextIgnorePlacement()); + propertyValue = self.rawLayer->getDefaultTextIgnorePlacement(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setTextIgnorePlacement:(MGLStyleValue<NSNumber *> *)textIgnorePlacement { +- (void)setTextIgnorePlacement:(NSExpression *)textIgnorePlacement { } -- (MGLStyleValue<NSNumber *> *)textIgnorePlacement { +- (NSExpression *)textIgnorePlacement { return self.textIgnoresPlacement; } -- (void)setTextJustification:(MGLStyleValue<NSValue *> *)textJustification { +- (void)setTextJustification:(NSExpression *)textJustification { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenPropertyValue(textJustification); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::style::TextJustifyType>>(textJustification); self.rawLayer->setTextJustify(mbglValue); } -- (MGLStyleValue<NSValue *> *)textJustification { +- (NSExpression *)textJustification { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextJustify(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextJustify()); + propertyValue = self.rawLayer->getDefaultTextJustify(); } - return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TextJustifyType, NSValue *, mbgl::style::TextJustifyType, MGLTextJustification>().toExpression(propertyValue); } -- (void)setTextJustify:(MGLStyleValue<NSValue *> *)textJustify { +- (void)setTextJustify:(NSExpression *)textJustify { } -- (MGLStyleValue<NSValue *> *)textJustify { +- (NSExpression *)textJustify { return self.textJustification; } -- (void)setTextLetterSpacing:(MGLStyleValue<NSNumber *> *)textLetterSpacing { +- (void)setTextLetterSpacing:(NSExpression *)textLetterSpacing { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textLetterSpacing); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textLetterSpacing); self.rawLayer->setTextLetterSpacing(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textLetterSpacing { +- (NSExpression *)textLetterSpacing { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextLetterSpacing(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextLetterSpacing()); + propertyValue = self.rawLayer->getDefaultTextLetterSpacing(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextLineHeight:(MGLStyleValue<NSNumber *> *)textLineHeight { +- (void)setTextLineHeight:(NSExpression *)textLineHeight { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(textLineHeight); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(textLineHeight); self.rawLayer->setTextLineHeight(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textLineHeight { +- (NSExpression *)textLineHeight { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextLineHeight(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextLineHeight()); + propertyValue = self.rawLayer->getDefaultTextLineHeight(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextOffset:(MGLStyleValue<NSValue *> *)textOffset { +- (void)setTextOffset:(NSExpression *)textOffset { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenPropertyValue(textOffset); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<std::array<float, 2>>>(textOffset); self.rawLayer->setTextOffset(mbglValue); } -- (MGLStyleValue<NSValue *> *)textOffset { +- (NSExpression *)textOffset { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextOffset(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextOffset()); + propertyValue = self.rawLayer->getDefaultTextOffset(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } -- (void)setTextOptional:(MGLStyleValue<NSNumber *> *)textOptional { +- (void)setTextOptional:(NSExpression *)textOptional { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(textOptional); + auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<bool>>(textOptional); self.rawLayer->setTextOptional(mbglValue); } -- (MGLStyleValue<NSNumber *> *)isTextOptional { +- (NSExpression *)isTextOptional { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextOptional(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextOptional()); + propertyValue = self.rawLayer->getDefaultTextOptional(); } - return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<bool, NSNumber *>().toExpression(propertyValue); } -- (void)setTextPadding:(MGLStyleValue<NSNumber *> *)textPadding { +- (void)setTextPadding:(NSExpression *)textPadding { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(textPadding); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::PropertyValue<float>>(textPadding); self.rawLayer->setTextPadding(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textPadding { +- (NSExpression *)textPadding { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextPadding(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultTextPadding()); + propertyValue = self.rawLayer->getDefaultTextPadding(); } - return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextPitchAlignment:(MGLStyleValue<NSValue *> *)textPitchAlignment { +- (void)setTextPitchAlignment:(NSExpression *)textPitchAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toEnumPropertyValue(textPitchAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::AlignmentType>>(textPitchAlignment); self.rawLayer->setTextPitchAlignment(mbglValue); } -- (MGLStyleValue<NSValue *> *)textPitchAlignment { +- (NSExpression *)textPitchAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextPitchAlignment(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toEnumStyleValue(self.rawLayer->getDefaultTextPitchAlignment()); + propertyValue = self.rawLayer->getDefaultTextPitchAlignment(); } - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextPitchAlignment>().toExpression(propertyValue); } -- (void)setTextRotation:(MGLStyleValue<NSNumber *> *)textRotation { +- (void)setTextRotation:(NSExpression *)textRotation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textRotation); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textRotation); self.rawLayer->setTextRotate(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textRotation { +- (NSExpression *)textRotation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextRotate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextRotate()); + propertyValue = self.rawLayer->getDefaultTextRotate(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } -- (void)setTextRotate:(MGLStyleValue<NSNumber *> *)textRotate { +- (void)setTextRotate:(NSExpression *)textRotate { } -- (MGLStyleValue<NSNumber *> *)textRotate { +- (NSExpression *)textRotate { return self.textRotation; } -- (void)setTextRotationAlignment:(MGLStyleValue<NSValue *> *)textRotationAlignment { +- (void)setTextRotationAlignment:(NSExpression *)textRotationAlignment { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toEnumPropertyValue(textRotationAlignment); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::AlignmentType>>(textRotationAlignment); self.rawLayer->setTextRotationAlignment(mbglValue); } -- (MGLStyleValue<NSValue *> *)textRotationAlignment { +- (NSExpression *)textRotationAlignment { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextRotationAlignment(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toEnumStyleValue(self.rawLayer->getDefaultTextRotationAlignment()); + propertyValue = self.rawLayer->getDefaultTextRotationAlignment(); } - return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::AlignmentType, NSValue *, mbgl::style::AlignmentType, MGLTextRotationAlignment>().toExpression(propertyValue); } -- (void)setTextTransform:(MGLStyleValue<NSValue *> *)textTransform { +- (void)setTextTransform:(NSExpression *)textTransform { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toDataDrivenPropertyValue(textTransform); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::style::TextTransformType>>(textTransform); self.rawLayer->setTextTransform(mbglValue); } -- (MGLStyleValue<NSValue *> *)textTransform { +- (NSExpression *)textTransform { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextTransform(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextTransform()); + propertyValue = self.rawLayer->getDefaultTextTransform(); } - return MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TextTransformType, NSValue *, mbgl::style::TextTransformType, MGLTextTransform>().toExpression(propertyValue); } #pragma mark - Accessing the Paint Attributes -- (void)setIconColor:(MGLStyleValue<MGLColor *> *)iconColor { +- (void)setIconColor:(NSExpression *)iconColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(iconColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(iconColor); self.rawLayer->setIconColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)iconColor { +- (NSExpression *)iconColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconColor()); + propertyValue = self.rawLayer->getDefaultIconColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setIconColorTransition:(MGLTransition )transition { @@ -922,21 +922,21 @@ namespace mbgl { return transition; } -- (void)setIconHaloBlur:(MGLStyleValue<NSNumber *> *)iconHaloBlur { +- (void)setIconHaloBlur:(NSExpression *)iconHaloBlur { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(iconHaloBlur); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(iconHaloBlur); self.rawLayer->setIconHaloBlur(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconHaloBlur { +- (NSExpression *)iconHaloBlur { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconHaloBlur(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconHaloBlur()); + propertyValue = self.rawLayer->getDefaultIconHaloBlur(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setIconHaloBlurTransition:(MGLTransition )transition { @@ -957,21 +957,21 @@ namespace mbgl { return transition; } -- (void)setIconHaloColor:(MGLStyleValue<MGLColor *> *)iconHaloColor { +- (void)setIconHaloColor:(NSExpression *)iconHaloColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(iconHaloColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(iconHaloColor); self.rawLayer->setIconHaloColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)iconHaloColor { +- (NSExpression *)iconHaloColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconHaloColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconHaloColor()); + propertyValue = self.rawLayer->getDefaultIconHaloColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setIconHaloColorTransition:(MGLTransition )transition { @@ -992,21 +992,21 @@ namespace mbgl { return transition; } -- (void)setIconHaloWidth:(MGLStyleValue<NSNumber *> *)iconHaloWidth { +- (void)setIconHaloWidth:(NSExpression *)iconHaloWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(iconHaloWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(iconHaloWidth); self.rawLayer->setIconHaloWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconHaloWidth { +- (NSExpression *)iconHaloWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconHaloWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconHaloWidth()); + propertyValue = self.rawLayer->getDefaultIconHaloWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setIconHaloWidthTransition:(MGLTransition )transition { @@ -1027,21 +1027,21 @@ namespace mbgl { return transition; } -- (void)setIconOpacity:(MGLStyleValue<NSNumber *> *)iconOpacity { +- (void)setIconOpacity:(NSExpression *)iconOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(iconOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(iconOpacity); self.rawLayer->setIconOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)iconOpacity { +- (NSExpression *)iconOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultIconOpacity()); + propertyValue = self.rawLayer->getDefaultIconOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setIconOpacityTransition:(MGLTransition )transition { @@ -1062,21 +1062,21 @@ namespace mbgl { return transition; } -- (void)setIconTranslation:(MGLStyleValue<NSValue *> *)iconTranslation { +- (void)setIconTranslation:(NSExpression *)iconTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(iconTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(iconTranslation); self.rawLayer->setIconTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconTranslation { +- (NSExpression *)iconTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultIconTranslate()); + propertyValue = self.rawLayer->getDefaultIconTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setIconTranslationTransition:(MGLTransition )transition { @@ -1097,52 +1097,52 @@ namespace mbgl { return transition; } -- (void)setIconTranslate:(MGLStyleValue<NSValue *> *)iconTranslate { +- (void)setIconTranslate:(NSExpression *)iconTranslate { } -- (MGLStyleValue<NSValue *> *)iconTranslate { +- (NSExpression *)iconTranslate { return self.iconTranslation; } -- (void)setIconTranslationAnchor:(MGLStyleValue<NSValue *> *)iconTranslationAnchor { +- (void)setIconTranslationAnchor:(NSExpression *)iconTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslationAnchor>().toEnumPropertyValue(iconTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(iconTranslationAnchor); self.rawLayer->setIconTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)iconTranslationAnchor { +- (NSExpression *)iconTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getIconTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultIconTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultIconTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLIconTranslationAnchor>().toExpression(propertyValue); } -- (void)setIconTranslateAnchor:(MGLStyleValue<NSValue *> *)iconTranslateAnchor { +- (void)setIconTranslateAnchor:(NSExpression *)iconTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)iconTranslateAnchor { +- (NSExpression *)iconTranslateAnchor { return self.iconTranslationAnchor; } -- (void)setTextColor:(MGLStyleValue<MGLColor *> *)textColor { +- (void)setTextColor:(NSExpression *)textColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(textColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(textColor); self.rawLayer->setTextColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)textColor { +- (NSExpression *)textColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextColor()); + propertyValue = self.rawLayer->getDefaultTextColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setTextColorTransition:(MGLTransition )transition { @@ -1163,21 +1163,21 @@ namespace mbgl { return transition; } -- (void)setTextHaloBlur:(MGLStyleValue<NSNumber *> *)textHaloBlur { +- (void)setTextHaloBlur:(NSExpression *)textHaloBlur { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textHaloBlur); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textHaloBlur); self.rawLayer->setTextHaloBlur(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textHaloBlur { +- (NSExpression *)textHaloBlur { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextHaloBlur(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextHaloBlur()); + propertyValue = self.rawLayer->getDefaultTextHaloBlur(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setTextHaloBlurTransition:(MGLTransition )transition { @@ -1198,21 +1198,21 @@ namespace mbgl { return transition; } -- (void)setTextHaloColor:(MGLStyleValue<MGLColor *> *)textHaloColor { +- (void)setTextHaloColor:(NSExpression *)textHaloColor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenPropertyValue(textHaloColor); + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<mbgl::Color>>(textHaloColor); self.rawLayer->setTextHaloColor(mbglValue); } -- (MGLStyleValue<MGLColor *> *)textHaloColor { +- (NSExpression *)textHaloColor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextHaloColor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextHaloColor()); + propertyValue = self.rawLayer->getDefaultTextHaloColor(); } - return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toExpression(propertyValue); } - (void)setTextHaloColorTransition:(MGLTransition )transition { @@ -1233,21 +1233,21 @@ namespace mbgl { return transition; } -- (void)setTextHaloWidth:(MGLStyleValue<NSNumber *> *)textHaloWidth { +- (void)setTextHaloWidth:(NSExpression *)textHaloWidth { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textHaloWidth); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textHaloWidth); self.rawLayer->setTextHaloWidth(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textHaloWidth { +- (NSExpression *)textHaloWidth { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextHaloWidth(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextHaloWidth()); + propertyValue = self.rawLayer->getDefaultTextHaloWidth(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setTextHaloWidthTransition:(MGLTransition )transition { @@ -1268,21 +1268,21 @@ namespace mbgl { return transition; } -- (void)setTextOpacity:(MGLStyleValue<NSNumber *> *)textOpacity { +- (void)setTextOpacity:(NSExpression *)textOpacity { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenPropertyValue(textOpacity); + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue<mbgl::style::DataDrivenPropertyValue<float>>(textOpacity); self.rawLayer->setTextOpacity(mbglValue); } -- (MGLStyleValue<NSNumber *> *)textOpacity { +- (NSExpression *)textOpacity { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextOpacity(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextOpacity()); + propertyValue = self.rawLayer->getDefaultTextOpacity(); } - return MGLStyleValueTransformer<float, NSNumber *>().toDataDrivenStyleValue(propertyValue); + return MGLStyleValueTransformer<float, NSNumber *>().toExpression(propertyValue); } - (void)setTextOpacityTransition:(MGLTransition )transition { @@ -1303,21 +1303,21 @@ namespace mbgl { return transition; } -- (void)setTextTranslation:(MGLStyleValue<NSValue *> *)textTranslation { +- (void)setTextTranslation:(NSExpression *)textTranslation { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(textTranslation); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue<mbgl::style::PropertyValue<std::array<float, 2>>>(textTranslation); self.rawLayer->setTextTranslate(mbglValue); } -- (MGLStyleValue<NSValue *> *)textTranslation { +- (NSExpression *)textTranslation { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextTranslate(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultTextTranslate()); + propertyValue = self.rawLayer->getDefaultTextTranslate(); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toExpression(propertyValue); } - (void)setTextTranslationTransition:(MGLTransition )transition { @@ -1338,34 +1338,34 @@ namespace mbgl { return transition; } -- (void)setTextTranslate:(MGLStyleValue<NSValue *> *)textTranslate { +- (void)setTextTranslate:(NSExpression *)textTranslate { } -- (MGLStyleValue<NSValue *> *)textTranslate { +- (NSExpression *)textTranslate { return self.textTranslation; } -- (void)setTextTranslationAnchor:(MGLStyleValue<NSValue *> *)textTranslationAnchor { +- (void)setTextTranslationAnchor:(NSExpression *)textTranslationAnchor { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslationAnchor>().toEnumPropertyValue(textTranslationAnchor); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslationAnchor>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>>(textTranslationAnchor); self.rawLayer->setTextTranslateAnchor(mbglValue); } -- (MGLStyleValue<NSValue *> *)textTranslationAnchor { +- (NSExpression *)textTranslationAnchor { MGLAssertStyleLayerIsValid(); auto propertyValue = self.rawLayer->getTextTranslateAnchor(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultTextTranslateAnchor()); + propertyValue = self.rawLayer->getDefaultTextTranslateAnchor(); } - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslationAnchor>().toEnumStyleValue(propertyValue); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLTextTranslationAnchor>().toExpression(propertyValue); } -- (void)setTextTranslateAnchor:(MGLStyleValue<NSValue *> *)textTranslateAnchor { +- (void)setTextTranslateAnchor:(NSExpression *)textTranslateAnchor { } -- (MGLStyleValue<NSValue *> *)textTranslateAnchor { +- (NSExpression *)textTranslateAnchor { return self.textTranslationAnchor; } diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h index 6603570e25..7780a34c7f 100644 --- a/platform/darwin/src/MGLVectorStyleLayer.h +++ b/platform/darwin/src/MGLVectorStyleLayer.h @@ -34,108 +34,9 @@ MGL_EXPORT comes from the style, its predicate corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#layer-filter">`filter`</a> property in the style JSON. - - The following comparison operators are supported. - - <ul> - <li><code>NSEqualToPredicateOperatorType</code> (<code>=</code>, <code>==</code>)</li> - <li><code>NSGreaterThanOrEqualToPredicateOperatorType</code> (<code>>=</code>, <code>=></code>)</li> - <li><code>NSLessThanOrEqualToPredicateOperatorType</code> (<code><=</code>, <code>=<</code>)</li> - <li><code>NSGreaterThanPredicateOperatorType</code> (<code>></code>)</li> - <li><code>NSLessThanPredicateOperatorType</code> (<code><</code>)</li> - <li><code>NSNotEqualToPredicateOperatorType</code> (<code>!=</code>, <code><></code>)</li> - <li><code>NSBetweenPredicateOperatorType</code> (<code>BETWEEN</code>)</li> - </ul> - - The following compound operators are supported: - - <ul> - <li><code>NSAndPredicateType</code> (<code>AND</code>, <code>&&</code>)</li> - <li><code>NSOrPredicateType</code> (<code>OR</code>, <code>||</code>)</li> - <li><code>NSNotPredicateType</code> (<code>NOT</code>, <code>!</code>)</li> - </ul> - - The following aggregate operators are supported: - - <ul> - <li><code>NSInPredicateOperatorType</code> (<code>IN</code>)</li> - <li><code>NSContainsPredicateOperatorType</code> (<code>CONTAINS</code>)</li> - </ul> - - To test whether a feature has or lacks a specific attribute, compare the - attribute to `NULL` or `NIL`. Predicates created using the - `+[NSPredicate predicateWithValue:]` method are also supported. String - operators and custom operators are not supported. - - For details about the predicate format string syntax, consult the “Predicate - Format String Syntax” chapter of the - “<a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/">Predicate Programming Guide</a>” - in Apple developer documentation. - - The predicate's left-hand expression must be a string that identifies a feature - attribute or, alternatively, one of the following special attributes: - - <table> - <thead> - <tr><th>Attribute</th><th>Meaning</th></tr> - </thead> - <tbody> - <tr> - <td><code>$id</code></td> - <td> - A value that uniquely identifies the feature in the containing source. - For details on the types of values that may be associated with this key, - consult the documentation for the <code>MGLFeature</code> protocol’s - <code>identifier</code> property. - </td> - </tr> - <tr> - <td><code>$type</code></td> - <td> - The type of geometry represented by the feature. A feature’s type is - guaranteed to be one of the following strings: - <ul> - <li> - <code>Point</code> for point features, corresponding to the - <code>MGLPointAnnotation</code> class - </li> - <li> - <code>LineString</code> for polyline features, corresponding to - the <code>MGLPolyline</code> class - </li> - <li> - <code>Polygon</code> for polygon features, corresponding to the - <code>MGLPolygon</code> class - </li> - </ul> - </td> - </tr> - <tr> - <td><code>point_count</code></td> - <td>The number of point features in a given cluster.</td> - </tr> - </tbody> - </table> - - The predicate’s right-hand expression must be an `NSString` (to match strings) - or `NSNumber` (to match numbers, including Boolean values) or an array of - `NSString`s or `NSNumber`s, depending on the operator and the type of values - expected for the attribute being tested. For floating-point values, use - `-[NSNumber numberWithDouble:]` instead of `-[NSNumber numberWithFloat:]` - to avoid precision issues. - - Automatic type casting is not performed. Therefore, a feature only matches this - predicate if its value for the attribute in question is of the same type as the - value specified in the predicate. Also, operator modifiers such as `c` (for - case insensitivity), `d` (for diacritic insensitivity), and `l` (for locale - sensitivity) are unsupported for comparison and aggregate operators that are - used in the predicate. - - It is possible to create expressions that contain special characters in the - predicate format syntax. This includes the `$` in the `$id` and `$type` special - style attributes and also `hyphen-minus` and `tag:subtag`. However, you must use - `%K` in the format string to represent these variables: - `@"%K == 'LineString'", @"$type"`. + + See the “<a href="../predicates-and-expressions.html">Predicates and Expressions</a>” + guide for details about the predicate syntax supported by this class. ### Example diff --git a/platform/darwin/src/NSArray+MGLAdditions.mm b/platform/darwin/src/NSArray+MGLAdditions.mm index 3cab7ff427..195e96b09d 100644 --- a/platform/darwin/src/NSArray+MGLAdditions.mm +++ b/platform/darwin/src/NSArray+MGLAdditions.mm @@ -1,7 +1,7 @@ #import "NSArray+MGLAdditions.h" #import "NSDictionary+MGLAdditions.h" -#import "NSExpression+MGLAdditions.mm" +#import "NSExpression+MGLPrivateAdditions.h" @implementation NSArray (MGLAdditions) diff --git a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm index ac2d598d05..5b54d66aeb 100644 --- a/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSComparisonPredicate+MGLAdditions.mm @@ -1,7 +1,7 @@ #import "NSComparisonPredicate+MGLAdditions.h" #import "NSPredicate+MGLAdditions.h" -#import "NSExpression+MGLAdditions.h" +#import "NSExpression+MGLPrivateAdditions.h" @implementation NSComparisonPredicate (MGLAdditions) @@ -294,3 +294,45 @@ } @end + +@implementation NSComparisonPredicate (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + NSString *op; + switch (self.predicateOperatorType) { + case NSLessThanPredicateOperatorType: + op = @"<"; + break; + case NSLessThanOrEqualToPredicateOperatorType: + op = @"<="; + break; + case NSGreaterThanPredicateOperatorType: + op = @">"; + break; + case NSGreaterThanOrEqualToPredicateOperatorType: + op = @">="; + break; + case NSEqualToPredicateOperatorType: + op = @"=="; + break; + case NSNotEqualToPredicateOperatorType: + op = @"!="; + break; + case NSMatchesPredicateOperatorType: + case NSLikePredicateOperatorType: + case NSBeginsWithPredicateOperatorType: + case NSEndsWithPredicateOperatorType: + case NSInPredicateOperatorType: + case NSCustomSelectorPredicateOperatorType: + case NSContainsPredicateOperatorType: + case NSBetweenPredicateOperatorType: + [NSException raise:NSInvalidArgumentException + format:@"NSPredicateOperatorType:%lu is not supported.", (unsigned long)self.predicateOperatorType]; + } + if (op) { + return @[op, self.leftExpression.mgl_jsonExpressionObject, self.rightExpression.mgl_jsonExpressionObject]; + } + return nil; +} + +@end diff --git a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm index 0039b5af82..19568b8033 100644 --- a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm @@ -1,7 +1,7 @@ #import "NSCompoundPredicate+MGLAdditions.h" #import "NSPredicate+MGLAdditions.h" -#import "NSExpression+MGLAdditions.h" +#import "NSExpression+MGLPrivateAdditions.h" @implementation NSCompoundPredicate (MGLAdditions) @@ -71,3 +71,31 @@ } @end + +@implementation NSCompoundPredicate (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + switch (self.compoundPredicateType) { + case NSNotPredicateType: { + NSAssert(self.subpredicates.count <= 1, @"NOT predicate cannot have multiple subpredicates."); + NSPredicate *subpredicate = self.subpredicates.firstObject; + return @[@"!", subpredicate.mgl_jsonExpressionObject]; + } + + case NSAndPredicateType: { + NSArray *subarrays = [self.subpredicates valueForKeyPath:@"mgl_jsonExpressionObject"]; + return [@[@"all"] arrayByAddingObjectsFromArray:subarrays]; + } + + case NSOrPredicateType: { + NSArray *subarrays = [self.subpredicates valueForKeyPath:@"mgl_jsonExpressionObject"]; + return [@[@"any"] arrayByAddingObjectsFromArray:subarrays]; + } + } + + [NSException raise:@"Compound predicate type not handled" + format:@""]; + return nil; +} + +@end diff --git a/platform/darwin/src/NSDictionary+MGLAdditions.mm b/platform/darwin/src/NSDictionary+MGLAdditions.mm index aad7fd8810..4bc7ddb3cf 100644 --- a/platform/darwin/src/NSDictionary+MGLAdditions.mm +++ b/platform/darwin/src/NSDictionary+MGLAdditions.mm @@ -1,6 +1,6 @@ #import "NSDictionary+MGLAdditions.h" -#import "NSExpression+MGLAdditions.mm" +#import "NSExpression+MGLPrivateAdditions.h" #import "NSArray+MGLAdditions.h" @implementation NSDictionary (MGLAdditions) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 491ed5a536..b4d36bc1b1 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -1,17 +1,46 @@ #import <Foundation/Foundation.h> +#if TARGET_OS_IPHONE + #import <UIKit/UIKit.h> +#else + #import <Cocoa/Cocoa.h> +#endif -#include <mbgl/style/filter.hpp> +#import "MGLTypes.h" NS_ASSUME_NONNULL_BEGIN @interface NSExpression (MGLAdditions) -@property (nonatomic, readonly) mbgl::Value mgl_constantMBGLValue; -@property (nonatomic, readonly) std::vector<mbgl::Value> mgl_aggregateMBGLValue; -@property (nonatomic, readonly) mbgl::FeatureType mgl_featureType; -@property (nonatomic, readonly) std::vector<mbgl::FeatureType> mgl_aggregateFeatureType; -@property (nonatomic, readonly) mbgl::FeatureIdentifier mgl_featureIdentifier; -@property (nonatomic, readonly) std::vector<mbgl::FeatureIdentifier> mgl_aggregateFeatureIdentifier; +/** + Returns an expression equivalent to the given Foundation object deserialized + from JSON data. + + The Foundation object is interpreted according to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the “[Predicates and Expressions](../predicates-and-expressions.html)” + guide for a correspondence of operators and types between the style + specification and the `NSExpression` representation used by this SDK. + + @param object A Foundation object deserialized from JSON data, for example + using `NSJSONSerialization`. + @return An initialized expression equivalent to `object`, suitable for use as + the value of a style layer attribute. + */ ++ (instancetype)mgl_expressionWithJSONObject:(id)object; + +/** + An equivalent Foundation object that can be serialized as JSON. + + The Foundation object conforms to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the “[Predicates and Expressions](../predicates-and-expressions.html)” + guide for a correspondence of operators and types between the style + specification and the `NSExpression` representation used by this SDK. + + You can use `NSJSONSerialization` to serialize the Foundation object as data to + write to a file. + */ +@property (nonatomic, readonly) id mgl_jsonExpressionObject; @end diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index a7759cda9d..5ad565c398 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1,13 +1,19 @@ -#import "NSExpression+MGLAdditions.h" +#import "NSExpression+MGLPrivateAdditions.h" #import "MGLTypes.h" #if TARGET_OS_IPHONE #import "UIColor+MGLAdditions.h" + #define MGLEdgeInsets UIEdgeInsets #else #import "NSColor+MGLAdditions.h" + #define MGLEdgeInsets NSEdgeInsets #endif +#import "NSPredicate+MGLAdditions.h" +#import "NSValue+MGLStyleAttributeAdditions.h" -@implementation NSExpression (MGLAdditions) +#import <mbgl/style/expression/expression.hpp> + +@implementation NSExpression (MGLPrivateAdditions) - (std::vector<mbgl::Value>)mgl_aggregateMBGLValue { if ([self.constantValue isKindOfClass:[NSArray class]] || [self.constantValue isKindOfClass:[NSSet class]]) { @@ -154,3 +160,578 @@ } @end + +@implementation NSObject (MGLExpressionAdditions) + +- (NSNumber *)mgl_number { + return nil; +} + +- (NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... { + if (self.mgl_number) { + return self.mgl_number; + } + + va_list fallbackValues; + va_start(fallbackValues, fallbackValue); + for (id value = fallbackValue; value; value = va_arg(fallbackValues, id)) { + if ([value mgl_number]) { + return [value mgl_number]; + } + } + + return nil; +} + +@end + +@implementation NSNull (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + return self; +} + +@end + +@implementation NSString (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + return self; +} + +- (NSNumber *)mgl_number { + if (self.doubleValue || ![[NSDecimalNumber decimalNumberWithString:self] isEqual:[NSDecimalNumber notANumber]]) { + return @(self.doubleValue); + } + + return nil; +} + +@end + +@implementation NSNumber (MGLExpressionAdditions) + +- (id)mgl_interpolateWithCurveType:(NSString *)curveType + parameters:(NSArray *)parameters + stops:(NSDictionary<NSNumber *, id> *)stops { + [NSException raise:NSInvalidArgumentException + format:@"Interpolation expressions lack underlying Objective-C implementations."]; + return nil; +} + +- (id)mgl_stepWithMinimum:(id)minimum stops:(NSDictionary<NSNumber *, id> *)stops { + [NSException raise:NSInvalidArgumentException + format:@"Interpolation expressions lack underlying Objective-C implementations."]; + return nil; +} + +- (NSNumber *)mgl_number { + return self; +} + +- (id)mgl_jsonExpressionObject { + if ([self isEqualToNumber:@(M_E)]) { + return @[@"e"]; + } else if ([self isEqualToNumber:@(M_PI)]) { + return @[@"pi"]; + } + return self; +} + +@end + +@implementation MGLColor (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + auto color = [self mgl_color]; + if (color.a == 1) { + return @[@"rgb", @(color.r * 255), @(color.g * 255), @(color.b * 255)]; + } + return @[@"rgba", @(color.r * 255), @(color.g * 255), @(color.b * 255), @(color.a)]; +} + +@end + +@implementation NSArray (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + return [self valueForKeyPath:@"mgl_jsonExpressionObject"]; +} + +@end + +@implementation NSDictionary (MGLExpressionAdditions) + +- (id)mgl_jsonExpressionObject { + NSMutableDictionary *expressionObject = [NSMutableDictionary dictionaryWithCapacity:self.count]; + [self enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + expressionObject[[key mgl_jsonExpressionObject]] = [obj mgl_jsonExpressionObject]; + }]; + + return expressionObject; +} + +@end + +@implementation NSExpression (MGLExpressionAdditions) + +- (NSExpression *)mgl_expressionWithContext:(NSDictionary<NSString *, NSExpression *> *)context { + [NSException raise:NSInternalInconsistencyException + format:@"Assignment expressions lack underlying Objective-C implementations."]; + return self; +} + +@end + +@implementation NSExpression (MGLAdditions) + +static NSDictionary<NSString *, NSString *> *MGLFunctionNamesByExpressionOperator; +static NSDictionary<NSString *, NSString *> *MGLExpressionOperatorsByFunctionNames; + +NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { + NSMutableArray *subexpressions = [NSMutableArray arrayWithCapacity:objects.count]; + for (id object in objects) { + NSExpression *expression = [NSExpression mgl_expressionWithJSONObject:object]; + [subexpressions addObject:expression]; + } + return subexpressions; +} + ++ (instancetype)mgl_expressionWithJSONObject:(id)object { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + MGLFunctionNamesByExpressionOperator = @{ + @"+": @"add:to:", + @"-": @"from:subtract:", + @"*": @"multiply:by:", + @"/": @"divide:by:", + @"%": @"modulus:by:", + @"sqrt": @"sqrt:", + @"log10": @"log:", + @"ln": @"ln:", + @"^": @"raise:toPower:", + @"upcase": @"uppercase:", + @"downcase": @"lowercase:", + }; + }); + + if (!object || object == [NSNull null]) { + return [NSExpression expressionForConstantValue:nil]; + } + + if ([object isKindOfClass:[NSString class]] || + [object isKindOfClass:[NSNumber class]] || + [object isKindOfClass:[NSValue class]] || + [object isKindOfClass:[MGLColor class]]) { + return [NSExpression expressionForConstantValue:object]; + } + + if ([object isKindOfClass:[NSDictionary class]]) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:[object count]]; + [object enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + dictionary[key] = [NSExpression mgl_expressionWithJSONObject:obj]; + }]; + return [NSExpression expressionForConstantValue:dictionary]; + } + + if ([object isKindOfClass:[NSArray class]]) { + NSArray *array = (NSArray *)object; + NSString *op = array.firstObject; + + NSArray *argumentObjects = [array subarrayWithRange:NSMakeRange(1, array.count - 1)]; + + NSString *functionName = MGLFunctionNamesByExpressionOperator[op]; + if (functionName) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + if ([op isEqualToString:@"+"] && argumentObjects.count > 2) { + NSExpression *subexpression = [NSExpression expressionForAggregate:subexpressions]; + return [NSExpression expressionForFunction:@"sum:" + arguments:@[subexpression]]; + } else if ([op isEqualToString:@"^"] && [argumentObjects.firstObject isEqual:@[@"e"]]) { + functionName = @"exp:"; + subexpressions = [subexpressions subarrayWithRange:NSMakeRange(1, subexpressions.count - 1)]; + } + + return [NSExpression expressionForFunction:functionName + arguments:subexpressions]; + } else if ([op isEqualToString:@"literal"]) { + if ([argumentObjects.firstObject isKindOfClass:[NSArray class]]) { + return [NSExpression expressionForAggregate:MGLSubexpressionsWithJSONObjects(argumentObjects.firstObject)]; + } + return [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + } else if ([op isEqualToString:@"to-boolean"]) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + return [NSExpression expressionForFunction:operand selectorName:@"boolValue" arguments:@[]]; + } else if ([op isEqualToString:@"to-number"]) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + return [NSExpression expressionForFunction:operand selectorName:@"mgl_numberWithFallbackValues:" arguments:subexpressions]; + } else if ([op isEqualToString:@"to-string"]) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + return [NSExpression expressionForFunction:operand selectorName:@"stringValue" arguments:@[]]; + } else if ([op isEqualToString:@"get"]) { + if (argumentObjects.count == 2) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.lastObject]; + if ([argumentObjects.firstObject isKindOfClass:[NSString class]]) { + return [NSExpression expressionWithFormat:@"%@.%K", operand, argumentObjects.firstObject]; + } + NSExpression *key = [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + return [NSExpression expressionWithFormat:@"%@.%@", operand, key]; + } + return [NSExpression expressionForKeyPath:argumentObjects.firstObject]; + } else if ([op isEqualToString:@"length"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + return [NSExpression expressionForFunction:@"count:" arguments:@[subexpressions.firstObject]]; + } else if ([op isEqualToString:@"min"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + NSExpression *subexpression = [NSExpression expressionForAggregate:subexpressions]; + return [NSExpression expressionForFunction:@"min:" arguments:@[subexpression]]; + } else if ([op isEqualToString:@"max"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + NSExpression *subexpression = [NSExpression expressionForAggregate:subexpressions]; + return [NSExpression expressionForFunction:@"max:" arguments:@[subexpression]]; + } else if ([op isEqualToString:@"e"]) { + return [NSExpression expressionForConstantValue:@(M_E)]; + } else if ([op isEqualToString:@"pi"]) { + return [NSExpression expressionForConstantValue:@(M_PI)]; + } else if ([op isEqualToString:@"concat"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(argumentObjects); + NSExpression *operand = subexpressions.firstObject; + subexpressions = [subexpressions subarrayWithRange:NSMakeRange(1, subexpressions.count - 1)]; + return [NSExpression expressionForFunction:operand selectorName:@"stringByAppendingString:" arguments:subexpressions]; + } else if ([op isEqualToString:@"interpolate"]) { + NSArray *interpolationOptions = argumentObjects.firstObject; + NSString *curveType = interpolationOptions.firstObject; + NSExpression *curveTypeExpression = [NSExpression mgl_expressionWithJSONObject:curveType]; + id curveParameters; + if ([curveType isEqual:@"exponential"]) { + curveParameters = interpolationOptions[1]; + } else if ([curveType isEqualToString:@"cubic-bezier"]) { + curveParameters = @[@"literal", [interpolationOptions subarrayWithRange:NSMakeRange(1, 4)]]; + } + NSExpression *curveParameterExpression = [NSExpression mgl_expressionWithJSONObject:curveParameters]; + argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.firstObject]; + NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; + NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; + while (NSNumber *key = stopEnumerator.nextObject) { + NSExpression *valueExpression = stopEnumerator.nextObject; + stops[key] = [NSExpression mgl_expressionWithJSONObject:valueExpression]; + } + NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; + return [NSExpression expressionForFunction:operand + selectorName:@"mgl_interpolateWithCurveType:parameters:stops:" + arguments:@[curveTypeExpression, curveParameterExpression, stopExpression]]; + } else if ([op isEqualToString:@"step"]) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects[0]]; + NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSExpression *minimum; + if (stopExpressions.count % 2) { + minimum = [NSExpression mgl_expressionWithJSONObject:stopExpressions.firstObject]; + stopExpressions = [stopExpressions subarrayWithRange:NSMakeRange(1, stopExpressions.count - 1)]; + } + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; + NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; + while (NSNumber *key = stopEnumerator.nextObject) { + NSExpression *valueExpression = stopEnumerator.nextObject; + if (minimum) { + stops[key] = [NSExpression mgl_expressionWithJSONObject:valueExpression]; + } else { + minimum = [NSExpression mgl_expressionWithJSONObject:valueExpression]; + } + } + NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; + return [NSExpression expressionForFunction:operand + selectorName:@"mgl_stepWithMinimum:stops:" + arguments:@[minimum, stopExpression]]; + } else if ([op isEqualToString:@"zoom"]) { + return [NSExpression expressionForVariable:@"zoomLevel"]; + } else if ([op isEqualToString:@"heatmap-density"]) { + return [NSExpression expressionForVariable:@"heatmapDensity"]; + } else if ([op isEqualToString:@"let"]) { + NSExpression *operand = [NSExpression mgl_expressionWithJSONObject:argumentObjects.lastObject]; + NSArray *bindingObjects = [argumentObjects subarrayWithRange:NSMakeRange(0, argumentObjects.count - 1)]; + NSMutableDictionary *context = [NSMutableDictionary dictionaryWithCapacity:bindingObjects.count / 2]; + NSEnumerator *bindingEnumerator = bindingObjects.objectEnumerator; + while (NSString *key = bindingEnumerator.nextObject) { + context[key] = [NSExpression mgl_expressionWithJSONObject:bindingEnumerator.nextObject]; + } + return [NSExpression expressionForFunction:operand + selectorName:@"mgl_expressionWithContext:" + arguments:@[[NSExpression expressionForConstantValue:context]]]; + } else if ([op isEqualToString:@"var"]) { + return [NSExpression expressionForVariable:argumentObjects.firstObject]; + } else if ([op isEqualToString:@"case"]) { + NSPredicate *conditional = [NSPredicate mgl_predicateWithJSONObject:argumentObjects.firstObject]; + NSExpression *trueExpression = [NSExpression mgl_expressionWithJSONObject:argumentObjects[1]]; + NSExpression *falseExpression; + if (argumentObjects.count > 3) { + NSArray *falseObjects = [@[@"case"] arrayByAddingObjectsFromArray: + [argumentObjects subarrayWithRange:NSMakeRange(2, argumentObjects.count - 2)]]; + falseExpression = [NSExpression mgl_expressionWithJSONObject:falseObjects]; + } else { + falseExpression = [NSExpression mgl_expressionWithJSONObject:argumentObjects[2]]; + } + return [NSExpression expressionForConditional:conditional trueExpression:trueExpression falseExpression:falseExpression]; + } else { + [NSException raise:NSInvalidArgumentException + format:@"Expression operator %@ not yet implemented.", op]; + } + } + + [NSException raise:NSInvalidArgumentException + format:@"Unable to convert JSON object %@ to an NSExpression.", object]; + + return nil; +} + +- (id)mgl_jsonExpressionObject { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + MGLExpressionOperatorsByFunctionNames = @{ + @"add:to:": @"+", + @"from:subtract:": @"-", + @"multiply:by:": @"*", + @"divide:by:": @"/", + @"modulus:by:": @"%", + @"sqrt:": @"sqrt", + @"log:": @"log10", + @"ln:": @"ln", + @"raise:toPower:": @"^", + @"uppercase:": @"upcase", + @"lowercase:": @"downcase", + }; + }); + + switch (self.expressionType) { + case NSVariableExpressionType: { + if ([self.variable isEqualToString:@"heatmapDensity"]) { + return @[@"heatmap-density"]; + } + if ([self.variable isEqualToString:@"zoomLevel"]) { + return @[@"zoom"]; + } + return @[@"var", self.variable]; + } + + case NSConstantValueExpressionType: { + id constantValue = self.constantValue; + if (!constantValue || constantValue == [NSNull null]) { + return [NSNull null]; + } + if ([constantValue isEqual:@(M_E)]) { + return @[@"e"]; + } + if ([constantValue isEqual:@(M_PI)]) { + return @[@"pi"]; + } + if ([constantValue isKindOfClass:[NSArray class]] || + [constantValue isKindOfClass:[NSDictionary class]]) { + NSArray *collection = [constantValue mgl_jsonExpressionObject]; + return @[@"literal", collection]; + } + if ([constantValue isKindOfClass:[MGLColor class]]) { + auto color = [constantValue mgl_color]; + if (color.a == 1) { + return @[@"rgb", @(color.r * 255), @(color.g * 255), @(color.b * 255)]; + } + return @[@"rgba", @(color.r * 255), @(color.g * 255), @(color.b * 255), @(color.a)]; + } + if ([constantValue isKindOfClass:[NSValue class]]) { + const auto boxedValue = (NSValue *)constantValue; + if (strcmp([boxedValue objCType], @encode(CGVector)) == 0) { + // offset [x, y] + std::array<float, 2> mglValue = boxedValue.mgl_offsetArrayValue; + return @[@"literal", @[@(mglValue[0]), @(mglValue[1])]]; + } + if (strcmp([boxedValue objCType], @encode(MGLEdgeInsets)) == 0) { + // padding [x, y] + std::array<float, 4> mglValue = boxedValue.mgl_paddingArrayValue; + return @[@"literal", @[@(mglValue[0]), @(mglValue[1]), @(mglValue[2]), @(mglValue[3])]]; + } + } + return self.constantValue; + } + + case NSKeyPathExpressionType: { + NSArray *expressionObject; + for (NSString *pathComponent in self.keyPath.pathComponents.reverseObjectEnumerator) { + if (expressionObject) { + expressionObject = @[@"get", pathComponent, expressionObject]; + } else { + expressionObject = @[@"get", pathComponent]; + } + } + return expressionObject; + } + + case NSFunctionExpressionType: { + NSString *function = self.function; + NSString *op = MGLExpressionOperatorsByFunctionNames[function]; + if (op) { + NSArray *arguments = self.arguments.mgl_jsonExpressionObject; + return [@[op] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"valueForKeyPath:"]) { + return @[@"get", self.arguments.firstObject.mgl_jsonExpressionObject, self.operand.mgl_jsonExpressionObject]; + } else if ([function isEqualToString:@"average:"]) { + NSExpression *sum = [NSExpression expressionForFunction:@"sum:" arguments:self.arguments]; + NSExpression *count = [NSExpression expressionForFunction:@"count:" arguments:self.arguments]; + return [NSExpression expressionForFunction:@"divide:by:" arguments:@[sum, count]].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"sum:"]) { + NSArray *arguments = [self.arguments.firstObject.collection valueForKeyPath:@"mgl_jsonExpressionObject"]; + return [@[@"+"] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"count:"]) { + NSArray *arguments = self.arguments.firstObject.mgl_jsonExpressionObject; + return @[@"length", arguments]; + } else if ([function isEqualToString:@"min:"]) { + NSArray *arguments = [self.arguments.firstObject.collection valueForKeyPath:@"mgl_jsonExpressionObject"]; + return [@[@"min"] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"max:"]) { + NSArray *arguments = [self.arguments.firstObject.collection valueForKeyPath:@"mgl_jsonExpressionObject"]; + return [@[@"max"] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"exp:"]) { + return [NSExpression expressionForFunction:@"raise:toPower:" arguments:@[@(M_E), self.arguments.firstObject]].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"ceiling:"]) { + return [NSExpression expressionWithFormat:@"trunc:(%@) + TERNARY(modulus:by:(%@, 1) > 0, 1, 0)", + self.arguments.firstObject, self.arguments.firstObject].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"trunc:"]) { + return [NSExpression expressionWithFormat:@"%@ - modulus:by:(%@, 1)", + self.arguments.firstObject, self.arguments.firstObject].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"abs:"]) { + return [NSExpression expressionWithFormat:@"%@ * TERNARY(%@ > 0, 1, -1)", + self.arguments.firstObject, self.arguments.firstObject].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"floor:"]) { + return [NSExpression expressionWithFormat:@"trunc:(%@) - TERNARY(modulus:by:(%@, 1) < 0, 1, 0)", + self.arguments.firstObject, self.arguments.firstObject].mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"stringByAppendingString:"]) { + NSArray *arguments = self.arguments.mgl_jsonExpressionObject; + return [@[@"concat", self.operand.mgl_jsonExpressionObject] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"boolValue"]) { + return @[@"to-boolean", self.operand.mgl_jsonExpressionObject]; + } else if ([function isEqualToString:@"mgl_numberWithFallbackValues:"] || + [function isEqualToString:@"decimalValue"] || + [function isEqualToString:@"floatValue"] || + [function isEqualToString:@"doubleValue"]) { + NSArray *arguments = self.arguments.mgl_jsonExpressionObject; + return [@[@"to-number", self.operand.mgl_jsonExpressionObject] arrayByAddingObjectsFromArray:arguments]; + } else if ([function isEqualToString:@"stringValue"]) { + return @[@"to-string", self.operand.mgl_jsonExpressionObject]; + } else if ([function isEqualToString:@"noindex:"]) { + return self.arguments.firstObject.mgl_jsonExpressionObject; + } else if ([function isEqualToString:@"mgl_interpolateWithCurveType:parameters:stops:"]) { + if (self.arguments.count < 3) { + [NSException raise:NSInvalidArgumentException format: + @"Too few arguments to ‘mgl_interpolateWithCurveType:parameters:stops:’ function; expected 3 arguments."]; + } else if (self.arguments.count > 3) { + [NSException raise:NSInvalidArgumentException format: + @"%lu unexpected arguments to ‘mgl_interpolateWithCurveType:parameters:stops:’ function; expected 3 arguments.", + self.arguments.count - 3]; + } + NSString *curveType = self.arguments.firstObject.constantValue; + NSMutableArray *interpolationArray = [NSMutableArray arrayWithObject:curveType]; + if ([curveType isEqualToString:@"exponential"]) { + id base = [self.arguments[1] mgl_jsonExpressionObject]; + [interpolationArray addObject:base]; + } else if ([curveType isEqualToString:@"cubic-bezier"]) { + NSArray *controlPoints = [self.arguments[1].collection mgl_jsonExpressionObject]; + [interpolationArray addObjectsFromArray:controlPoints]; + } + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"interpolate", interpolationArray, self.operand.mgl_jsonExpressionObject, nil]; + NSDictionary<NSNumber *, NSExpression *> *stops = self.arguments[2].constantValue; + for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) { + [expressionObject addObject:key]; + [expressionObject addObject:[stops[key] mgl_jsonExpressionObject]]; + } + return expressionObject; + } else if ([function isEqualToString:@"mgl_stepWithMinimum:stops:"]) { + id minimum = self.arguments.firstObject.mgl_jsonExpressionObject; + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", self.operand.mgl_jsonExpressionObject, minimum, nil]; + NSDictionary<NSNumber *, NSExpression *> *stops = self.arguments[1].constantValue; + for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) { + [expressionObject addObject:key]; + [expressionObject addObject:[stops[key] mgl_jsonExpressionObject]]; + } + return expressionObject; + } else if ([function isEqualToString:@"mgl_expressionWithContext:"]) { + id context = self.arguments.firstObject; + if ([context isKindOfClass:[NSExpression class]]) { + context = [context constantValue]; + } + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"let", nil]; + [context enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, NSExpression * _Nonnull obj, BOOL * _Nonnull stop) { + [expressionObject addObject:key]; + [expressionObject addObject:obj.mgl_jsonExpressionObject]; + }]; + [expressionObject addObject:self.operand.mgl_jsonExpressionObject]; + return expressionObject; + } else if ([function isEqualToString:@"median:"] || + [function isEqualToString:@"mode:"] || + [function isEqualToString:@"stddev:"] || + [function isEqualToString:@"random"] || + [function isEqualToString:@"randomn:"] || + [function isEqualToString:@"now"] || + [function isEqualToString:@"bitwiseAnd:with:"] || + [function isEqualToString:@"bitwiseOr:with:"] || + [function isEqualToString:@"bitwiseXor:with:"] || + [function isEqualToString:@"leftshift:by:"] || + [function isEqualToString:@"rightshift:by:"] || + [function isEqualToString:@"onesComplement:"] || + [function isEqualToString:@"distanceToLocation:fromLocation:"]) { + [NSException raise:NSInvalidArgumentException + format:@"Expression function %@ not yet implemented.", function]; + return nil; + } else { + [NSException raise:NSInvalidArgumentException + format:@"Unrecognized expression function %@.", function]; + return nil; + } + } + + case NSConditionalExpressionType: { + NSMutableArray *arguments = [NSMutableArray arrayWithObjects:self.predicate.mgl_jsonExpressionObject, self.trueExpression.mgl_jsonExpressionObject, nil]; + if (self.falseExpression.expressionType == NSConditionalExpressionType) { + // Fold nested conditionals into a single case expression. + NSArray *falseArguments = self.falseExpression.mgl_jsonExpressionObject; + falseArguments = [falseArguments subarrayWithRange:NSMakeRange(1, falseArguments.count - 1)]; + [arguments addObjectsFromArray:falseArguments]; + } else { + [arguments addObject:self.falseExpression.mgl_jsonExpressionObject]; + } + + [arguments insertObject:@"case" atIndex:0]; + return arguments; + } + + case NSAggregateExpressionType: { + NSArray *collection = [self.collection valueForKeyPath:@"mgl_jsonExpressionObject"]; + return @[@"literal", collection]; + } + + case NSEvaluatedObjectExpressionType: + case NSUnionSetExpressionType: + case NSIntersectSetExpressionType: + case NSMinusSetExpressionType: + case NSSubqueryExpressionType: + case NSAnyKeyExpressionType: + case NSBlockExpressionType: + [NSException raise:NSInvalidArgumentException + format:@"Expression type %lu not yet implemented.", self.expressionType]; + } + + // NSKeyPathSpecifierExpression + if (self.expressionType == 10) { + return self.description; + } + // An assignment expression type is present in the BNF grammar, but the + // corresponding NSExpressionType value and property getters are missing. + if (self.expressionType == 12) { + [NSException raise:NSInvalidArgumentException + format:@"Assignment expressions not yet implemented."]; + } + + return nil; +} + +@end diff --git a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h new file mode 100644 index 0000000000..8d1b4d6af5 --- /dev/null +++ b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h @@ -0,0 +1,79 @@ +#import <Foundation/Foundation.h> +#if TARGET_OS_IPHONE + #import <UIKit/UIKit.h> +#else + #import <Cocoa/Cocoa.h> +#endif + +#import "NSExpression+MGLAdditions.h" + +#include <mbgl/style/filter.hpp> + +NS_ASSUME_NONNULL_BEGIN + +@interface NSObject (MGLExpressionAdditions) + +- (NSNumber *)mgl_number; +- (NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION; + +@end + +@interface NSExpression (MGLPrivateAdditions) + +@property (nonatomic, readonly) mbgl::Value mgl_constantMBGLValue; +@property (nonatomic, readonly) std::vector<mbgl::Value> mgl_aggregateMBGLValue; +@property (nonatomic, readonly) mbgl::FeatureType mgl_featureType; +@property (nonatomic, readonly) std::vector<mbgl::FeatureType> mgl_aggregateFeatureType; +@property (nonatomic, readonly) mbgl::FeatureIdentifier mgl_featureIdentifier; +@property (nonatomic, readonly) std::vector<mbgl::FeatureIdentifier> mgl_aggregateFeatureIdentifier; + +@end + +@interface NSNull (MGLExpressionAdditions) + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface NSString (MGLExpressionAdditions) + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface NSNumber (MGLExpressionAdditions) + +- (id)mgl_interpolateWithCurveType:(NSString *)curveType parameters:(NSArray *)parameters stops:(NSDictionary<NSNumber *, id> *)stops; +- (id)mgl_stepWithMinimum:(id)minimum stops:(NSDictionary<NSNumber *, id> *)stops; + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface NSArray (MGLExpressionAdditions) + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface NSDictionary (MGLExpressionAdditions) + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface MGLColor (MGLExpressionAdditions) + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end + +@interface NSExpression (MGLExpressionAdditions) + +- (NSExpression *)mgl_expressionWithContext:(NSDictionary<NSString *, NSExpression *> *)context; + +@end + +extern NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects); + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.h b/platform/darwin/src/NSPredicate+MGLAdditions.h index fd774dd58b..89e9e65c64 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.h +++ b/platform/darwin/src/NSPredicate+MGLAdditions.h @@ -1,7 +1,6 @@ #import <Foundation/Foundation.h> -#import "NSExpression+MGLAdditions.h" -#include <mbgl/style/filter.hpp> +#import "NSExpression+MGLPrivateAdditions.h" @interface NSPredicate (MGLAdditions) @@ -11,3 +10,10 @@ @end +@interface NSPredicate (MGLExpressionAdditions) + ++ (instancetype)mgl_predicateWithJSONObject:(id)object; + +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + +@end diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm index e0511d8740..3ffe200d01 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm @@ -228,3 +228,94 @@ public: } @end + +@implementation NSPredicate (MGLExpressionAdditions) + +NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) { + NSMutableArray *subpredicates = [NSMutableArray arrayWithCapacity:objects.count]; + for (id object in objects) { + NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:object]; + [subpredicates addObject:predicate]; + } + return subpredicates; +} + ++ (instancetype)mgl_predicateWithJSONObject:(id)object { + if ([object isEqual:@YES]) { + return [NSPredicate predicateWithValue:YES]; + } + if ([object isEqual:@NO]) { + return [NSPredicate predicateWithValue:NO]; + } + + NSAssert([object isKindOfClass:[NSArray class]], @"Condition for case expression should be an expression."); + NSArray *objects = (NSArray *)object; + NSString *op = objects.firstObject; + + if ([op isEqualToString:@"=="]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%@ == %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@"!="]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%@ != %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@"<"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%@ < %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@"<="]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%@ <= %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@">"]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%@ > %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@">="]) { + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSPredicate predicateWithFormat:@"%K >= %@" argumentArray:subexpressions]; + } + if ([op isEqualToString:@"!"]) { + NSArray *subpredicates = MGLSubpredicatesWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + if (subpredicates.count > 1) { + NSCompoundPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates]; + return [NSCompoundPredicate notPredicateWithSubpredicate:predicate]; + } + if (subpredicates.count) { + return [NSCompoundPredicate notPredicateWithSubpredicate:subpredicates.firstObject]; + } + return [NSPredicate predicateWithValue:YES]; + } + if ([op isEqualToString:@"all"]) { + NSArray *subpredicates = MGLSubpredicatesWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates]; + } + if ([op isEqualToString:@"any"]) { + NSArray *subpredicates = MGLSubpredicatesWithJSONObjects([objects subarrayWithRange:NSMakeRange(1, objects.count - 1)]); + return [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates]; + } + + NSAssert(NO, @"Unrecognized expression conditional operator %@.", op); + return nil; +} + +- (id)mgl_jsonExpressionObject { + if ([self isEqual:[NSPredicate predicateWithValue:YES]]) { + return @YES; + } + if ([self isEqual:[NSPredicate predicateWithValue:NO]]) { + return @NO; + } + + if ([self.predicateFormat hasPrefix:@"BLOCKPREDICATE("]) { + [NSException raise:NSInvalidArgumentException + format:@"Block-based predicates are not supported."]; + } + + [NSException raise:NSInvalidArgumentException + format:@"Unrecognized predicate type."]; + return nil; +} + +@end |