首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mapbox-gl js使用阶跃斜坡作为“文本偏移”。

mapbox-gl js使用阶跃斜坡作为“文本偏移”。
EN

Stack Overflow用户
提问于 2018-07-16 12:10:45
回答 2查看 1.5K关注 0票数 4

我在layout-block中的mapbox层中使用字段text-offset

代码语言:javascript
复制
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'非常有效,但是对于文本偏移量,我无法找到正确的语法。我试过以下几种方法:

代码语言:javascript
复制
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-偏移量:期望值,数组找到

代码语言:javascript
复制
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找到

代码语言:javascript
复制
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-偏移量:期望值,数组找到

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-17 14:36:44

您需要用文字类型转换器包装文本偏移量值:

代码语言:javascript
复制
'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不明确,所以您需要显式地告诉它们的类型。

票数 2
EN

Stack Overflow用户

发布于 2020-01-08 02:48:44

1.6.1版本中,我没有测试其他版本。

您只需要在properties中设置一个数组,

比如"offsetdate": [-1,0]

然后使用"text-offset": ['get', 'offsetdate']获取数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51361544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档