Created
March 15, 2019 00:06
-
-
Save harllos/0ea2883bee30b43b83fcf098e8ef9dbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Supercluster with property aggregation | |
var cluster = supercluster({ | |
radius: clusterRadius, | |
maxZoom: clusterMaxZoom, | |
initial: function() { | |
return { | |
count: 0, | |
sum: 0, | |
min: Infinity, | |
max: -Infinity | |
}; | |
}, | |
map: function(properties) { | |
return { | |
count: 1, | |
sum: Number(properties[propertyToAggregate]), | |
min: Number(properties[propertyToAggregate]), | |
max: Number(properties[propertyToAggregate]) | |
}; | |
}, | |
reduce: function(accumulated, properties) { | |
accumulated.sum += Math.round(properties.sum * 100) / 100; | |
accumulated.count += properties.count; | |
accumulated.min = Math.round(Math.min(accumulated.min, properties.min) * 100) / 100; | |
accumulated.max = Math.round(Math.max(accumulated.max, properties.max) * 100) / 100; | |
accumulated.avg = Math.round(100 * accumulated.sum / accumulated.count) / 100; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment