[英]How to create expression for a specific case in Mapbox-gl-js?
Our Goal is to create Geo-json as light-weight as possible.我们的目标是创建尽可能轻量级的 Geo-json。 In order to achieve this we are making Geo-json properties key and value as small as possible.
为了实现这一点,我们使 Geo-json 属性的 key 和 value 尽可能小。
From:从:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": []//coordinates
},
"properties": {
"rotation": 0, //<-- Notice Keys
"size": 0.609524,
"text": "143",
"text-justify" : "left"
}
},
To到
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": []//coordinates
},
"properties": {
"r": 0,
"s": 0.609524,
"t": "143",
"tj": "l" //"l" is "left", "r" is right and "c" is center
}
},
And then on frontend while adding layer, will do something like below:然后在前端添加层时,将执行以下操作:
"layout": {
"text-justify": ['get', 'tj'] //<--- How to create this expression
"text-field": ['get', 't'],
"text-size":
[
'interpolate',
['exponential', 1.75],
['zoom'],
1, ["/", ["get", "s"], 5.15],
11, ["/", ["get", "s"], 0.01]
],
"text-rotate": ['get', 'r'],
}
So my question is: How to write expression for "text-justify" property as value's are "l"/"r"/"c" to be "left"/"right"/"center"?所以我的问题是:如何为“text-justify”属性编写表达式,因为值是“l”/“r”/“c”为“left”/“right”/“center”?
You can write it like this:你可以这样写:
"text-justify": ['match', ['get', 'tj'],
'l', 'left',
'r', 'right',
//...
'center'
]
If your goal is to send large data files statically to the browser, you might want to look at Geobuf as a more space-efficient format.如果您的目标是将大数据文件静态发送到浏览器,您可能希望将Geobuf视为一种更节省空间的格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.