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


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