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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。