可以使用带有 mapbox-gl-js 的一个数据层来显示点的子集吗?

Possible to show a subset of the points using one datalayer with mapbox-gl-js?

我在 Mapbox-gl-js 中有由点/标记组成的数据层。当我想将我的观点分成几类时,我可以使用数据样式,例如 this:

"source-layer": "sf2010",
    "paint": {
        "circle-radius": {
            "base": 1.75,
            "stops": [[12, 2], [22, 180]]
        },
        "circle-color": {
          property: 'ethnicity',
          type: 'categorical',
          stops: [
            ['White', "#fbb03b"], 
            ['Black', '#223b53'], 
            ['Hispanic', '#e55e5e'], 
            ['Asian', '#3bb2d0'], 
            ['Other', '#ccc']]
        }

看起来,使用一个数据层,所有点(可能具有不同的类别样式)都将包含在地图上。我可以通过给它一个零圆半径来设置一类点不显示的样式,但它仍然对点击等做出反应。或者有没有办法使用一个数据层真正呈现点的子集?

正如 Molly 所建议的,您需要一个过滤器:

    "source-layer": "sf2010",
    "paint": {
        "circle-radius": {
            "base": 1.75,
            "stops": [[12, 2], [22, 180]]
        },
        "circle-color": {
          property: 'ethnicity',
          type: 'categorical',
          stops: [
            ['White', "#fbb03b"], 
            ['Black', '#223b53'], 
            ['Hispanic', '#e55e5e'], 
            ['Asian', '#3bb2d0'], 
            ['Other', '#ccc']]
        }
   }, 
   "filter": ['!==', 'ethnicity','Martian']