Supercluster supports map and reduce options that let users aggregate custom properties per cluster. For example, summing a numeric property across all points in a cluster:
const index = new Supercluster({
map: (props) => ({ sum: props.myValue }),
reduce: (accumulated, props) => {
accumulated.sum += props.sum;
},
});
This is one of Supercluster's most-used features. arrow-supercluster doesn't support it yet.
What needs to happen
- Add optional
map and reduce fields to ArrowClusterEngineOptions in packages/arrow-supercluster/src/types.ts
- During clustering in
_cluster() (packages/arrow-supercluster/src/arrow-cluster-engine.ts), call map for leaf points and reduce when merging points into clusters
- Store the aggregated properties and expose them in
ClusterOutput (likely a new properties array or similar)
- The tricky part:
ClusterOutput currently uses only typed arrays. Aggregated properties are user-defined objects, so this needs a design decision on how to expose them without breaking the typed-array-only contract
- Add tests in
packages/arrow-supercluster/tests/
References
Supercluster supports
mapandreduceoptions that let users aggregate custom properties per cluster. For example, summing a numeric property across all points in a cluster:This is one of Supercluster's most-used features.
arrow-superclusterdoesn't support it yet.What needs to happen
mapandreducefields toArrowClusterEngineOptionsinpackages/arrow-supercluster/src/types.ts_cluster()(packages/arrow-supercluster/src/arrow-cluster-engine.ts), callmapfor leaf points andreducewhen merging points into clustersClusterOutput(likely a newpropertiesarray or similar)ClusterOutputcurrently uses only typed arrays. Aggregated properties are user-defined objects, so this needs a design decision on how to expose them without breaking the typed-array-only contractpackages/arrow-supercluster/tests/References
packages/arrow-supercluster/src/arrow-cluster-engine.ts(the_clustermethod at ~line 354)