首页 > 解决方案 > Mapbox - 如何为一个属性设置多个值并独立过滤它们

问题描述

我正在使用 Mapbox API 上传带有公司数据的 Tileset。对于每家公司,我都有 2 个可能具有多个值的字段(部门和标签),例如:

Company name: Acme
Sectors: IT, SmartTech
Tags: digital, smart, application

这些字段的值是我的 GeoJSON 字段中的一个数组,并嵌套在 Properties 节点下,但是它们作为一个字符串而不是该属性的单个值被导入,所以如果我想根据 Sectors 在我的地图上设置一个过滤器只显示 IT 公司,Acme 不会显示,因为它的 Sectors 属性是:["IT", "Engineering"]

这是我的 GeoJSON 结构:

{  
   "type":"FeatureCollection",
   "features":[  
      {  
         "id":45543000000218192,
         "type":"Feature",
         "geometry":{  
            "type":"Point",
            "coordinates":[  
               1.475,
               52.796
            ]
         },
         "properties":{  
            "Company":"Acme",
            "Website":"",
            "Sectors":[  
               "SmartTech",
               "IT"
            ],
            "Tags":[  
               "digital",
               "smart",
               "application"
            ]
         }
      }
   ]
}

这就是我的 Mapbox 样式过滤器的样子:

在此处输入图像描述

标签: listapipropertiesmapboxgeojson

解决方案


Glen,我最终不得不为我的每个属性创建每个扇区和标签的单独值,然后使用数字 (1) 和 (0) 标记它们,具体取决于该扇区/标签是否适用于该属性。这样我就可以在 Mapbox 中应用我需要的过滤器。

{  
   "type":"FeatureCollection",
   "features":[  
      {  
         "id":45543000000218192,
         "type":"Feature",
         "geometry":{  
            "type":"Point",
            "coordinates":[  
               1.475,
               52.796
            ]
         },
         "properties":{  
            "Company":"Acme",
            "Website":"",
            "Sector - SmartTech": 0,
            "Sector - IT": 1,
            "Tag - Digital": 0,
            "Tag - Smart": 1,
            "Tag - Apps": 1
         }
      }
   ]
}


推荐阅读