how to customise cluster icon in mapbox-gl?

我与影子孤独终老i 提交于 2019-12-22 14:02:14

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/42524947/how-to-customise-cluster-icon-in-mapbox-gl

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