How to add background color for layer text field in mapbox-gl

how to add a background color for a text field of a layer in mapbox-gl .. or how can this be done so that there is a background field in the text field

map.addLayer({ "id": "markers", "type": "symbol", "source": "markers", "layout": { "icon-image": "{marker-symbol}-15", "text-field": "{title}", "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-offset": [0, 0.6], "text-anchor": "top" } }); 
+6
source share
1 answer

While I also donโ€™t know how to draw a background window, we can look for the very same thing that should hide any other text under the userโ€™s shortcut so that it appears and is more legible. If so, I found that you can add a โ€œhaloโ€ that will achieve the desired effect.

 "layout": { "icon-image": symbol + "-15", "icon-allow-overlap": true, "text-field": symbol, "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"], "text-size": 11, "text-transform": "uppercase", "text-letter-spacing": 0.05, "text-offset": [0, 1.5] }, "paint": { "text-color": "#202", "text-halo-color": "#fff", "text-halo-width": 2 }, 

This was taken from this example on their website.

+1
source

All Articles