Hi everyone
I’m using clustering to optimize the visualization of large amount of points written in CZML.
It works really well. But when I’m using the clustering, the label of each CZML packet can not be displayed.
I wonder if there is a solution to let single point labeled.
What I tried is to find cluster that has only one entity, but it seems the cluster should have at least 2 entities.
Any help appreciated
Thanks
Chris
This is my code:
var dataSourcePromise = viewer.dataSources.add(Cesium.CzmlDataSource.load(czml));
dataSourcePromise.then(function(dataSource) {
var pixelRange = 30;
var minimumClusterSize = 6;
var enabled = true;
dataSource.clustering.enabled = enabled;
dataSource.clustering.pixelRange = pixelRange;
dataSource.clustering.minimumClusterSize = minimumClusterSize;
var removeListener;
function customStyle() {
if (Cesium.defined(removeListener)) {
removeListener();
removeListener = undefined;
} else {
removeListener = dataSource.clustering.clusterEvent.addEventListener(function(clusteredEntities, cluster) {
cluster.label.show = true;
cluster.point.show = true;
cluster.label.horizontalOrigin = Cesium.HorizontalOrigin.CENTER;
cluster.label.verticalOrigin = Cesium.VerticalOrigin.CENTER;
cluster.label.fillColor = Cesium.Color.BLACK;
cluster.label.outlineWidth = 0;
cluster.point.color= Cesium.Color.RED;
cluster.point.outlineColor=Cesium.Color.BLACK;
cluster.point.outlineWidth=3;
if(clusteredEntities.length==1) console.log('1');
if (clusteredEntities.length >= 50) {
cluster.point.pixelSize=32;
cluster.label.font = "20px sans-serif";
} else if (clusteredEntities.length >= 40) {
cluster.point.pixelSize=28;
cluster.label.font = "18px sans-serif";
} else if (clusteredEntities.length >= 30) {
cluster.point.pixelSize=24;
cluster.label.font = "16px sans-serif";
} else if (clusteredEntities.length >= 20) {
cluster.point.pixelSize=20;
cluster.label.font = "14px sans-serif";
} else if (clusteredEntities.length >= 10) {
cluster.point.pixelSize=16;
cluster.label.font = "12px sans-serif";
} else if(clusteredEntities.length>1){
cluster.point.pixelSize=12;
cluster.label.font = "10px sans-serif";
} else{
console.log(clusteredEntities[0]);//Here I try to find out the single entity but failed
cluster.label = clusteredEntities[0].label;
}
});
}
// force a re-cluster with the new styling
var pixelRange = dataSource.clustering.pixelRange;
dataSource.clustering.pixelRange = 0;
dataSource.clustering.pixelRange = pixelRange;
}
// start with custom style
customStyle();
});