利用Arcade表达式显示多行标签
要素图层依然是全球气象站点分布数据,属性表如下:
展示效果如下,显示的四行数据分别是属性表中的wind_name,temp,wind(运算之后的),r_humidity
本次尝试一次性写全所有的信息:
1、定义涉及到的变量:
var minscale = 250000000;
var featureurl = "https://services.arcgis.com/v6zhfr6zdgnzuvg0/arcgis/rest/services/weather_stations_010417/featureserver/0";
2、直接进入地图展示环节:
"esri/webmap","esri/views/mapview","esri/layers/featurelayer"
var view = new mapview({
container:"viewdiv",
map:new webmap({
portalitem:{id:"372b7caa8fe340b0a6300df93ef18a7e"},
layers:[new featurelayer({
url:featureurl,
renderer:{
type:"simple",
symbol:{
type:"simple-marker",
color:[75,75,75,0.7],
size:4,
outline:{
color:[0,0,0,0.7],
width:0.1
}
}
},
labelinginfo:[{
labelexpressioninfo:{
expression:document.getelementbyid("label-expression").text;
},
labelplacement:"center-right",
minscale = minscale,
symbol:{
type:"text",
font:{
size:9,
family:"noto sans"
}
},
horizontalalignment:"left",
color:"#2b2b2b"
}]
})]
}),
center:[-117.842, 33.799],
zoom:10
})
<script type="text/plain" id="label-expression">
var name = $feature.station_name;
var temp = round($feature.temp)+'° f';
var speed = $feature.wind_speed;
var deg = $feature.wind_direct;
var rh = $feature.r_humidity+'% rh';
var wind = when( speed == 0, null,
(deg < 22.5 && deg >= 0) || deg > 337.5, 'n',
deg >= 22.5 && deg < 67.5, 'ne',
deg >= 67.5 && deg < 112.5, 'e',
deg >= 112.5 && deg < 157.5, 'se',
deg >= 157.5 && deg < 202.5, 's',
deg >= 202.5 && deg < 247.5, 'sw',
deg >= 247.5 && deg < 292.5, 'w',
deg >= 292.5 && deg < 337.5, 'nw', null)
var label = [name,temp,wind,rh]
return concatenate(labels,textformatting.newline)
</script>