Skip to content
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

How to access clusterProperties of a clustered vector source? #4

Closed
octopusabhiraj opened this issue Nov 16, 2020 · 1 comment
Closed

Comments

@octopusabhiraj
Copy link

I am converting a GeoJson of 10 million points to MapBox tiles (.mbtiles)

var vList = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; // List of video IDs
supertiler({
    input: '../file.json',
    output: '../file.mbtiles',
    maxZoom: 12,
    initial: () => {
        var t = Object();
        videoList.forEach(v => {
            t[v] = 0
        });
        return t;
    },
    map: (props) => {
        var t = Object();
        videoList.forEach(v => {
            t[v] = v === props.i ? 1 : 0; // i is the video ID - property of a single point
        });
        return t;
    },
    reduce: (accumulated, props) => {

        videoList.forEach(v => {
            accumulated[v] = accumulated[v] + props[v];
        });

    }
}).then(null, (err) => console.log(err));

I am then uploading the .mbtiles files to the Mapbox using their Uploads API so that I can add the data to my application as a vector source.

map.addSource(layerID, {
    type: 'vector',
    url: 'mapbox://octopusmapbox.vLayer',
});

map.addLayer({
    id: `${layerID}-cluster`,
    type: 'circle',
    source: layerID,
    'source-layer': 'geojsonLayer',
    maxzoom: 12.99,
    paint: {
        'circle-color': 'hsla(1, 86%, 65%, 0.5)',
        'circle-radius': [
            'interpolate',
            ['linear'],
            ['get', 'point_count'],
            0,
            20,
            156342,
            200,
        ],
        'circle-opacity': 0.7,
        'circle-stroke-color': '#f35e5b',
        'circle-stroke-width': 1,
    },
});

When I console log the properties of the cluster, I do not see any cluster properties, but only the following:

{
  "cluster": true,
  "cluster_id": 612,
  "point_count": 1399,
  "point_count_abbreviated": "1.4k"
}

How do I access the properties 'a', 'b', 'c', etc.?

@octopusabhiraj
Copy link
Author

The vector layers take time to propagate the changes to the source when used in the application. My code is generating the clusterProperties correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant