Return all the attributes(fields) in a feature layer for a PopupTemplate - ArcGis Javascript

718
2
01-03-2022 02:23 AM
MuhammadArsalan27
New Contributor

Is there a way to return all the attributes(fields) in a feature layer for a PopupTemplate, without declaring all of them in the fieldInfos object in Angular?

.ts

const template = {
        title: "{NAME} in {COUNTY}",
        content: ,
        fieldInfos : fieldInfos
      };
      
              
     const layer = new FeatureLayer({
      url: this.featureLayerUrl,
      visible: true,
      popupTemplate : template
      });
      
      var fieldInfos = layer.map(layer.fields, function(field){
         return {
                "fieldName": field.name,
                "label": field.alias,
                "visible": true

    webmap.add(layer);
    

.html

    <!-- Map Div -->

I’m using arcgis-js-api version 4.2.1.
But when I use this example it is working. (But I want to set these fields dynamically.)

const fields = [{
  name: "NAME",
  alias: "Name",
  type: "string"
    }, {
  name: "County",
  alias: "County",
  type: "string"
}, {
  
const config = {
  fields: fields,
  title: "County land"
}; 

 

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor

You can use the createPopupTemplate method on the layer.

view.when(() => {
  const popupTemplate = featureLayer.createPopupTemplate();
  featureLayer.popupTemplate = popupTemplate;
});
0 Kudos
UndralBatsukh
Esri Regular Contributor

You also need to set MapView.popup.defaultPopupTemplateEnabled to true on top of what @ReneRubalcava  pointed out.

 

 

0 Kudos