JS API version 4.12
I'm generating my own custom popup content, specific to each sublayer in my map image layer. I don't want to hard code dozens of fields in 40+ layers like this:
content: "<tr><td>Utility ID: </td><td>{UtilityID}</td></tr>"
It's going to be more of a custom template with some functions applied to common fields throughout many layers.
When creating a function for the sublayer.popupTemplate's content, the only thing I have available in the graphic's attributes are field names. Can I not easily get the aliases for these features? I don't see a more direct way to do this aside from a traversing through the metadata of the entire map image layer using an esriRequest...get layer field name/alias pairs into an array. Can I avoid the overhead of an esriRequest?
var identifyTask = new IdentifyTask(app.mapImgLyrUtil.url);
var params = new IdentifyParameters();
params.tolerance = 10;
params.layerOption = "visible";
params.width = app.mapView.width;
params.height = app.mapView.height;
const arrExcludeFields = ["OBJECTID", "SHAPE", "SHAPE.STLENGTH()"];
function executeIdentifyTask(event) {
params.geometry = event.mapPoint;
params.mapExtent = app.mapView.extent;
identifyTask
.execute(params)
}
app.mapView.on("click", executeIdentifyTask);
app.mapView.popup = {
dockEnabled: true,
collapseEnabled: false,
overwriteActions: true,
defaultPopupTemplateEnabled: true,
dockOptions: {
position: "bottom-right"
}
};
function createContent(content) {
var graphic = content.graphic;
var displayContent = "";
for (var key in graphic.attributes) {
if (arrExcludeFields.indexOf(key.toUpperCase()) == -1) {
var attrVal = "";
if (graphic.attributes[key]) {
attrVal = graphic.attributes[key];
}
displayContent += key + ": " + attrVal + "<br>";
}
}
return displayContent;
}
app.mapImgLyrUtil.allSublayers.map(function (sublayer) {
sublayer.popupTemplate = new PopupTemplate({
outFields: ["*"],
content: createContent,
title: sublayer.name
});
return sublayer;
});