MGLVectorStyleLayer
@interface MGLVectorStyleLayer : MGLForegroundStyleLayer
MGLVectorStyleLayer is an abstract superclass for style layers whose content
is defined by an MGLShapeSource or MGLVectorSource object.
Do not create instances of this class directly, and do not create your own
subclasses of this class. Instead, create instances of the following concrete
subclasses: MGLCircleStyleLayer, MGLFillStyleLayer, MGLLineStyleLayer,
and MGLSymbolStyleLayer.
-
Identifier of the layer within the source identified by the
sourceIdentifierproperty from which the receiver obtains the data to style.Declaration
Objective-C
@property (assign, readwrite, nonatomic, nullable) NSString *sourceLayerIdentifier;Swift
var sourceLayerIdentifier: String? { get set } -
The style layer’s predicate.
Use the style layer’s predicate to include only the features in the source layer that satisfy a condition that you define. If the style layer initially comes from the style, its predicate corresponds to the
filterproperty in the style JSON.The following comparison operators are supported.
NSEqualToPredicateOperatorType(=,==)NSGreaterThanOrEqualToPredicateOperatorType(>=,=>)NSLessThanOrEqualToPredicateOperatorType(<=,=<)NSGreaterThanPredicateOperatorType(>)NSLessThanPredicateOperatorType(<)NSNotEqualToPredicateOperatorType(!=,<>)NSBetweenPredicateOperatorType(BETWEEN)
The following compound operators are supported:
NSAndPredicateType(AND,&&)NSOrPredicateType(OR,||)NSNotPredicateType(NOT,!)
The following aggregate operators are supported:
NSInPredicateOperatorType(IN)NSContainsPredicateOperatorType(CONTAINS)
To test whether a feature has or lacks a specific attribute, compare the attribute to
NULLorNIL. 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 “Predicate Programming Guide” 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:
Attribute Meaning $idA 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 MGLFeatureprotocol’sidentifierproperty.$typeThe type of geometry represented by the feature. A feature’s type is guaranteed to be one of the following strings: -
Pointfor point features, corresponding to theMGLPointAnnotationclass -
LineStringfor polyline features, corresponding to theMGLPolylineclass -
Polygonfor polygon features, corresponding to theMGLPolygonclass
point_countThe number of point features in a given cluster. The predicate’s right-hand expression must be an
NSString(to match strings) orNSNumber(to match numbers, including Boolean values) or an array ofNSStrings orNSNumbers, 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), andl(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$idand$typespecial style attributes and alsohyphen-minusandtag:subtag. However, you must use%Kin the format string to represent these variables:@"%K == 'LineString'", @"$type".Example
To filter the layer to include only the features whose
indexattribute is 5 or 10 and whoseeleattribute is at least 1,500, you could create anNSCompoundPredicatealong these lines:let layer = MGLLineStyleLayer(identifier: "contour", source: terrain) layer.sourceLayerIdentifier = "contours" layer.predicate = NSPredicate(format: "(index == 5 || index == 10) && ele >= 1500.0") mapView.style?.addLayer(layer)Declaration
Objective-C
@property (assign, readwrite, nonatomic, nullable) NSPredicate *predicate;Swift
var predicate: NSPredicate? { get set }
Install in Dash
MGLVectorStyleLayer Class Reference