Apparently drawing text labels is only possible if using a Mapbox basemap?
When using another map provider (such as stamen or osm), upon adding a layer which uses text-field, it throws:
Error: layers.symbols.layout.text-field: use of "text-field" requires a style "glyphs" property
Here is a working example with a mapbox vector tile source for the basemap:
http://jsfiddle.net/brianssheldon/wm18a33d/27/
And here is the same code, just with another basemap provider (here: osm, but same behavior with stamen):
http://jsfiddle.net/wm18a33d/38/
Is there a workaround? This would completely derail using mapbox-gl in my project if true.
adding "glyphs": "http://fonts.openmaptiles.org/{fontstack}/{range}.pbf" works.
For others getting stuck on this, you need to add the "glyphs" property on the same level as "sources" and "layers". And you need to use a provider that has the fonts you use. For example for Mapbox example derivations you probably want "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf".
For OSM and other non Mapbox layers, see:
https://openmaptiles.org/docs/style/mapbox-gl-style-spec/
https://github.com/openmaptiles/fonts
They're served from Github via "glyphs": "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf" where fontstack will be font name from https://github.com/openmaptiles/fonts/tree/gh-pages — for example "Open Sans Bold", when defined in your layer like so:
{
// ...
layout: {
'text-font': ['Open Sans Bold'],
},
}
You should add layers which render text only after main style is loaded, i.e. in map.on("styledata", …)
Most helpful comment
For others getting stuck on this, you need to add the
"glyphs"property on the same level as"sources"and"layers". And you need to use a provider that has the fonts you use. For example for Mapbox example derivations you probably want"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf".