javascript - 如何在 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”/“center”?
解决方案
你可以这样写:
"text-justify": ['match', ['get', 'tj'],
'l', 'left',
'r', 'right',
//...
'center'
]
如果您的目标是将大型数据文件静态发送到浏览器,您可能希望将Geobuf视为一种更节省空间的格式。
推荐阅读
- python - Python:如何获取列表中的对象,然后返回该对象的值(这是一个变量)?
- python - 在 Python 中按顺序运行 Powershell 命令
- javascript - 在 Excel VBA 中保存网页中 javascript 函数的结果
- sql - 想生成自定义唯一键并同时处理多个请求
- angularjs - 动态启用/禁用滑动器(触摸/鼠标)
- ios - WKWebview 超时
- android-studio - 如何在 Android Studio 中恢复 XML 代码样式设置
- pycharm - 无法接受 PyCharm 的条款和条件
- git - 如何使用 FULL COMMITS 将 git repo 迁移到 svn?
- abap - 如果输入不正确,如何禁用可编辑 ALV 网格?