how to customise cluster icon in mapbox-gl?

痴心易碎 提交于 2019-12-06 12:15:59

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"
});

I think the solution is:
1. You calculate all the center's bound of the children's marker,
and store them as clusters's marker
2. You have to control the Zoom action,
if it is greater than 15 then you only show the children's marker
else if it lesser than 15 then you only show the clusters's marker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!