我在layout-block中的mapbox层中使用字段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现在不支持文本偏移的阶梯坡道?
错误信息:
错误:layers.cluster-offline.layout.text-偏移量:期望值,数组找到
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-偏移量:数组长度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-偏移量:期望值,数组找到
发布于 2018-07-17 14:36:44
您需要用文字类型转换器包装文本偏移量值:
'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不明确,所以您需要显式地告诉它们的类型。
发布于 2020-01-08 02:48:44
在1.6.1版本中,我没有测试其他版本。
您只需要在properties中设置一个数组,
比如"offsetdate": [-1,0],
然后使用"text-offset": ['get', 'offsetdate']获取数据。
https://stackoverflow.com/questions/51361544
复制相似问题