英文:
Mapbox GL JS: unknown property "text-halo-width" when other properties work
问题
Using mapbox-gl 2.14.1, when I configure a layer for my map like this:
map.addLayer({
'id': 'labels-layer',
'type': 'symbol',
'source': 'labels-source',
'layout': {
'text-field': ['get', 'description'],
'text-halo-width': 1,
'text-font': ["Lato Bold"],
'text-size': 14,
'text-max-width': 20,
'text-variable-anchor': ['left', 'bottom', 'top', 'right'],
'text-radial-offset': 0.5,
'text-justify': 'auto'
}
});
I get an error: Error: layers.labels-layer.layout.text-halo-width: unknown property "text-halo-width"
The property is documented on the website, alongside all of the other text-*
properties I'm using. If I remove that property, everything works fine. The other text-halo-*
properties (not used in the example above) also produce errors.
Is this a documentation problem? Or am I overlooking something obvious?
英文:
Using mapbox-gl 2.14.1, when I configure a layer for my map like this:
map.addLayer({
'id': 'labels-layer',
'type': 'symbol',
'source': 'labels-source',
'layout': {
'text-field': ['get', 'description'],
'text-halo-width': 1,
'text-font': ["Lato Bold"],
'text-size': 14,
'text-max-width': 20,
'text-variable-anchor': ['left', 'bottom', 'top', 'right'],
'text-radial-offset': 0.5,
'text-justify': 'auto'
}
});
I get an error: Error: layers.labels-layer.layout.text-halo-width: unknown property "text-halo-width"
The property is documented on the website, alongside all of the other text-*
properties I'm using. If I remove that property, everything works fine. The other text-halo-*
properties (not used in example above) also produce errors.
Is this a documentation problem? Or am I overlooking something obvious?
答案1
得分: 1
在仔细阅读文档后,我意识到text-halo-width
和相关属性是绘制属性,而不是布局属性,因此需要在不同的地方配置。
具体来说,这段代码有效:
map.addLayer({
'id': 'labels-layer',
'type': 'symbol',
'source': 'labels-source',
'layout': {
'text-field': ['get', 'description'],
'text-font': ["Lato Bold"],
'text-size': 14,
'text-max-width': 20,
'text-variable-anchor': ['left', 'bottom', 'top', 'right'],
'text-radial-offset': 0.5,
'text-justify': 'auto'
},
'paint': {
'text-halo-width': 1,
'text-halo-color': 'white'
}
});
注意:我只翻译了您提供的代码部分,不包括其他内容。
英文:
Upon closer reading of the documentation, I realized that text-halo-width
and related properties are paint properties, not layout properties, and so need to be configured in a different place.
Specifically, this works:
map.addLayer({
'id': 'labels-layer',
'type': 'symbol',
'source': 'labels-source',
'layout': {
'text-field': ['get', 'description'],
'text-font': ["Lato Bold"],
'text-size': 14,
'text-max-width': 20,
'text-variable-anchor': ['left', 'bottom', 'top', 'right'],
'text-radial-offset': 0.5,
'text-justify': 'auto'
},
'paint': {
'text-halo-width': 1,
'text-halo-color': 'white'
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论