Javascript mapbox数据驱动样式。为不在对象中的值设置颜色

Javascript 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

目前我正在这样设置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]]);
因此,对于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访问令牌。