iOS - 具有群集的Mapbox,MGLSymbolStyleLayer不显示自定义图像

Aam*_*irR 5 ios mapbox swift

我正在使用这个ios-sdk-examples> ClusteringExample来聚类标记,除了这个例子,我需要为每个标记显示不同的UIImages(意味着每个标记都有自己的UIImage),我试过以下:

let source = MGLShapeSource(identifier: "clusteredPorts", features: self.features, options: [.clustered: true, .clusterRadius: 22])
style.addSource(source)

// remoteImages is an array of tuple [(image: UIImage, key: String)]
remoteImages.forEach { item in
    mapView.style!.setImage(item.image, forName: item.key)
    let layer = MGLSymbolStyleLayer(identifier: item.key, source: source)
    layer.iconImageName = MGLStyleValue(rawValue: item.key as NSString)
    layer.predicate = NSPredicate(format: "%K != YES", "cluster")
    style.addLayer(layer)
}
Run Code Online (Sandbox Code Playgroud)

但是上面的代码显示了所有非聚集标记的单个UIImage(附带截图),我需要指定这些自定义图像的任何想法吗?

Update-1: self.features是一个数组[MGLPointFeature],每个数组MGLPointFeature只有以下内容:

let feature = MGLPointFeature()
feature.coordinate = CLLocationCoordinate2D(latitude: LatValue, longitude: LngValue)
feature.attributes = ["id": IntegerValue]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 -1

我想如果你想显示聚集标记,你必须写

%K == YES不是%K != YES

 layer.predicate = NSPredicate(format: "%K == YES", "cluster")
Run Code Online (Sandbox Code Playgroud)