Tuesday, 29 May 2018

How to use the reduce options with Mapbox's clusters?

I'm POC-ing clusters with Mabpox-gl-js v0.45.

I would like to customize my cluster's properties (actual default values are point_count and point_count_abbreviated). Each of my points (one for each city) have a surface property (an integer) which I want to sum when points are clustered.

I see in mapbox's sources a reference to a reduce function to calculate custom properties:

SuperCluster.prototype = {
    options: {
        minZoom: 0,   // min zoom to generate clusters on
        // .....
        log: false,   // whether to log timing info

        // a reduce function for calculating custom cluster properties
        reduce: null, // function (accumulated, props) { accumulated.sum += props.sum; }

        // initial properties of a cluster (before running the reducer)
        initial: function () { return {}; }, // function () { return {sum: 0}; },

        // properties to use for individual points when running the reducer
        map: function (props) { return props; } // function (props) { return {sum: props.my_value}; },
    },

But I don't see any mention about it on the documentation. How can I set these options?



from How to use the reduce options with Mapbox's clusters?

No comments:

Post a Comment