mapbox-gl-js - Mapbox 中的“step”表达式是如何工作的?
问题描述
步进函数如何在数组的 Mapbox 填充颜色属性中工作?尽管:
R=[ 'interpolate', ['linear'],['number',['get', dim_properties.name]], -150, "#800026", -133, "#bd0026", -116, "#e31a1c", -100, "#fc4e2a", -83, "#fd8d3c", -66, "#feb24c", -50, "#fed976", -33, "#ffeda0", -16, "#ffffcc", 0, "#ffffff"]
map.addLayer({
id: 'er',
type: 'fill',
source: {
type: 'vector',
url: pixelling_url
},
'source-layer':pixelling_source_layer,
paint: {
'fill-color':R
}
完美运行,
这个其他代码没有。
R=[ 'step',['get', dim_properties.name]], -150, "#800026", -133, "#bd0026", -116, "#e31a1c", -100, "#fc4e2a", -83, "#fd8d3c", -66, "#feb24c", -50, "#fed976", -33, "#ffeda0", -16, "#ffffcc", 0, "#ffffff"]
map.addLayer({
id: 'er',
type: 'fill',
source: {
type: 'vector',
url: pixelling_url
},
'source-layer':pixelling_source_layer,
paint: {
'fill-color':R
}
错误消息是:“paint.fill-color: Expected an even number of arguments
请注意,两段代码之间的区别仅在于 R 的定义。
解决方案
使用步骤表达式,您需要设置一个基值。如果愿意,只需删除第一个中断值即可解决您的问题。现在 Mapbox 在查找四个参数(表达式类型、属性值、基值、断点集合)时只读取三个参数(表达式类型、属性、断点集合)。基本上,您不需要定义最小值。Mapbox GL 将推断应该将基值分配给第一个断点以下的任何要素。在这种情况下,它将是满足条件的任何特征dim_properties.name < -133
R = [
'step', // arg 1
['get', 'dim_properties.name'], // arg 2
'#800026', // arg 3
-133, '#bd0026', // rest of the expression is arg 4
-116, '#e31a1c',
-100, '#fc4e2a',
-83, '#fd8d3c',
-66, '#feb24c',
-50, '#fed976',
-33, '#ffeda0',
-16, '#ffffcc',
0, '#ffffff'
]
推荐阅读
- r - R:如何从 XY 数据框中检测和绘制多边形边缘
- android - 视频无法在 WebView android 中呈现
- javascript - How to convert a date to ISO format but with timezone info in place of the 'Z' in Javascript?
- php - Facebook Custom Audience Marketing API / Graph API 提供 200 ok 状态,但什么也不做
- image - 如何在 oracle apex 中显示图像(在表格中保存为 LONG RAW 数据类型的图像)
- python-3.x - PostgreSQL 和 PostGIS 用于提取 ROI 多边形覆盖的特定区域
- c# - 可枚举类型属性的元素的属性的路径表达式
- python - C++ 对 Python 的扩展——安全的内存访问和内存布局
- sprite - 在 2-D 游戏中碰撞时,什么可能导致精灵停止定向运动(精灵仍然有动画)?
- php - 如何通过读取文件来动态添加 cron 作业,而与服务器无关