当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS ExpressionContent用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/popup/content/ExpressionContent"], (ExpressionContent) => { /* code goes here */ });

ESM: import ExpressionContent from "@arcgis/core/popup/content/ExpressionContent";

类: esri/popup/content/ExpressionContent

继承: ExpressionContent > Content > Accessor

自从:用于 JavaScript 4.22 的 ArcGIS API

用法说明

ExpressionContent 元素允许您使用 Arcade 表达式定义弹出内容元素。表达式必须计算为表示 TextContentFieldsContentMediaContent 弹出元素的字典,如 Popup Element web map specification 中定义的那样。

定义弹出内容的表达式通常使用元素的attributes 属性来引用在表或图表中的表达式内计算的值。

此内容元素专为图表、表格或富文本元素中的内容基于逻辑条件的高级方案而设计。例如,如果一个或多个字段中的数据为空,您可以使用此元素动态创建一个表,该表仅由包含有效数据值的字段组成。您还可以使用此元素创建由聚合数据值组成的图表或其他内容类型。这在 cluster popups 中特别有用。

例子:

// Creates an column chart where each category/value
// is an aggregate of two or more fields
layer.popupTemplate = {
  title: "Educational Attainment",
  content: [{
    type: "expression",
    expressionInfo: {
      expression: `
        // Create a dictionary of attributes representing the values
        // to display in the chart
        var attributes = {
          "No School": $feature.no_school + $feature.some_primary,
          "Primary": $feature.primary_complete + $feature.some_secondary,
          "Secondary": $feature.secondary_complete + $feature.some_highSchool,
          "High School": $feature.highSchool_diploma + $feature.highSchool_ged + $feature.some_college,
          "College/University": $feature.associates + $feature.bachelors + $feature.masters + $feature.doctorate + $feature.professional;
        };

        var fields = [];

        // Create an array representing the attribute names (or keys)
        for (var k in attributes){
          Push(fields, k);
        }

        // Returns a dictionary providing the information
        // required by the popup to render a column chart
        return {
          type: "media",
          attributes: attributes,
          title: "Educational attainment",
          mediaInfos: [{
            type: "columnchart",
            value: {
              // The list of attribute names (keys) to include in the chart
              fields: fields
            }
          }]
        };
      `,
      title: "Educational Attainment"
    }
  }]
};

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 ExpressionContent。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。