Mapbox GL js: How to enumerate all textfield properties to display a sub element

17 views Asked by At

Is there a way to parse all textfield properties in a foreach display a sub element with Mapbox GL js? In my example I add a layer with the id test and want to add a title over a circle.

Code
map
    .current
    .addLayer({
        id: LOCATIONS_LAYER_ID,
        type: "circle",
        source: "locations",
        filter: ['!', ['has', 'point_count']],
        paint: {
            "circle-color": "#4264fb",
            "circle-radius": 6,
            "circle-stroke-width": 2,
            "circle-stroke-color": "#fff"
        }
    })
    .addLayer({
        id: "test",
        type: "symbol",
        source: "locations",
        filter: ['!', ['has', 'point_count']],
        layout: {
            "text-field": ['get', 'alias'],
            "text-variable-anchor": ['top', 'bottom', 'left', 'right'],
            "text-radial-offset": 1,
            "text-justify": 'auto',
        }
    })

I´ve tried a lot of ideas for example to change "text-field": ['get', 'alias'], to something like "text-field": ['at', 0, ['get', 'alias']],. Also a workaround like in this thread didn´t work.

Sample Data

enter image description here

I need to display a title in a MapBox symbol/circle.

0

There are 0 answers