触发聚类时如何 show/hide SymbolLayer 的图标
How to show/hide icon for a SymbolLayer when clustering is triggered
我有两个符号层图标集。我希望一个图标在图层未聚类时可见,并且在触发聚类时我想为同一层显示不同的图标。我遇到的问题是单个图标在群集图标下方仍然可见,我希望在群集时隐藏单个图标。如何添加此标志?
要显示我使用的集群的新图标:
// Add Source
val options = GeoJsonOptions().withCluster(true).withClusterRadius(30)
val stopSource = GeoJsonSource(sourceId, collection, options)
style.addSource(stopSource)
// Add single layer
val singleLayer = SymbolLayer(singleLayerId, sourceId).apply {
withProperties(
PropertyFactory.iconImage(singleLayerId),
PropertyFactory.iconAllowOverlap(true)
)
}
style.addImage(singleLayerId, singleIcon)
style.addLayer(singleLayer)
// Add cluster layer
val clusterLayer = SymbolLayer(clusterLayerId, sourceId).apply {
setFilter(eq(get("cluster"), true))
withProperties(
PropertyFactory.iconImage(clusterLayerId),
PropertyFactory.iconAllowOverlap(true)
)
}
style.addImage(clusterLayerId, clusterIcon)
style.addLayer(clusterLayer)
这有效,但仅适用于集群。单个图标仍然可见。
我使用标志 setFilter(eq(get("cluster"), true))
纯属猜测,因为我查看了具有相同要求的 iOS 实现,它似乎按预期工作。
如果我对单层使用setFilter(eq(get("cluster"), false))
,图标根本不可见。
iOS 使用标志,像这样:
单层图标:
layer.predicate = NSPredicate(format: "%K != YES", "cluster")
簇层图标:
layer.predicate = NSPredicate(format: "%K == YES", "cluster")
我希望 setFilter
是等效的,但它不起作用。
我发现了与重叠 属性 有关的问题。
PropertyFactory.iconAllowOverlap(true)
为我的单层将其设置为 false
修复了它。
我有两个符号层图标集。我希望一个图标在图层未聚类时可见,并且在触发聚类时我想为同一层显示不同的图标。我遇到的问题是单个图标在群集图标下方仍然可见,我希望在群集时隐藏单个图标。如何添加此标志?
要显示我使用的集群的新图标:
// Add Source
val options = GeoJsonOptions().withCluster(true).withClusterRadius(30)
val stopSource = GeoJsonSource(sourceId, collection, options)
style.addSource(stopSource)
// Add single layer
val singleLayer = SymbolLayer(singleLayerId, sourceId).apply {
withProperties(
PropertyFactory.iconImage(singleLayerId),
PropertyFactory.iconAllowOverlap(true)
)
}
style.addImage(singleLayerId, singleIcon)
style.addLayer(singleLayer)
// Add cluster layer
val clusterLayer = SymbolLayer(clusterLayerId, sourceId).apply {
setFilter(eq(get("cluster"), true))
withProperties(
PropertyFactory.iconImage(clusterLayerId),
PropertyFactory.iconAllowOverlap(true)
)
}
style.addImage(clusterLayerId, clusterIcon)
style.addLayer(clusterLayer)
这有效,但仅适用于集群。单个图标仍然可见。
我使用标志 setFilter(eq(get("cluster"), true))
纯属猜测,因为我查看了具有相同要求的 iOS 实现,它似乎按预期工作。
如果我对单层使用setFilter(eq(get("cluster"), false))
,图标根本不可见。
iOS 使用标志,像这样:
单层图标:
layer.predicate = NSPredicate(format: "%K != YES", "cluster")
簇层图标:
layer.predicate = NSPredicate(format: "%K == YES", "cluster")
我希望 setFilter
是等效的,但它不起作用。
我发现了与重叠 属性 有关的问题。
PropertyFactory.iconAllowOverlap(true)
为我的单层将其设置为 false
修复了它。