Data-joins with Mapbox free country Boundaries

Viewed 37

I'm trying to style MapBox countries based on a specific rating that varies from 1-5. So the idea is to use that rating to set a different colour for each rating:

MapBox.map.addLayer({
    id: 'country-layer',
    type: 'fill',
    source: 'countryTiles',
    'source-layer': 'country_boundaries',
    paint: {
        'fill-color':
        [
            'match',
            ['get', 'travelRiskRating'],
            1, '#90C388',
            2, '#D3B446',
            3, '#F0682B',
            4, '#F22F2F',
            5, '#741106',
            '#5FE9D0'
        ]
    }
})

So basically to achieve it I would need to use the setFeatureState(link) function to add that property to the source feature (country). This is a concept described by MapBox as Data-Joins and it's really well described in their tutorial.

As described in the tutorial:

Using feature state requires knowing the unique feature id property for each boundary in the vector tiles to manipulate its rendering. In the Mapbox Boundaries lookup tables, feature_id is this unique integer-only identifier.

Also in the Feature lookup tables it says:

The Mapbox Boundaries lookup tables are JSON and CSV files that are delivered to you when you buy access to Boundaries. They provide extra information about features that is not directly available in the vector tiles.

So, it's nice to know that this extra data will come with other boundaries when I buy them, the problem is that the country boundaries (mapbox.country-boundaries-v1) are free and there is no way to find that feature_id. I've searched everywhere and tried many ways to somehow give an additional value to the country feature without success. The best I could achieve was to somehow log the features of the countries that come with the boundaries (thanks to this post), just to discover some id (of the feature?) to be equal to undefined

enter image description here

I wonder if I'm missing something, how to get it, or achieve what I'm trying to achieve. I wonder if this feature_id or lookup tables are provided already somewhere, or will be provided if I pay for this "free" version of country boundaries?

I will appreciate any help or clarifications here.

0 Answers
Related