ios - Mapbox 表达式检查 MGLStyleLayer 的属性并与字符串进行比较
问题描述
在该mapView:didFinishLoadingStyle:
方法中,我希望能够检查 a 是否MGLSymbolStyleLayer
使用特定的class
,类似于我们如何filter
在 JSON 样式文件中使用将样式仅应用于某个类:
但是,就我而言,我想检查地图上是否存在一个类,如果它是字符串数组的一部分,则将其隐藏:
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];
推荐阅读
- mongodb - 我在哪里可以获得DocuementDB集群的确切使用存储
- python - IBM Watson Visual Recognition 上自定义模型的错误分类
- shell - 使用 shell 脚本命令从文本中提取 UUID 字符串
- react-native - `useAuthRequest` 总是返回 `dismiss`
- html - 使用 window.print() 时创建封面
- javascript - Document.querySelector 返回 NULL 值 - 脚本位于页面底部
- swift - MapBox 注释标题在 Swift 中居中
- notepad++ - 制作大括号时如何使notepad ++转到下一行
- dpdk - 如何安装 DPDK 内核模块?
- sql-server - 仅当字段在更新之前为 false 时 SQL Server 才会触发