[英]Mapbox Expression to check property of MGLStyleLayer and compare with string
In the mapView:didFinishLoadingStyle:
method, I would like to be able to check to see if a MGLSymbolStyleLayer
uses a specific class
, similar to how we can use filter
in a JSON style file to apply a style to only a certain class:
但是,就我而言,我想檢查並查看 map 上是否存在 class,如果它是字符串數組的一部分,則將其隱藏:
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.