1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<scripttype="text/plain"id="predominance-arcade">// The fields from which to calculate predominance// The expression will return the alias of the predominant fieldvar fields = [
{ value: $feature.NOT_LABORFORCE_16, alias: "NOT participating in the labor force" },
{ value: $feature.CIVLBFR_CY, alias: "participating in labor the force" }
];
// Returns the predominant category as the alias// defined in the fields array. If there is a tie,// then both names are concatenated and used to// indicate the tiefunctiongetPredominantCategory(fieldsArray){
var maxValue = -Infinity;
var maxCategory = "";
for(var k in fieldsArray){
if(fieldsArray[k].value > maxValue){
maxValue = fieldsArray[k].value;
maxCategory = fieldsArray[k].alias;
} elseif (fieldsArray[k].value == maxValue){
maxCategory = maxCategory + "/" + fieldsArray[k].alias;
}
}
return maxCategory;
}
getPredominantCategory(fields);
</script>
另一个用于返回多类别的值。
1
2
3
4
5
6
7
<scripttype="text/plain"id="strength-arcade">// Returns the share of the dominant demographic as a percentagevar fieldValues = [ $feature.NOT_LABORFORCE_16, $feature.CIVLBFR_CY ];
var winner = Max(fieldValues);
var total = Sum(fieldValues);
return (winner/total) * 100;
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const arcadeExpressionInfos = [
{
name: "predominance-arcade",
title: "Is the majority (>50%) of the population 16+ participating in the labor force?",
// defined in separate script elementexpression: document.getElementById("predominance-arcade").text
},
{
name: "strength-arcade",
title: "% of population belonging to majority category",
// defined in separate script elementexpression: document.getElementById("strength-arcade").text
},
{
name: "not-working-arcade",
title: "Total population 16+ not employed or in labor force",
expression: "$feature.POP_16UP - $feature.EMP_CY" },
{
name: "%-not-working-arcade",
title: "% of population 16+ not employed or in labor force",
expression: "Round((($feature.POP_16UP - $feature.EMP_CY)/$feature.POP_16UP)*100,2) + '%'" }
];
popupTemplate.expressionInfos = arcadeExpressionInfos;
该 名称 用于引用 popupTemplate 内容中的表达式值。 名称必须以 表达式/ 开头。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
popupTemplate.content = [
{
type: "text",
text:
"In this county, {UNEMPRT_CY}% of the labor force is unemployed. " +
" {expression/strength-arcade}% of the {POP_16UP} people ages 16+" +
" living here are {expression/predominance-arcade}." },
{
type: "fields",
fieldInfos: [
{
fieldName: "expression/not-working-arcade",
format: {
digitSeparator: true,
places: 0 }
},
{
fieldName: "expression/%-not-working-arcade",
format: {
digitSeparator: true,
places: 0 }
}
]
}
];