- 自定义显示格式
//创建默认数据源(默认图层)
let layer= new Cesium.CustomDataSource(layerName);
layer.clustering.enabled = true;
layer.clustering.pixelRange = 10;
layer.clustering.minimumClusterSize = 2;
layer.clustering.clusterLabels = true;
layer.clustering.clusterBillboards = false;
layer.clustering.clusterPoints = false;
layer.clustering.clusterEvent.addEventListener(function (
entities,
cluster
) {
cluster.label.show = true;
let dislabel = entities[0].label;
cluster.label.text = dislabel.text.getValue();
cluster.label.font = dislabel.font.getValue();
cluster.label.showBackground = dislabel.showBackground.getValue();
cluster.label.backgroundColor = dislabel.backgroundColor.getValue();
cluster.label.fillColor = dislabel.fillColor.getValue();
cluster.label.scale = dislabel.scale.getValue();
});
注意:
- cluster值必须是常量
- 而label Entity真是属性
cluster的values必须是常量属性(不能设置cluster.label.text = dislabel)
- 上述代码用到的地方
cluster.label.show = true;
let dislabel = entities[0].label;
cluster.label.text = dislabel.text.getValue();
cluster.label.font = dislabel.font.getValue();
cluster.label.showBackground = dislabel.showBackground.getValue();
cluster.label.backgroundColor = dislabel.backgroundColor.getValue();
cluster.label.fillColor = dislabel.fillColor.getValue();
cluster.label.scale = dislabel.scale.getValue();
结果:
这样的自定义显示不会显示数字,而默认的聚合显示是上图中所有聚合Entity的数量,这里显示的是以聚合的第一个Entity作为显示。



