Mapbox - How can I have multiple values for a property and filter them independently

Viewed 453

I am using Mapbox API to upload a Tileset with companies data. For each of the companies I have 2 fields (Sectors and Tags) that may have more than one value, for example:

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

The values of these fields are an array in my GeoJSON field and are nested under the Properties node, however they are being imported as one String instead of individual values of that property, so if I want to setup a filter on my map based on Sectors to only display the IT companies, Acme will not be displayed because its Sectors property is: ["IT", "Engineering"]

This is my GeoJSON structure:

{  
   "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"
            ]
         }
      }
   ]
}

This is how my Mapbox style filter looks like:

enter image description here

1 Answers

Glen, I ended up having to create, for each one of my properties, individual values for each sector and tag, then marked them using numbers (1) and (0) depending if that sector / tag applies to that property. This way I was able to applied the filters I needed in 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
         }
      }
   ]
}

Related