Mapbox GL JS:当其他属性有效时,未知属性“text-halo-width”

问题描述 投票:0回答:1

使用 mapbox-gl 2.14.1,当我像这样为我的地图配置图层时:

        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'
            }
        });

我得到一个错误:

Error: layers.labels-layer.layout.text-halo-width: unknown property "text-halo-width"

该属性记录在网站 上,以及我正在使用的所有其他

text-*
属性。如果我删除该属性,一切正常。其他
text-halo-*
属性(在上面的示例中未使用)也会产生错误。

这是文档问题吗?还是我忽略了一些明显的东西?

mapbox-gl-js
1个回答
0
投票

仔细阅读文档后,我意识到

text-halo-width
和相关属性是paint属性,而不是layout属性,因此需要在不同的地方配置。

具体来说,这有效:

        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'
            }
        });

© www.soinside.com 2019 - 2024. All rights reserved.