Javascript mapbox数据驱动样式。为不在对象中的值设置颜色
目前我正在这样设置paintpropertyJavascript mapbox数据驱动样式。为不在对象中的值设置颜色,javascript,mapbox,mapbox-gl-js,Javascript,Mapbox,Mapbox Gl Js,目前我正在这样设置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]]); 因此,对于c
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]]);
因此,对于coloredDas对象中id为的tiles来说,这很好。但它将未发现的颜色设置为黑色。是否可以为不在对象中的值设置默认颜色?我希望它是透明的。不确定语法或者它是否可能。我在网上找不到关于这个案子的任何信息
根据答案,我尝试了以下方法
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.
您可以尝试使用
大小写
或匹配
表达式。将其与当前的get
组合,并提供一个默认值。大概是这样的:
[
'case',
[
'has',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
[
'get',
['to-string', ['get', 'DAUID']],
[
'literal',
colors
]
],
'white'
];
请在此处查看文档:
下面是一个JSFIDLE演示了圆形颜色绘制属性的表达式:这似乎不起作用。。。告诉我一些关于object literal的信息噢,很抱歉,对于get
和has
你仍然不应该将添加到你问题中已经得到的字符串和literal
表达式中。我编辑了我的答案以显示你的查询结果。我用正确的表达式更新了我的答案。还有一个jsfiddle,您可以在其中检查解决方案,只需添加mapbox访问令牌。