多行标注

尝试一下在线预览

此示例演示如何使用 Arcade 表达式在 2D FeatureLayer 中标注要素。要显示标注,请将 FeatureLayer 的 labelInfo 属性设置为一个或多个标注分类。

所有标注表达式都是使用 Arcade 编写的,Arcade 允许您通过 $feature 全局变量访问要素属性。标注表达式在单独的脚本元素中定义,并使用 Concatenate Arcade 函数进行格式化。

标注使用 TextFormatting.NewLine Arcade 常量分隔为多行。请参阅标注指南页面,了解更多信息和已知限制。

                            
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
<script type="text/plain" id="label">
  // field storing wind direction as a number from 0 - 360
  var DEG = $feature.WIND_DIRECT;
  // field storing wind speed in mph
  var SPEED = $feature.WIND_SPEED;

  // The When() function will classify the wind direction
  // to a compass point (e.g. N, NW, S, SE)
  var DIR = 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 WIND = SPEED + ' mph ' + DIR;
  var TEMP = Round($feature.TEMP) + '° F';
  var RH = $feature.R_HUMIDITY + '% RH';
  var NAME = $feature.STATION_NAME;

  var labels = [ NAME, TEMP, WIND, RH ];

  // Concatenate all label variables in the same string
  // but on multiple lines
  return Concatenate(labels, TextFormatting.NewLine);
</script>

Arcade 表达式在 labelingInfo 中按以下方式引用。

                  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
labelingInfo: [
  {
    labelExpressionInfo: {
      expression: document.getElementById("label").text
    },
    labelPlacement: "center-right",
    minScale: minScale,
    symbol: {
      type: "text",
      font: {
        size: 9,
        family: "Noto Sans"
      },
      horizontalAlignment: "left",
      color: "#2b2b2b"
    }
  }
];

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.