Mapbox Mpabox GL案例表达式输出,执行数学表达式

Mapbox Mpabox GL案例表达式输出,执行数学表达式,mapbox,mapbox-gl-js,Mapbox,Mapbox Gl Js,Hi问题不是在满足条件后返回输出,而是应用一些数学运算并将结果返回到文本字段。 Mapboxgl js版本1.11.0 "text-field": [ "case", ['all', [">=", ["abs", ["get", "count"]], 1.0e+3]], //if thousands ["/",

Hi问题不是在满足条件后返回输出,而是应用一些数学运算并将结果返回到文本字段。 Mapboxgl js版本1.11.0

  "text-field": [
     "case",
    ['all', [">=",   ["abs", ["get", "count"]], 1.0e+3]], //if thousands
   
    ["/", ["get", "count"], 1.0e+3], //<--- doesn't work perform division, should return 1 if count is 1000
    
     ["get", "count"] //fallback value 
   ],
“文本字段”:[
“案件”,
['all',[“>=”,[“abs”,[“get”,“count”]],1.0e+3]],//如果有千

[“/”、[“get”、“count”]、1.0e+3]、//出来的问题是类型,我尝试在case表达式输出中执行数学运算,但没有将其带到类型number,在添加了“to string”(用于结果)和“number”(用于操作本身)之后,它得到了解决,格式化效果非常好。 这是可行的解决方案

    "text-field": [
    "case",
     // Billions  
    ["all", [">=",   ["abs", ["get", "usersCount"]], 1.0e+9]], 
    // divide usersCount by 1 billion, than strigify("to-string"), and concat result with string "B" same for all
    ["concat", ["to-string", ["round", ["/", ["number", ["get", "usersCount"]], ["number", 1000000000]]]], 'B'],
    
    ["all", [">=",   ["abs", ["get", "usersCount"]], 1.0e+6]],
    ["concat", ["to-string", ["round", ["/", ["number", ["get", "usersCount"]], ["number", 1000000]]]], "M"] ,

    ["all", [">=", ["abs", ["get", "usersCount"]], 1.0e+3]],
    ["concat",["to-string",  ["round", ["/", ["number", ["get", "usersCount"]], ["number", 1.0e+3]]]], "K"],
    //if none of above (1-10) return the value itself 
    ["get", "usersCount"]
  ],

希望这会对某人有所帮助

嗨,本,我想你要做的是显示
1.2
如果count是
1200
,但保持
700
,例如(1000以下的)不变?你能试一下
“文本字段”:[“/”,[“get”,“count”],1000]
看看它是否能自己工作?然后我们可以尝试重新添加条件。如果这不是你要问的,你可以尝试重新编写问题,可能添加完整的样式,如果可能的话添加一个示例地图吗?另外,你能提一下它使用的是什么平台(iOS、Android、JS)?如果是JavaScript,还要告诉我们您是将映射指向该样式的JSON文件还是将样式对象直接传递到映射?如果您使用JSON(无论哪个平台),请删除注释(如果它们在原始代码中),并用
'all'
替换
'all'
,因为JSON不支持单引号。@Rafaelalmeda,我们使用mapbogl js,版本1.11.0。感谢您的时间和帮助,我已经解决了这个问题,问题是,使用大小写表达式的输出类型,所以一旦我将除法运算的输出更新为字符串类型,一切都很好。