@@ -900,6 +900,58 @@ function disableCollectionClustering(collection) {
900
900
}
901
901
}
902
902
903
+ function getVisibleEntitiesFromCollection ( collection ) {
904
+ if ( ! defined ( collection ) ) {
905
+ return [ ] ;
906
+ }
907
+
908
+ const visibleEntities = [ ] ;
909
+ for ( let i = 0 ; i < collection . length ; i ++ ) {
910
+ const item = collection . get ( i ) ;
911
+ if ( defined ( item . id ) && item . show ) {
912
+ visibleEntities . push ( item . id ) ;
913
+ }
914
+ }
915
+ return visibleEntities ;
916
+ }
917
+
918
+ function handleDeclusteredEvent ( entityCluster ) {
919
+ if ( entityCluster . _declusteredEvent . numberOfListeners === 0 ) {
920
+ return ;
921
+ }
922
+ const allVisibleEntities = [
923
+ ...getVisibleEntitiesFromCollection ( entityCluster . _labelCollection ) ,
924
+ ...getVisibleEntitiesFromCollection ( entityCluster . _billboardCollection ) ,
925
+ ...getVisibleEntitiesFromCollection ( entityCluster . _pointCollection ) ,
926
+ ] ;
927
+
928
+ if ( allVisibleEntities . length > 0 ) {
929
+ const uniqueEntities = Array . from ( new Set ( allVisibleEntities ) ) ;
930
+
931
+ entityCluster . _declusteredEvent . raiseEvent ( {
932
+ clustered : [ ] ,
933
+ declustered : uniqueEntities ,
934
+ cluster : null ,
935
+ allProcessed : uniqueEntities ,
936
+ } ) ;
937
+
938
+ entityCluster . _lastClusteredEntities = [ ] ;
939
+ entityCluster . _lastDeclusteredEntities = uniqueEntities . slice ( ) ;
940
+ entityCluster . _allProcessedEntities = uniqueEntities . slice ( ) ;
941
+ } else {
942
+ entityCluster . _declusteredEvent . raiseEvent ( {
943
+ clustered : [ ] ,
944
+ declustered : [ ] ,
945
+ cluster : null ,
946
+ allProcessed : [ ] ,
947
+ } ) ;
948
+
949
+ entityCluster . _lastClusteredEntities = [ ] ;
950
+ entityCluster . _lastDeclusteredEntities = [ ] ;
951
+ entityCluster . _allProcessedEntities = [ ] ;
952
+ }
953
+ }
954
+
903
955
function updateEnable ( entityCluster ) {
904
956
if ( entityCluster . enabled ) {
905
957
return ;
@@ -923,66 +975,7 @@ function updateEnable(entityCluster) {
923
975
disableCollectionClustering ( entityCluster . _billboardCollection ) ;
924
976
disableCollectionClustering ( entityCluster . _pointCollection ) ;
925
977
926
- if ( entityCluster . _declusteredEvent . numberOfListeners !== 0 ) {
927
- const allVisibleEntities = [ ] ;
928
-
929
- if ( defined ( entityCluster . _labelCollection ) ) {
930
- for ( let i = 0 ; i < entityCluster . _labelCollection . length ; i ++ ) {
931
- const label = entityCluster . _labelCollection . get ( i ) ;
932
- if ( defined ( label . id ) && label . show ) {
933
- allVisibleEntities . push ( label . id ) ;
934
- }
935
- }
936
- }
937
-
938
- if ( defined ( entityCluster . _billboardCollection ) ) {
939
- for ( let i = 0 ; i < entityCluster . _billboardCollection . length ; i ++ ) {
940
- const billboard = entityCluster . _billboardCollection . get ( i ) ;
941
- if ( defined ( billboard . id ) && billboard . show ) {
942
- allVisibleEntities . push ( billboard . id ) ;
943
- }
944
- }
945
- }
946
-
947
- if ( defined ( entityCluster . _pointCollection ) ) {
948
- for ( let i = 0 ; i < entityCluster . _pointCollection . length ; i ++ ) {
949
- const point = entityCluster . _pointCollection . get ( i ) ;
950
- if ( defined ( point . id ) && point . show ) {
951
- allVisibleEntities . push ( point . id ) ;
952
- }
953
- }
954
- }
955
-
956
- if ( allVisibleEntities . length > 0 ) {
957
- const uniqueEntities = Array . from ( new Set ( allVisibleEntities ) ) ;
958
-
959
- entityCluster . _declusteredEvent . raiseEvent ( {
960
- clustered : [ ] ,
961
- declustered : uniqueEntities ,
962
- cluster : null ,
963
- allProcessed : uniqueEntities ,
964
- } ) ;
965
-
966
- entityCluster . _lastClusteredEntities = [ ] ;
967
- entityCluster . _lastDeclusteredEntities = uniqueEntities . slice ( ) ;
968
- entityCluster . _allProcessedEntities = uniqueEntities . slice ( ) ;
969
- } else {
970
- entityCluster . _declusteredEvent . raiseEvent ( {
971
- clustered : [ ] ,
972
- declustered : [ ] ,
973
- cluster : null ,
974
- allProcessed : [ ] ,
975
- } ) ;
976
-
977
- entityCluster . _lastClusteredEntities = [ ] ;
978
- entityCluster . _lastDeclusteredEntities = [ ] ;
979
- entityCluster . _allProcessedEntities = [ ] ;
980
- }
981
- } else {
982
- entityCluster . _lastClusteredEntities = [ ] ;
983
- entityCluster . _lastDeclusteredEntities = [ ] ;
984
- entityCluster . _allProcessedEntities = [ ] ;
985
- }
978
+ handleDeclusteredEvent ( entityCluster ) ;
986
979
}
987
980
988
981
/**
0 commit comments