[英]How to set "text-font" with mapbox expressioins
I am trying to set the font with the help of Mapbox expressions from font_size field.我试图在 font_size 字段中的 Mapbox 表达式的帮助下设置字体。 This doesn't work for me (Invalid data expression for "text-font". Output values must be contained as literals within the expression)
这对我不起作用(“文本字体”的数据表达式无效。输出值必须作为文字包含在表达式中)
"text-font": [
"case",
['!=', ["get", "text_font"], ""],
["get", "text_font"],
['literal',['DIN Offc Pro Italic', 'Arial Unicode MS Regular']]
],
So I want to get a text-font from text_font: ["Open Sans Semibold Italic"]
and if it is empty like text_font: ""
use ['DIN Offc Pro Italic', 'Arial Unicode MS Regular']
Thanks所以我想从
text_font: ["Open Sans Semibold Italic"]
获取文本字体,如果它像text_font: ""
一样为空,请使用['DIN Offc Pro Italic', 'Arial Unicode MS Regular']
谢谢
I think the error message is telling you what you need to know, but don't want to hear:我认为错误消息告诉你你需要知道什么,但不想听到:
Invalid data expression for "text-font".
“文本字体”的无效数据表达式。 Output values must be contained as literals within the expression.
输出值必须作为文字包含在表达式中。
The output values (that is, the font that is going to be set) must be specified as a literal - not derived from a feature property.输出值(即将要设置的字体)必须指定为文字 - 而不是从特征属性派生。
So you could do something like this as a workaround:所以你可以做这样的事情作为解决方法:
"text-font": [
"match", ["get", "text_font"],
"Open Sans Semibold Italic", ["literal", ["Open Sans Semibold Italic"]],
"Arial", ["literal", ["Arial"]],
// ... all possible values ...
['literal',['DIN Offc Pro Italic', 'Arial Unicode MS Regular']]
]
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.