在ArcGIS Esri中,想要在Popup模板自定义内容中显示图形属性,需要对ArcGIS API进行自定义扩展。具体实现步骤如下:
//在扩展中添加要显示的属性字段
declare module "esri/PopupTemplate" {
interface PopupTemplate {
customFieldInfos: CustomFieldInfo[];
}
interface CustomFieldInfo {
fieldName: string;
label?: string;
format?: {
digitSeparator: boolean;
places: number;
};
}
}
const POPULATION_CUSTOM_FIELD_INFO: CustomFieldInfo = {
fieldName: "POPULATION",
label: "Population",
format: { digitSeparator: true, places: 0 },
};
{{ popup.title }}
${{ $feature.POPULATION }} people live here.
{{ popup.actions }}
//设置Popup模板
const popupTemplate = new PopupTemplate({
title: "{CITY_NAME}, {STATE_NAME}",
customFieldInfos: [POPULATION_CUSTOM_FIELD_INFO],
});
//设置自定义Popup模板
const customPopupTemplate = {
content: this.customPopupTemplate