mapbox 数据驱动风格。为不在对象中的值设置颜色
mapbox data driven style. setting color for values not in object
目前我正在像这样设置 paintproperty
this.map.setPaintProperty('da-highlighted', 'fill-color',
// get the id property and use it as a key into "values"
["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]]);
所以这对于 id 在 coloredDas 对象中的图块来说效果很好。但是它将未找到的颜色设置为黑色。无论如何我可以为不在对象中的值设置默认颜色吗?我希望它是透明的。不确定语法或者是否可能。我在网上找不到关于这个案例的任何信息。
我已根据答案尝试了以下方法
this.map.setPaintProperty('da-highlighted', 'fill-color',
// get the id property and use it as a key into "values"
[
'case',
['has', ["to-string", ['has', "DAUID"],["literal", coloredDas]], ["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]],
'blue'
]]
);
但收到以下错误:
Error: layers.da-highlighted.paint.fill-color: Expected at least 3 arguments, but found only 1.
我后来将查询格式化为:
[
'case',
['has', ["to-string", ['has', "DAUID"],["literal", coloredDas]]], [["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]]],
'blue'
]
然而我得到的错误是
Error: layers.da-highlighted.paint.fill-color[1][1]: Expected arguments of type (value), but found (boolean, object) instead.
您可以尝试使用 case
或 match
表达式。将它与您当前的 get
结合起来并提供一个 default
值。像这样:
[
'case',
[
'has',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
[
'get',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
'white'
];
在此处查看文档:https://www.mapbox.com/mapbox-gl-js/style-spec#expressions-case
这是一个演示 circle-color
paint 属性 表达式的 jsfiddle:https://jsfiddle.net/Scarysize/xwbxx3wq/14/
目前我正在像这样设置 paintproperty
this.map.setPaintProperty('da-highlighted', 'fill-color',
// get the id property and use it as a key into "values"
["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]]);
所以这对于 id 在 coloredDas 对象中的图块来说效果很好。但是它将未找到的颜色设置为黑色。无论如何我可以为不在对象中的值设置默认颜色吗?我希望它是透明的。不确定语法或者是否可能。我在网上找不到关于这个案例的任何信息。
我已根据答案尝试了以下方法
this.map.setPaintProperty('da-highlighted', 'fill-color',
// get the id property and use it as a key into "values"
[
'case',
['has', ["to-string", ['has', "DAUID"],["literal", coloredDas]], ["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]],
'blue'
]]
);
但收到以下错误:
Error: layers.da-highlighted.paint.fill-color: Expected at least 3 arguments, but found only 1.
我后来将查询格式化为:
[
'case',
['has', ["to-string", ['has', "DAUID"],["literal", coloredDas]]], [["get", ["to-string", ["get", "DAUID"]], ["literal", coloredDas]]],
'blue'
]
然而我得到的错误是
Error: layers.da-highlighted.paint.fill-color[1][1]: Expected arguments of type (value), but found (boolean, object) instead.
您可以尝试使用 case
或 match
表达式。将它与您当前的 get
结合起来并提供一个 default
值。像这样:
[
'case',
[
'has',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
[
'get',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
'white'
];
在此处查看文档:https://www.mapbox.com/mapbox-gl-js/style-spec#expressions-case
这是一个演示 circle-color
paint 属性 表达式的 jsfiddle:https://jsfiddle.net/Scarysize/xwbxx3wq/14/