@@ -905,35 +905,6 @@ function updateEnable(entityCluster) {
905905 return ;
906906 }
907907
908- const allVisibleEntities = [ ] ;
909-
910- if ( defined ( entityCluster . _labelCollection ) ) {
911- for ( let i = 0 ; i < entityCluster . _labelCollection . length ; i ++ ) {
912- const label = entityCluster . _labelCollection . get ( i ) ;
913- if ( defined ( label . id ) && label . show ) {
914- allVisibleEntities . push ( label . id ) ;
915- }
916- }
917- }
918-
919- if ( defined ( entityCluster . _billboardCollection ) ) {
920- for ( let i = 0 ; i < entityCluster . _billboardCollection . length ; i ++ ) {
921- const billboard = entityCluster . _billboardCollection . get ( i ) ;
922- if ( defined ( billboard . id ) && billboard . show ) {
923- allVisibleEntities . push ( billboard . id ) ;
924- }
925- }
926- }
927-
928- if ( defined ( entityCluster . _pointCollection ) ) {
929- for ( let i = 0 ; i < entityCluster . _pointCollection . length ; i ++ ) {
930- const point = entityCluster . _pointCollection . get ( i ) ;
931- if ( defined ( point . id ) && point . show ) {
932- allVisibleEntities . push ( point . id ) ;
933- }
934- }
935- }
936-
937908 if ( defined ( entityCluster . _clusterLabelCollection ) ) {
938909 entityCluster . _clusterLabelCollection . destroy ( ) ;
939910 }
@@ -952,27 +923,62 @@ function updateEnable(entityCluster) {
952923 disableCollectionClustering ( entityCluster . _billboardCollection ) ;
953924 disableCollectionClustering ( entityCluster . _pointCollection ) ;
954925
955- if ( allVisibleEntities . length > 0 ) {
956- const uniqueEntities = [ ... new Set ( allVisibleEntities ) ] ;
926+ if ( entityCluster . _declusteredEvent . numberOfListeners !== 0 ) {
927+ const allVisibleEntities = [ ] ;
957928
958- entityCluster . _declusteredEvent . raiseEvent ( {
959- clustered : [ ] ,
960- declustered : uniqueEntities ,
961- cluster : null ,
962- allProcessed : uniqueEntities ,
963- } ) ;
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+ }
964937
965- entityCluster . _lastClusteredEntities = [ ] ;
966- entityCluster . _lastDeclusteredEntities = uniqueEntities . slice ( ) ;
967- entityCluster . _allProcessedEntities = uniqueEntities . slice ( ) ;
968- } else {
969- entityCluster . _declusteredEvent . raiseEvent ( {
970- clustered : [ ] ,
971- declustered : [ ] ,
972- cluster : null ,
973- allProcessed : [ ] ,
974- } ) ;
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+ }
975955
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 {
976982 entityCluster . _lastClusteredEntities = [ ] ;
977983 entityCluster . _lastDeclusteredEntities = [ ] ;
978984 entityCluster . _allProcessedEntities = [ ] ;
0 commit comments