'使用“文本字段”需要样式“glyphs”财产当使用纯色背景时
我使用的是纯背景,而不是使用 MapBox 样式,按照 这个答案
var map = new mapboxgl.Map({
container: 'map',
style: {
version: 8,
sources: {},
layers: [
{
id: 'background',
type: 'background',
paint: {'background-color': 'white'}
}
]
}
});
我添加了一个 GeoJSON
点图层,我正在尝试对其进行标记:
'layout': {
'text-field': ['get', 'name'],
'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
},
如果我对地图使用标准 MapBox 样式,则该图层会被正确标记。但如果我使用前面提到的空白底图,该图层将返回错误:
使用“文本字段”需要样式“glyphs”属性
搜索此错误消息表明我需要添加一个 glyphs
选项:
"glyphs":"mapbox://fonts/mapbox/{fontstack}/{range}.pbf"
或 "glyphs":"https://fonts.openmaptiles.org/{ fontstack}/{range}.pbf"
但是,这两个选项都不能阻止错误消息,并且该图层不会被标记。
使用空底图时,glyphs
参数的正确语法是什么?
I'm using a plain background, rather than using a MapBox style, as per this answer
var map = new mapboxgl.Map({
container: 'map',
style: {
version: 8,
sources: {},
layers: [
{
id: 'background',
type: 'background',
paint: {'background-color': 'white'}
}
]
}
});
I've added a GeoJSON
point layer and I'm trying to label it:
'layout': {
'text-field': ['get', 'name'],
'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
},
If I use a standard MapBox style for the map, the layer is correctly labelled. But if I use the aforementioned blank basemap, this layer returns the error:
use of "text-field" requires a style "glyphs" property
Searching this error message shows that I need to add a glyphs
option:
"glyphs":"mapbox://fonts/mapbox/{fontstack}/{range}.pbf"
or "glyphs":"https://fonts.openmaptiles.org/{fontstack}/{range}.pbf"
However, neither of these options prevents the error message, and the layer is not labelled.
What is the correct syntax for the glyphs
parameter when using an empty basemap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将其复制到我的样式选项中,当我以前遇到与您相同的错误时,它工作正常,没有错误:
https://github.com/mapbox/mapbox-gl-styles/blob/master/styles/empty-v8.json
I copied this for my style option and it worked fine with no errors when I previously had the same error as you:
https://github.com/mapbox/mapbox-gl-styles/blob/master/styles/empty-v8.json
作为解决方法,我在 MapBox Studio 中创建了一个新的空白样式并将其用作底图。此后,标签正确显示。
不过,我仍然想知道是否有一种编程方式可以使用 MapBox GL-JS API 来执行此操作。
As a workaround, I created a new Blank style in MapBox Studio and used that as the basemap. After this, the labels appeared correctly.
I'd still like to know if there's a programmatic way to do this using the MapBox GL-JS API though.
当我不小心尝试将地图的样式设置为
未定义
时,我遇到了此错误。当我修复了错误并提供了合法的mapbox://
样式 URL 后,问题就消失了。I ran into this error when I accidentally attempted to set my map's style to
undefined
. The problem went away when I fixed the bug and instead provided a legitimatemapbox://
style URL.