簡體   English   中英

Mapbox 表達式檢查 MGLStyleLayer 的屬性並與字符串進行比較

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM