Can any one help solve how to do this?
I'v added a property to each cluster that sums all the active cars and now I need to set the image for the cluster by that property (active_count).
Whatever I try I'm getting that it can't be parsed.
style.setImage(UIImage(named: "CarIconCluster")!, forName: "carCluster")
style.setImage(UIImage(named: "CarIconClusterFinal")!, forName: "carClusterFinal")
let stops = [
//2: NSExpression(forConstantValue: "carCluster"), // This line is working of course but it only show that active cluster always, I need to add a condition expression here
//2: NSExpression(format: "active_count >= 1, 'carCluster', 'carClusterFinal'"), // THIS IS NOT WORKING
2: NSExpression(format: "TERNARY(FUNCTION(%@, 'valueForKeyPath:', active_count) >= 1, 'carCluster', 'carClusterFinal'"), // THIS IS NOT WORKING
]
let defaultShape = NSExpression(forConstantValue: "car")
clusterLayer.iconImageName = NSExpression(format: "mgl_step:from:stops:(point_count, %@, %@)", defaultShape, stops)
clusterLayer.text = NSExpression(format: "CAST(point_count, 'NSString')")
All I need is that if there at list one active car in the cluster than show the carCluster image, otherwise show the carClusterFinal image.
question from:
https://stackoverflow.com/questions/65950543/mapbox-ios-sdk-selecting-image-with-ternary-expression-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…