我在 -block layout
the field的 mapbox gl 层中使用text-offset
。
layout: { // Working
'text-field': '{point_count_abbreviated}',
'text-size': ['step', ['get', 'point_count'], 18, 10, 14, 100, 12],
'text-offset': [-0.84, 0.23],
}
这按预期工作,但现在我想根据属性更改偏移量。这对 . 来说效果很好'text-size'
,但对于文本偏移我找不到正确的语法。我尝试了以下方法:
layout: { // NOT working
'text-field': '{point_count_abbreviated}',
'text-size': ['step', ['get', 'point_count'], 18, 10, 14, 100, 12],
'text-offset': [
// [-0.84, 0.23],
['step', ['get', 'point_count'], -0.84, 10, -0.94, 100, -0.99],
['step', ['get', 'point_count'], 0.23, 10, 0.25, 100, 0.28],
],
},
也许 mapbox-gl 目前不支持文本偏移处的阶梯斜坡?
错误信息:
错误:layers.cluster-offline.layout.text-offset[0]: number expected, array found
layout: { // NOT working
'text-field': '{point_count_abbreviated}',
'text-size': ['step', ['get', 'point_count'], 18, 10, 14, 100, 12],
'text-offset': [
// [-0.84, 0.23],
['literal',
['step', ['get', 'point_count'], -0.84, 10, -0.94, 100, -0.99],
['step', ['get', 'point_count'], 0.23, 10, 0.25, 100, 0.28]
],
],
},
错误信息:
错误:layers.cluster-offline.layout.text-offset:预期数组长度 2,找到长度 1
layout: { // NOT working
'text-field': '{point_count_abbreviated}',
'text-size': ['step', ['get', 'point_count'], 18, 10, 14, 100, 12],
'text-offset': [
['literal', ['step', ['get', 'point_count'], -0.84, 10, -0.94, 100, -0.99]],
['literal', ['step', ['get', 'point_count'], 0.23, 10, 0.25, 100, 0.28]],
],
},
错误信息:
错误:layers.cluster-offline.layout.text-offset[0]: number expected, array found