IOS - Mapbox with clustering, MGLSymbolStyleLayer does not show custom images

I use this ios-sdk-examples> ClusteringExample for clustered tokens, in addition to this example I need to show different UIImages for each token (meaning that each token has its own UIImage), I tried the following:

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)
}

But the above code shows one single UIImage for all non-clustered markers (attached screenshot), any idea where I need to specify these custom images?

Update-1: self.features is an array [MGLPointFeature], each MGLPointFeaturehas nothing more than the following:

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

enter image description here

+4
source share
1

, clusterd,

%K == YES %K != YES.

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

Source: https://habr.com/ru/post/1675309/


All Articles