iOS: Fix case image expression crash (#4269)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1559,7 +1559,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) {
|
||||
firstCondition = self.operand;
|
||||
}
|
||||
|
||||
if ([firstCondition respondsToSelector:@selector(constantValue)] &&
|
||||
if (firstCondition.expressionType == NSConstantValueExpressionType &&
|
||||
[firstCondition.constantValue isKindOfClass:[NSComparisonPredicate class]]) {
|
||||
NSPredicate *predicate = (NSPredicate *)firstCondition.constantValue;
|
||||
condition = predicate.mgl_jsonExpressionObject;
|
||||
@@ -1572,7 +1572,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) {
|
||||
isAftermarketFunction ? self.arguments : self.arguments[minimumIndex].constantValue;
|
||||
|
||||
for (NSUInteger index = minimumIndex; index < arguments.count; index++) {
|
||||
if ([arguments[index] respondsToSelector:@selector(constantValue)] &&
|
||||
if (arguments[index].expressionType == NSConstantValueExpressionType &&
|
||||
[arguments[index].constantValue isKindOfClass:[NSComparisonPredicate class]]) {
|
||||
NSPredicate *predicate = (NSPredicate *)arguments[index].constantValue;
|
||||
[expressionObject addObject:predicate.mgl_jsonExpressionObject];
|
||||
|
||||
@@ -318,6 +318,23 @@
|
||||
NSException, @"MLNRedundantLayerIdentifierException");
|
||||
}
|
||||
|
||||
- (void)testSymbolLayerIconImageNameWithMultiCaseImageExpression {
|
||||
MLNPointFeature *feature = [[MLNPointFeature alloc] init];
|
||||
MLNShapeSource *source = [[MLNShapeSource alloc] initWithIdentifier:@"sourceID"
|
||||
shape:feature
|
||||
options:nil];
|
||||
MLNSymbolStyleLayer *layer = [[MLNSymbolStyleLayer alloc] initWithIdentifier:@"layerID"
|
||||
source:source];
|
||||
// Reproduces https://github.com/maplibre/maplibre-native/issues/3477.
|
||||
NSArray *jsonExpression = @[
|
||||
@"case", @[ @"==", @[ @"get", @"icon" ], @"1" ], @[ @"image", @"icon1" ],
|
||||
@[ @"==", @[ @"get", @"icon" ], @"2" ], @[ @"image", @"icon2" ], @[ @"image", @"icon3" ]
|
||||
];
|
||||
NSExpression *expression = [NSExpression expressionWithMLNJSONObject:jsonExpression];
|
||||
|
||||
XCTAssertNoThrow(layer.iconImageName = expression);
|
||||
}
|
||||
|
||||
- (void)testRemovingLayerBeforeAddingSameLayer {
|
||||
{
|
||||
MLNShapeSource *source =
|
||||
|
||||
Reference in New Issue
Block a user