Mapbox GL JS:其他属性可用,但出现未知属性”text-halo-width”

huangapple go评论45阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月11日 05:20:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定