當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。