Select to view content in your preferred language

Restrict some fields (and not all) to be visible in the layer pop up arcgis pro sdk

645
7
01-02-2024 06:01 AM
CarlosK
New Contributor III

 

Hi,

I am displaying a pop-up after a layer has been added to the active map. Two things need to be configured for the pop-up. One is to create an expression for the pop-up's display field. That is working correctly.

The second thing I want to implement is not to display all the fields of that layer (which is pop-up's default implementation), but to display some of those fields.

This is how I am creating an expression for the display field of the pop-up 

var cimFeatureDefinition = layer.GetDefinition() as CIMBasicFeatureLayer;
var cimDisplayTable = cimFeatureDefinition.FeatureTable;
cimDisplayTable.DisplayExpressionInfo = new CIMExpressionInfo
{
Expression = DisplayExpression,
Title = "Custom"
};
var baseLayer = cimFeatureDefinition as CIMBaseLayer;
layer.SetDefinition(baseLayer);

The above code is working correctly.

But the below code to display not all but some fields of the layer in pop-up is not working. Its actually also affecting the above code to work. 

var fieldsList = new List<CIMPopupFieldDescription>();
foreach (var field in GetPopupFields())
{
var popupFieldDescription = new CIMPopupFieldDescription
{
Alias = field.AliasName,
FieldName = field.Name
};
 
fieldsList.Add(popupFieldDescription);
}
 
var popupInfo = new CIMPopupInfo()
{
FieldDescriptions = fieldsList.ToArray()
};
 
var featureLayer = layer as FeatureLayer;
var cimFeatureDefinition = featureLayer.GetDefinition() as CIMBasicFeatureLayer;
cimFeatureDefinition.PopupInfo = popupInfo;
var baseLayer = cimFeatureDefinition as CIMBaseLayer;
featureLayer.SetDefinition(baseLayer);
 
Can someone help me to implement the correct way to display some of the fields in the pop-up?
 
Tags (1)
0 Kudos
7 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Try to add NumberFormat initialization to new created CIMPopupFielDescription:

var popupFieldDescription = new CIMPopupFieldDescription
{
    Alias = field.AliasName,
    FieldName = field.Name,
    NumberFormat = field.NumberFormat
};
0 Kudos
CarlosK
New Contributor III

@GKmieliauskas what is numberformat? right i have only stated the list of fields with actual name and alias name. this getpopupfields data i am not getting from some layer but its just a static list i have created in which i have only defined actual and alias name. therefore i don’t have numberformat.

0 Kudos
GKmieliauskas
Esri Regular Contributor

NumberFormat is used in ArcGIS Pro SDK community sample

    /// <summary>
    /// Change field name in popup fields
    /// </summary>
    /// <param name="FieldDescriptions">Source CIMPopupFieldDescription array</param>
    /// <returns>New CIMPopupFieldDescription array</returns>
    private CIMPopupFieldDescription[] ChangeFieldNameInPopupFields(CIMPopupFieldDescription[] FieldDescriptions)
    {
      if (FieldDescriptions == null)
        return null;

      List<CIMPopupFieldDescription> fieldsList = new();

      foreach (CIMPopupFieldDescription fieldDescription in FieldDescriptions)
      {
        CIMPopupFieldDescription newDescript = new()
        {
          Alias = fieldDescription.Alias,
          FieldName = GetNewFieldName(fieldDescription.FieldName),
          NumberFormat = fieldDescription.NumberFormat
        };

        fieldsList.Add(newDescript);
      }

      return fieldsList.ToArray();
    }
0 Kudos
CarlosK
New Contributor III

@GKmieliauskas Thats what I am saying I don't have number format. The field description list I have is being created by me manually and I am not taking that info from somewhere. therefore, i don't have numberformat info.in that list when i created i have added only actual name and alias name of the fields.

So basically I will have list of fields that I want to make it visible and that is stored in a list. Now what is the way to configure popups with some of the fields to be visible in pop up. With the above code I am also getting memory issue when creating the pop up info. 

$exception {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} System.AccessViolationException

0 Kudos
GKmieliauskas
Esri Regular Contributor

I would try to take original popup fields like in my copy/pasted sample above and then leave only fields are required. Add to sample code additional parameter with list of field names and inside foreach check if fieldDescription field name exists in your list.

    private CIMPopupFieldDescription[] ChangeFieldNameInPopupFields(CIMPopupFieldDescription[] FieldDescriptions, List<string> fieldNames)
    {
      if (FieldDescriptions == null)
        return null;

      List<CIMPopupFieldDescription> fieldsList = new();

      foreach (CIMPopupFieldDescription fieldDescription in FieldDescriptions)
      {
        if(!fieldNames.Contains(fieldDescription.FieldName) continue;

        CIMPopupFieldDescription newDescript = new()
        {
          Alias = fieldDescription.Alias,
          FieldName = fieldDescription.FieldName,
          NumberFormat = fieldDescription.NumberFormat
        };

        fieldsList.Add(newDescript);
      }

      return fieldsList.ToArray();
    }
0 Kudos
KenBuja
MVP Esteemed Contributor

What does the function GetPopupFields look like? Do you have any logic to determine which fields get added?

0 Kudos
CarlosK
New Contributor III

@KenBuja In getpopfields i am just returning a static list of fields that needs to be displayed in the popup having only actual and alias field names

So basically I will have list of fields that I want to make it visible and that is stored in a list. Now what is the way to configure popups with some of the fields to be visible in pop up. With the above code I am also getting memory issue when creating the pop up info. 

$exception {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} System.AccessViolationException

0 Kudos