Closed fabiovalse closed 4 years ago
I haven't looked in detail (since there's no reproducible test case), but I'm guessing this has to do with categories
object being passed as a reference somewhere and modified in multiple clusters at once. To check this, can you try removing the nesting and see if it works with A/B/C as properties?
You were right. I updated my code to:
const start = async () => {
// Load points
const points = await fetch('./points.json')
.then(response => response.json())
.then((data) => {
return data;
});
// Create super cluster index
const clusterIndex = new Supercluster({
radius: 140,
maxZoom: 17,
map: (item) => ({
[item.category]: 1,
}),
reduce: (acc, cur) => {
for (const category in cur) {
acc[category] = (acc[category] || 0) + cur[category];
}
},
});
clusterIndex.load(points);
// Get clusters given a bounding box and a zoom level
const clusters = clusterIndex.getClusters([-7.416159899999997, -49.88668752867185, 51.910011975, -4.991106132448181], 4);
console.log(clusters);
}
start();
and the sum of the categories is now correct. Thank you!
@mourner sorry to revive this old issue.
to use in clusterProperties with gl-js is it possible to create this map/reduce with expressions ?
Hi, I'm trying to use
map
andreduce
options to group my points according to a category. There are three categories: A, B and C. This is a sample point:My code is this:
The output of the
getCluster
is:The sum of the categories in the second cluster (id = 2068) is matching the point_count while it is not true for the first one (id = 2004). Is there something wrong in my
map
andreduce
functions?