如何根据Mapbox js中位于其后面的位置的属性绘制聚类圆?

时间:2019-04-06 20:15:28

标签: javascript reactjs mapbox mapbox-gl-js mapbox-gl

我有一张包含3层的地图:

  1. 集群层,2.集群计数器层,3.points层。

点是每个位置都有一个属性的一些位置-> locationStatus。 根据这种状态,我将这一点涂成黑色  或黄色。我现在尝试根据其后面位置的属性来设置聚类圆的样式,所以

如果此聚类后面的所有位置的状态均为== 0,则聚类圆将为黄色

如果所有位置的状态均为== 1,则聚类圆将为黑色

否则,如果两个位置的状态都为1和2,则聚类圆圈将为黑色和黄色。

到目前为止,我发现的是根据位置的数量更改群集的颜色。我要尝试的是按位置状态过滤位置。 https://docs.mapbox.com/mapbox-gl-js/example/cluster/

map.addLayer({
                    id: "clusters",
                    type: "circle",
                    source: "wemap",
                    filter: ["has", "point_count"],
                    paint: {
                        "circle-stroke-width": 4,
                        "circle-stroke-color": "#fff",
                        "circle-color": [
                            "step",
                            ["get", "point_count"],
                            "#8398af",
                            100,
                            "#8398af",
                            750,
                            "#8398af"
                        ],
                        "circle-radius": [
                            "step",
                            ["get", "point_count"],
                            17,
                            100,
                            17,
                            750,
                            17
                        ]
                    }
                });

                map.addLayer({
                    id: "cluster-count",
                    type: "symbol",
                    source: "wemap",
                    filter: ["has", "point_count"],
                    layout: {
                        "text-field": "{point_count_abbreviated}",
                        "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
                        "text-size": 13,

                    },
                    paint: {
                        "text-color": "#ffffff"
                    }
                });

                map.addLayer({
                    id: "points",
                    type: "circle",
                    source: "wemap",
                    filter: ["!", ["has", "point_count"]],
                    paint: {
                        "circle-stroke-width": 2,
                        'circle-color': ['get', 'markerColor'],
                        "circle-radius": 6,
                        "circle-stroke-color": "#fff",
                    }
                });

这就是我为位置创建功能的方式:

var features = this.props.locations.map((item, i) => {
            return {
                "type": "Feature",
                "properties": {
                    "markerColor": item.locationStatus === 0 ? '#000' : '#f8c146',
                    "description": createDescription(item)
                },
                "geometry": {
                    "type": "Point",
                    "coordinates": [item.longitude, item.latitude]
                }
            }
        });

0 个答案:

没有答案