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

时间:2017-04-21 00:11:31

标签: ios swift mapbox

我使用这个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)
}

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

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

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

enter image description here

1 个答案:

答案 0 :(得分:-1)

我认为如果要显示群集标记,则必须编写

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

 layer.predicate = NSPredicate(format: "%K == YES", "cluster")