用於定義如何格式化彈出窗口中使用的標題的模板。您可以通過指定字符串值或返回簡單字符串的 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; }); } };
基本信息
以下是所在類或對象的基本信息。
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
函數(或屬性)的定義如下:
相關用法
- JavaScript ArcGIS PopupTemplate.fieldInfos用法及代碼示例
- JavaScript ArcGIS PopupTemplate.returnGeometry用法及代碼示例
- JavaScript ArcGIS PopupTemplate.expressionInfos用法及代碼示例
- JavaScript ArcGIS PopupTemplate.actions用法及代碼示例
- JavaScript ArcGIS PopupTemplate.content用法及代碼示例
- JavaScript ArcGIS PopupTemplate.overwriteActions用法及代碼示例
- JavaScript ArcGIS PopupTemplate.outFields用法及代碼示例
- JavaScript ArcGIS PopupTemplate用法及代碼示例
- JavaScript Popup.autoOpenEnabled用法及代碼示例
- JavaScript Popup.location用法及代碼示例
- JavaScript Popup.headingLevel用法及代碼示例
- JavaScript Popup trigger-action事件用法及代碼示例
- JavaScript Popup.features用法及代碼示例
- JavaScript Popup.content用法及代碼示例
- JavaScript Popup.alignment用法及代碼示例
- JavaScript Popup.title用法及代碼示例
- JavaScript Popup.classes用法及代碼示例
- JavaScript Popup.when用法及代碼示例
- JavaScript Popup.visibleElements用法及代碼示例
- JavaScript Popup.actions用法及代碼示例
- JavaScript Popup.open用法及代碼示例
- JavaScript Popup.fetchFeatures用法及代碼示例
- JavaScript Popup.dockEnabled用法及代碼示例
- JavaScript Popup.on用法及代碼示例
- JavaScript Popup.goToOverride用法及代碼示例
注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 PopupTemplate.title。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。