问题描述
我们正在解决的问题是,我们需要为集群中的所有对象通过特定属性对集群添加一些过滤。
那个需求之前的代码是:
// Create style layer to cluster features as images with labels
let clusterLayer = MGLSymbolStyleLayer(identifier: "clusteredCarsLayer",source: caRSSource)
clusterLayer.textColor = NSExpression(forConstantValue: UIColor.white)
clusterLayer.textHaloColor = NSExpression(forConstantValue: UIColor.withAlphaComponent(UIColor(hexString: "000000"))(0.4))
clusterLayer.textHaloWidth = NSExpression(forConstantValue: 20)
clusterLayer.textAnchor = NSExpression(forConstantValue: "bottom")
clusterLayer.textOffset = NSExpression(forConstantValue: NSValue(cgVector: CGVector(dx: 0,dy: 2)))
clusterLayer.texTradialOffset = nil
clusterLayer.textFontSize = NSExpression(forConstantValue: NSNumber(value: Double(self?.icon.size.width ?? 0) / 2))
clusterLayer.iconAllowsOverlap = NSExpression(forConstantValue: false)
clusterLayer.iconImageName = NSExpression(forConstantValue: "carsCluster")
style.setimage(UIImage(named: "CarIconCluster")!,forName: "carsCluster")
let stops = [
2: NSExpression(forConstantValue: "carsCluster"),]
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')")
style.addLayer(clusterLayer)
如您所见,这是有效的,如果有两辆以上的汽车,并且群集图标下有汽车数量,则创建一个群集。
现在,需求是通过汽车的状态进行聚类(状态是每个汽车对象都具有的属性)。例如,如果所有汽车都处于最终状态,则将图像设置为最终图像,否则将图像设置为活动图像。
我知道如何过滤特定汽车,就像我在这里所做的一样:
// Show unclustered features as icons. The `cluster` attribute is built into clustering-enabled source features.
// This example requires two style layers to work properly: one for clustered points and one for unclustered points
let markerLayer = MGLSymbolStyleLayer(identifier: "carsLayer",source: caRSSource)
//markerLayer.iconImageName = NSExpression(forConstantValue: "car")
markerLayer.predicate = nspredicate(format: "cluster != YES")
style.addLayer(markerLayer)
// Create a stops dictionary with keys that are possible values for 'status',paired with icon images that will represent those features.
style.setimage(UIImage(named: "CarIconFinal")!,forName: "carFinal")
style.setimage(UIImage(named: "CarIconActive")!,forName: "caractive")
style.setimage(UIImage(named: "CarIconSelected")!,forName: "caractiveSelected")
style.setimage(UIImage(named: "CarIconSelectedInactive")!,forName: "carFinalSelected")
let carIcons = ["Final" : "carFinal","Active" : "caractive"]
// Use the stops dictionary to assign an icon based on the "status" for each feature.
markerLayer.iconImageName = NSExpression(format: "FUNCTION(%@,'valueForKeyPath:',status)",carIcons)
但是对于 MapBox SDK 的本机实现,IOS 和 Android 团队都无法弄清楚这一点,只是无法弄清楚或找不到任何地方如何为集群执行此操作,因为我们需要查看其中的所有对象集群并为特定属性的所有值设置不同的图像以获取不同的状态(正如我之前写的,只有当集群中所有对象的状态都具有特定值而不是为特定图像设置图像时)。
有什么想法、方向吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)