Mapbox 表达式检查 MGLStyleLayer 的属性并与字符串进行比较

问题描述

mapView:didFinishLoadingStyle: 方法中,我希望能够检查 MGLSymbolStyleLayer 是否使用特定的 class,类似于我们如何使用 filter一个 JSON 样式文件,用于将样式仅应用于某个类:

enter image description here

但是,就我而言,我想检查并查看地图上是否存在一个类,如果它是字符串数组的一部分,则将其隐藏:

NSArray *poiTypesExcluded = @[@"airport"];
for (Nsstring *poiType in poiTypesExcluded) {
        
    layer.visible = [NSExpression expressionWithFormat:@"class != %@",poiType];
        
}

这是给我的错误

Unable to parse the format string "class != %@ == 1"

有关如何编写 NSExpression 以将 class 属性与另一个字符串进行比较的任何帮助?

解决方法

我在这上面浪费了很多时间,最后它比我想象的要容易:

NSArray *poiTypesExcluded = @[@"airport",@"grocery",@"bank"];
NSMutableArray *predicates = [[NSMutableArray alloc] init];
for (NSString *poiType in poiTypesExcluded) {
    
    [predicates addObject:[NSPredicate predicateWithFormat:@"class != %@",poiType]];
    
}

symbolLayer.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...