-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible aggregating issue with map/reduce. #150
Comments
I haven't looked in detail (since there's no reproducible test case), but I'm guessing this has to do with |
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 |
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?The text was updated successfully, but these errors were encountered: