步进函数如何在数组的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:预期参数为偶数
请注意,这两个代码片段之间的区别仅在于R的定义。
答案 0 :(得分:1)
对于步骤表达式,您需要设置一个基本值。如果愿意,只需删除第一个中断值即可解决问题。现在,当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'
]