因此,我目前在 Mapbox 示例的帮助下对地图上的点网格进行聚类: 创建聚类并设置样式
Mapbox 中的示例代码计算点数并像这样显示它 - 使用变量point_count_abbreviated:
map.addLayer({
id: "cluster-count",
...
layout: {
"text-field": "{point_count_abbreviated}",
},
...
})
Run Code Online (Sandbox Code Playgroud)
我的 geoJSON 源看起来像这样:
{
"type": "Feature",
"geometry": { ... },
"properties": {
"location": { ... },
"id": 111,
...
"value": {
"count": 2
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想做的是将所有“properties.value.count”加在一起,并在每个集群上显示总和。我已经尝试了有关 clusterProperties 的文档中的示例 ,但由于我的计数变量嵌套在值对象内,因此我很难使其工作。
所以我猜集群源定义中是这样的:
clusterProperties: {"sum": ["+", ["object", "value", ['get, 'count']]]}
Run Code Online (Sandbox Code Playgroud)
并将其显示在图层中:
layout: {
"text-field": ['get', 'sum'],
},
Run Code Online (Sandbox Code Playgroud)
有人可以指出我正确的方向吗?:)