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


JavaScript ArcGIS PopupTemplate.fieldInfos用法及代碼示例


基本信息

以下是所在類或對象的基本信息。

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

ESM: import PopupTemplate from "@arcgis/core/PopupTemplate";

類: esri/PopupTemplate

繼承: PopupTemplate > Accessor

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

PopupTemplate.fieldInfos函數(或屬性)的定義如下:

fieldInfos FieldInfo[] autocast


FieldInfo 數組,用於定義數據集中的字段或 Arcade 表達式中的值如何參與彈出窗口。如果未指定FieldInfo,則不會顯示任何內容,因為彈出窗口將僅顯示此數組定義的字段。每個 FieldInfo 包含單個字段或表達式的屬性。此屬性可以直接在 PopupTemplate 或 fields content element 內設置。如果這沒有在 fields content element 中設置,它將默認為直接在 PopupTemplate.fieldInfos 中指定的任何內容。左邊的圖像是使用下麵第一個示例片段的結果,而右邊的圖像是第二個片段的結果。

使用此fieldInfos 屬性為圖表或文本元素中顯示的數字指定任何格式選項。

使用 'fields' 類型設置的內容 從 fieldInfo 中設置的字段引用的內容
popuptemplate-fields popuptemplate-fieldinfocontent

例子:

// This snippet demonstrates how to show only a subset of fields.
// By setting the 'type: "fields"', and providing the fieldInfos,
// only field data will display within this feature layer's popuptemplate.
// If no fieldInfos is specified directly in the content, the popup defaults
// to whatever is set in the popupTemplate.fieldInfos.
let popupTemplate = new PopupTemplate({
  // autocasts as new PopupTemplate()
  title: "{NAME} in {COUNTY}",
  outFields: ["*"],
  content: [{
    // It is also possible to set the fieldInfos outside of the content
    // directly in the popupTemplate. If no fieldInfos is specifically set
    // in the content, it defaults to whatever may be set within the popupTemplate.
    type: "fields",
    fieldInfos: [{
      fieldName: "B12001_calc_pctMarriedE",
      label: "Married %"
    },{
      fieldName: "B12001_calc_numMarriedE",
      label: "People Married",
      format: {
        digitSeparator: true,
        places: 0
      }
    }]
  }]
});
// This snippet demonstrates setting the popup's content by referencing
// specific fields defined within the popupTemplate's fieldInfos.
let popupTemplate = new PopupTemplate({
  title: "{NAME} in {COUNTY}",
  outFields: ["*"],
  content: "Census data indicates that {B12001_calc_numMarriedE} people were married in {NAME}, {COUNTY}. The overall percentage of married people is {B12001_calc_pctMarriedE}%.",
  fieldInfos: [{
    fieldName: "B12001_calc_pctMarriedE",
    },{
    fieldName: 'B12001_calc_numMarriedE',
    format: {
      places: 0,
      digitSeparator: true
      }
  }]
});

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 PopupTemplate.fieldInfos。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。