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


JavaScript ArcGIS PopupTemplate.title用法及代码示例


基本信息

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

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.title函数(或属性)的定义如下:

title String | Function | Promise


用于定义如何格式化弹出窗口中使用的标题的模板。您可以通过指定字符串值或返回简单字符串的 JavaScript 函数或解析为字符串的承诺(自 4.15 起)来格式化标题。

如果使用函数,则定义的内容返回一个字符串值。单击该要素时,该要素将作为参数传递给该函数,并提供对该要素的图形和属性的访问。然后该函数执行并返回一个值以显示在弹出模板的标题中。

例子:

// Within the popup template, placeholders are denoted by `{}`.
// It specifies attributes to display.
// In a service where a field named NAME contains the name of a county, the title
// of the popup when the user clicks a feature representing Los Angeles County will say:
// "Population in Los Angeles County"
popupTemplate.title = "Population in {NAME} County";
// In this example, the popup template's title is set via a function. The function name is
// passed in for its property. Notice that the clicked feature is then passed in to the function.

let popupTemplate = {
  // autocasts as new PopupTemplate()
  title: countyName,
  outFields: ["*"] // Make sure to specify the outFields so that these are available in the function
};

function countyName(feature) {
  // Return the layer title and individual county name
  return feature.graphic.layer.title + " : {NAME}";
}
// Executes a reverse geocode in the popupTemplate title
// and returns the result as a promise. This will display the
// address for the location of the point in the title

const locatorUrl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";

const params = {location: event.mapPoint};

layer.popupTemplate = {
  outFields: ["*"],
  title: function(event) {
    return locator
      .locationToAddress(locatorUrl, params)
      .then(function(response) {
        // This value must be a string
        return response.address;
      });
  }
};

相关用法


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