2017-04-21 40 views
4

我使用这个ios-sdk-examples > ClusteringExample来聚集标记,除了这个例子,我需要为每个标记显示不同的UIImages(意味着每个标记都有它自己的UIImage),我有尝试以下操作:iOS - 带集群的Mapbox,MGLSymbolStyleLayer不显示自定义图像

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

+0

哪里可以解决这个问题? –

回答

-1

我认为,如果你想显示clusterd标记,你”必须写

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

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

它不起作用,%K == YES用于群集图层,原始示例https://www.mapbox.com/ios-sdk/examples/clustering/ – AamirR