如何在 Mapbox-gl-js 中为特定案例创建表达式?
How to create expression for a specific case in Mapbox-gl-js?
我们的目标是创建尽可能轻量级的 Geo-json。为了实现这一点,我们正在使 Geo-json 属性键和值尽可能小。
发件人:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": []//coordinates
},
"properties": {
"rotation": 0, //<-- Notice Keys
"size": 0.609524,
"text": "143",
"text-justify" : "left"
}
},
至
{
"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
}
},
然后在前端添加图层时,将执行如下操作:
"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'],
}
所以我的问题是:如何为“text-justify”编写表达式 属性 因为值是“l”/“r”/“c”为“left”/“right”/”中心”?
可以这样写:
"text-justify": ['match', ['get', 'tj'],
'l', 'left',
'r', 'right',
//...
'center'
]
如果您的目标是将大数据文件静态发送到浏览器,您可能希望将 Geobuf 视为更 space-efficient 的格式。
我们的目标是创建尽可能轻量级的 Geo-json。为了实现这一点,我们正在使 Geo-json 属性键和值尽可能小。
发件人:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": []//coordinates
},
"properties": {
"rotation": 0, //<-- Notice Keys
"size": 0.609524,
"text": "143",
"text-justify" : "left"
}
},
至
{
"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
}
},
然后在前端添加图层时,将执行如下操作:
"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'],
}
所以我的问题是:如何为“text-justify”编写表达式 属性 因为值是“l”/“r”/“c”为“left”/“right”/”中心”?
可以这样写:
"text-justify": ['match', ['get', 'tj'],
'l', 'left',
'r', 'right',
//...
'center'
]
如果您的目标是将大数据文件静态发送到浏览器,您可能希望将 Geobuf 视为更 space-efficient 的格式。