[英]mapbox-gl js use step ramp for "text-offset"
我在layout
中的 mapbox gl 层中使用 -block 字段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'
,但对于 text-offset 我找不到正确的语法。 我尝试了以下方法:
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]:预期数字,找到数组
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]:预期数字,找到数组
您需要使用文字类型转换器包装文本偏移值:
'text-offset': [
'step', // Expression type (discrete matching)
['get', 'point_count'], // Variable to compare to
['literal', [-0.84, 0.23]], // Default value (if none of the following match)
10, ['literal', [-0.94, 0.25]], // if point_count === 10: [-0.94, 0.25]
100, ['literal', [-0.99, 0.28]] // if point_count === 100: [-0.94, 0.28]
]
停止输出值必须是文字值(即不是函数或表达式)
这里, [-0.84, 0.23]
子表达式可能对 Mapbox 有歧义,因此您需要明确告知它们的类型。
在1.6.1
版本中,我没有测试其他版本。
你只需要在properties
设置一个数组,
例如"offsetdate": [-1,0]
,
然后使用"text-offset": ['get', 'offsetdate']
获取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.