用于定义如何格式化弹出窗口中使用的标题的模板。您可以通过指定字符串值或返回简单字符串的 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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。