根据自定义属性过滤器添加图层

时间:2019-03-06 16:58:57

标签: mapbox mapbox-gl

如何根据自定义属性过滤条件添加图层。

具有geojson数据

"totalFeatures": 1183,
"features": [{
    "type": "Feature",
    "id": "roster.fid-4a55c78_1693df1db69_-3cca",
    "geometry": {
        "type": "Point",
        "coordinates": [
            46.7643157,
            24.7604933
        ]
    },
    "geometry_name": "driver_geom",
    "properties": {
        "id": 28181,
        "status": "ToPickup",
        "created": "2019-03-02T10:27:39.582Z",
        "vc": 16400,
        "utc": "2019-03-02T10:27:38.976Z",
        "pit": 1,
        "jobs": 1,
        "vel": 0.897656,
        "dir": 97,
        "referenceid": 8159926,
        "dispatchid": 6543135,
        "distance": 7.5114408,
        "age": 1.313166,
        "dispatches": "6543135",
        "numdispatches": 1,
        "imei": "860119042739125",
        "mobile": "966504411206",
        "name": "Sami Balsharaf",
        "org_id": 11,
        "orgname": "ALAMAT - Driver",
        "ceased": false,
        "username": "966504411206"
    }
}]

我需要基于Feature.properties.status创建图层,例如在线或离线或可用

我已经尝试了以下步骤,但是没有任何一个可以帮助我。

map.on('load', function() {
    // 'cluster' option to true. GL-JS will add the point_count property to your source data.
    map.addSource("drivers_info", {
        type: "geojson",
        // Point to GeoJSON data. This example visualizes all M1.0+ Drivers
        data: './map.geojson',
        cluster: true,
        clusterMaxZoom: 14, // Max zoom to cluster points on
        clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50)
    });

    map.addLayer({
        id: "cluster-drivers",
        type: "symbol",
        source: "drivers_info",
        filter: ["==", "$properties.status", "Available"],
        layout: {
            "text-field": "{point_count_abbreviated}",
            "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
            "text-size": 12
        }
    });
});

0 个答案:

没有答案
相关问题