NSExpression(MGLAdditions)
@interface NSExpression (MGLAdditions)
Methods for creating expressions that use Mapbox-specific functionality and for converting to and from the JSON format defined in the Mapbox Style Specification.
-
NSExpressionvariable that corresponds to thezoomexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull zoomLevelVariableExpression;Swift
class var zoomLevelVariable: NSExpression { get } -
NSExpressionvariable that corresponds to theheatmap-densityexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull heatmapDensityVariableExpression;Swift
class var heatmapDensityVariable: NSExpression { get } -
NSExpressionvariable that corresponds to theline-progressexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull lineProgressVariableExpression;Swift
class var lineProgressVariable: NSExpression { get } -
NSExpressionvariable that corresponds to thegeometry-typeexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull geometryTypeVariableExpression;Swift
class var geometryTypeVariable: NSExpression { get } -
NSExpressionvariable that corresponds to theidexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull featureIdentifierVariableExpression;Swift
class var featureIdentifierVariable: NSExpression { get } -
NSExpressionvariable that corresponds to theidexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull featureAccumulatedVariableExpression;Swift
class var featureAccumulatedVariable: NSExpression { get } -
NSExpressionvariable that corresponds to thepropertiesexpression operator in the Mapbox Style Specification.Declaration
Objective-C
@property (class, nonatomic, readonly) NSExpression *_Nonnull featureAttributesVariableExpression;Swift
class var featureAttributesVariable: NSExpression { get }
-
Returns a conditional function expression specifying the string predicate, and expressions for each condition.
Declaration
Objective-C
+ (nonnull instancetype) mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression;Swift
convenience init(forMGLConditional conditionPredicate: NSPredicate, trueExpression: NSExpression, falseExpression: NSExpression)Parameters
conditionPredicateThe predicate to get evaluated.
trueExpressionThe expression for conditions equal to true.
falseExpressionThe expression for conditions equal to false.
-
Returns a step function expression specifying the stepping, from expression and stops.
Related examples
See the Data-driven circles, Cluster point data, and Use images to cluster point data examples to learn how to use this expression to style a map layer based on an attribute value.
Declaration
Objective-C
+ (nonnull instancetype) mgl_expressionForSteppingExpression: (nonnull NSExpression *)steppingExpression fromExpression: (nonnull NSExpression *)minimumExpression stops:(nonnull NSExpression *)stops;Swift
convenience init(forMGLStepping steppingExpression: NSExpression, from minimumExpression: NSExpression, stops: NSExpression)Parameters
steppingExpressionThe stepping expression.
minimumExpressionThe expression which could be a constant or function expression.
stopsThe stops must be an
NSDictionaryconstantNSExpression. -
Returns an interpolated function expression specifying the function operator, curve type, parameters and steps.
Related examples
See the Create a heatmap layer example to learn how to style an
MGLHeatmapStyleLayerbased on zoom level and point density with this expression.Declaration
Objective-C
+ (nonnull instancetype) mgl_expressionForInterpolatingExpression: (nonnull NSExpression *)inputExpression withCurveType: (nonnull MGLExpressionInterpolationMode) curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression *)stops;Swift
convenience init(forMGLInterpolating inputExpression: NSExpression, curveType: MGLExpressionInterpolationMode, parameters: NSExpression?, stops: NSExpression)Parameters
inputExpressionThe interpolating expression input.
curveTypeThe curve type could be
MGLExpressionInterpolationModeLinear,MGLExpressionInterpolationModeExponentialandMGLExpressionInterpolationModeCubicBezier.parametersThe parameters expression.
stopsThe stops expression.
-
Returns a match function expression specifying the input, matching values, and default value.
Declaration
Objective-C
+ (nonnull instancetype) mgl_expressionForMatchingExpression:(nonnull NSExpression *)inputExpression inDictionary:(nonnull NSDictionary<NSExpression *, NSExpression *> *) matchedExpressions defaultExpression: (nonnull NSExpression *)defaultExpression;Swift
convenience init(forMGLMatchingKey inputExpression: NSExpression, in matchedExpressions: [NSExpression : NSExpression], default defaultExpression: NSExpression)Parameters
inputExpressionThe matching expression.
matchedExpressionsThe matched values expression dictionary must be condition : value.
defaultExpressionThe defaultValue expression to be used in case there is no match.
-
Returns an attributed function expression specifying an
MGLAttributedExpressionconstant expression array.Declaration
Objective-C
+ (nonnull instancetype)mgl_expressionForAttributedExpressions: (nonnull NSArray<NSExpression *> *)attributedExpressions;Swift
convenience init(forAttributedExpressions attributedExpressions: [NSExpression])Parameters
attributedExpressionsThe
MGLAttributedExpressionconstant expression array.
-
Returns a constant expression appending the passed expression.
Note
Both the receiver and the given expression must be an
NSStringconstant expression type; otherwise, an exception is rised.Declaration
Objective-C
- (nonnull instancetype)mgl_expressionByAppendingExpression: (nonnull NSExpression *)expression;Swift
func mgl_appending(_ expression: NSExpression) -> SelfParameters
expressionThe expression to append to the receiver.
-
Returns an expression equivalent to the given Foundation object deserialized from JSON data.
The Foundation object is interpreted according to the Mapbox Style Specification. See the “Information for Style Authors” guide for a correspondence of operators and types between the style specification and the
NSExpressionrepresentation used by this SDK.Declaration
Objective-C
+ (nonnull instancetype)expressionWithMGLJSONObject:(nonnull id)object;Swift
convenience init(mglJSONObject object: Any)Parameters
objectA Foundation object deserialized from JSON data, for example using
NSJSONSerialization.Return Value
An initialized expression equivalent to
object, suitable for use as the value of a style layer attribute. -
An equivalent Foundation object that can be serialized as JSON.
The Foundation object conforms to the Mapbox Style Specification. See the “Information for Style Authors” guide for a correspondence of operators and types between the style specification and the
NSExpressionrepresentation used by this SDK.You can use
NSJSONSerializationto serialize the Foundation object as data to write to a file.Declaration
Objective-C
@property (nonatomic, readonly) id _Nonnull mgl_jsonExpressionObject;Swift
var mgl_jsonExpressionObject: Any { get }
-
Returns a copy of the receiver localized into the given locale.
This method assumes the receiver refers to the feature attributes that are available in vector tiles supplied by the Mapbox Streets source. On iOS, the user can set the system’s preferred language in Settings, General Settings, Language & Region. On macOS, the user can set the system’s preferred language in the Language & Region pane of System Preferences.
Declaration
Objective-C
- (nonnull NSExpression *)mgl_expressionLocalizedIntoLocale: (nullable NSLocale *)locale;Swift
func mgl_expressionLocalized(into locale: Locale?) -> NSExpressionParameters
localeThe locale into which labels should be localized. To use the system’s preferred language, if supported, specify
nil. To use the local language, specify a locale with the identifiermul.
Install in Dash
NSExpression(MGLAdditions) Category Reference