Estoy agrupando puntos en un mapa web y tengo un script de Arcade que resume algunos de los valores de atributos de los puntos agrupados.
Estoy encontrando algunos casos en los que el número de entidades indicadas en el clúster (y el número de registros que obtengo al hacer clic en «Examinar entidades») coincide con los recuentos que devuelve mi script de Arcade, pero en otros casos estos números no coinciden.
Al principio pensé que podría haber un problema con la lógica de mi script, pero, después de revisarlo y añadir algunas instrucciones Console() al script, veo que «Count($aggregatedFeatures)» devuelve un número menor que la cantidad de entidades que contiene el clúster.
Ejemplo de un clúster en el que no coinciden:

Ejemplo del registro del editor de Arcade con la instrucción Console(Count($aggregatedFeatures)); la capa se ha filtrado para mostrar solo los 7 puntos que forman el clúster de la captura de pantalla anterior:

El script completo de Arcade que intento usar:
// List the fields referenced by the expression.
Expects($aggregatedFeatures, "Project_Type", "Project_Status");
Console(Count($aggregatedFeatures))
// Create dict to store summaries of project type and status
var typeSummary = {};
// Go over each feature and add/update the counts of project type and status to the dict
for (feature in $aggregatedFeatures) {
// Set variables for type and status, setting nulls to 'null' string for proper handling
// While setting, replace spaces with _ so that dict keys can be created
var type = When(!IsEmpty(feature['Project_Type']), Replace(feature['Project_Type'], ' ', '_'), 'null');
var status = When(!IsEmpty(feature['Project_Status']), Replace(feature['Project_Status'], ' ', '_'), 'null');
// If dict doesn't have this type, add everything with an intitial count of 1
if (!HasKey(typeSummary, type)) {
typeSummary[type] = {
'count': 1,
'statusSummary': {}
}
typeSummary[type]['statusSummary'][status] = 1
} else {
// Dict has type, increment type count by 1
typeSummary[type]['count']++ ;
// Check if status exists for this type, set to 1 or increment by 1 as necessary
if (!HasKey(typeSummary[type]['statusSummary'], status)) {
typeSummary[type]['statusSummary'][status] = 1
} else {
typeSummary[type]['statusSummary'][status]++
}
}
}
// Prepare to build html list output with top level list
var html = '<ul>'
// Each project type will get a list item in the top level list
for (type in typeSummary) {
html += `\n\t<li>${Replace(type, '_', ' ')} - ${typeSummary[type]['count']} projects</li>\n\t<ul>`
// Each project status within each project type will get a list item in the nested list
for (status in typeSummary[type]['statusSummary']) {
html += `\n\t\t<li>${Replace(status, '_', ' ')} - ${typeSummary[type]['statusSummary'][status]} projects</li>`
}
html += '\n\t</ul>'
}
html += '\n</ul>'
return {
type : 'text',
text : html //this property supports html tags
}