Search code examples
mapboxmarkerclusterermapbox-glmapbox-gl-js

how to customise cluster icon in mapbox-gl?


I want to implement clustering in my map.

I found example of simple clustering from Mapbox Cluster Example but

My code is here, where marker ==> {marker-symbol} is from studio.

but it is not working. Is it possible to achieve output of cluster?


Solution

  • Solved By following code

    var layers = [
        [150],
        [20],
        [0]
    ];
    layers.forEach(function(layer, i) {
        map.addLayer({
            "id": "cluster-" + i,
            "source": "markers",
            "type": "symbol",
            "layout": {
                "text-field": "{point_count}",
                "text-font": [
                    "Arial Unicode MS Bold"
                ],
                "text-size": 13,
                "text-anchor": "bottom",
                "icon-image": "emptyMarker",
                "icon-size": 0.25
            },
            "paint": {
                "text-color": "white"
            },
            "filter": i === 0 ? [">=", "point_count", layer[0]] : ["all", [">=", "point_count", layer[0]],
                ["<", "point_count", layers[i - 1][0]]
            ]
        });
    });
    map.addLayer({
        "id": "cluster-count",
        "type": "symbol",
        "source": "markers"
    });