Select to view content in your preferred language

Configuring pop up based on attribute value

171
5
Jump to solution
Monday
Labels (1)
samshrma998
Occasional Contributor

We are trying to configure pop-up and one of the requirements is to display certain fields based on an query.

example, if field A = 1 then display field X, Y, Z and the value in these fields

else if field A = 2 then display field X and Y only and the value in these fields.

else if field A = 3 then display field Z only and the value in these fields.

We tried to use Arcade expression but it seems to be either adding new rows with variable name in Arcade and then pulling up values from these fields. I don't want to join them or have any new rows from Arcade variable.

Does anyone have configured such pop-ups and will it has potential to be an issue later on once we publish web maps? 

Any directions will be helpful.

0 Kudos
2 Solutions

Accepted Solutions
AlfredBaldenweck
MVP Regular Contributor

Depends on how fancy you want to get, honestly.

It sounds like you probably want the classic "Don't show empty fields" thing. How To: Replace or Omit Empty Attribute Fields from Displaying in Pop-Ups Using a Custom A

But this is a pretty simple way to do it. I remove all the fields I don't care about and then add the ones I do care about back in as an Arcade Element

//This expression uses HTML tags (<b> and <br>) for formatting. 
//If you do not want them, take them out.
//That being said, if you use HTML for one thing, you're stuck with it for everything. 
//You can't use TextFormatting.NewLine with it, 
//    for example, so that's why I'm using <br>.

//Define output text array
var out = []
//Add the fields I always want
var name = $feature.Name
name = `<b>Name</b>: ${name}`
var ftype = $feature.FeatType
ftype = `<b>FeatType</b>: ${ftype}`
Push(out, name)
Push(out, ftype)


// Define the variables for the fields I sometimes want
var x = $feature.FieldX
x = `<b>FieldX</b>: ${x}`
var y = $feature.FieldY
y = `<b>FieldY</b>: ${y}`
var z = $feature.FieldZ
z = `<b>FieldZ</b>: ${z}`

//Add the variables to the output depending on FeatType
if ($feature.FeatType == "1"){
    Push(out, x)
    Push(out, y)
    Push(out, z)
} else if ($feature.FeatType == "2"){
    Push(out, x)
    Push(out, y)
}else {
    Push(out, z)
}
//Add a new line between each field
out = concatenate(out, "<br>")

//Return your output
return { 
  	type : 'text', 
text : out 
}

3 features with the same attributes except for FeatType

AlfredBaldenweck_3-1765207942685.png

AlfredBaldenweck_0-1765207780641.png

AlfredBaldenweck_1-1765207787744.png

AlfredBaldenweck_2-1765207795532.png

View solution in original post

samshrma998
Occasional Contributor

Hi @AlfredBaldenweck , Thanks for suggestions!!

While the expression you provided meets our requirement but it loses the look and feel ArcGIS pro provides. 

We were able to write an expression which worked for us while retaining the original feel of pro map. Here is expression we used and results.


var s = Schema($feature);
var allFields = [];
for (var i = 0; i < Count(s.fields); i++) {
var f = s.fields[i];
Push(allFields, { fieldName: f.name });
}

return When(
// FeatType 1
$feature.FeatType == 1,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldX" },
{ fieldName: "FieldY" },
{ fieldName: "FieldZ" }
]
},

// FeatType 2
$feature.FeatType == 2,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldX" },
{ fieldName: "FieldY" }
]
},

// FeatType 3
$feature.FeatType == 3,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldZ" }
]
},

// Default (only once, and last)
{
type: 'fields',
fieldInfos: allFields
}
);

samshrma998_0-1765271852098.png

samshrma998_1-1765271933657.png

 

 

View solution in original post

0 Kudos
5 Replies
AlfredBaldenweck
MVP Regular Contributor

Depends on how fancy you want to get, honestly.

It sounds like you probably want the classic "Don't show empty fields" thing. How To: Replace or Omit Empty Attribute Fields from Displaying in Pop-Ups Using a Custom A

But this is a pretty simple way to do it. I remove all the fields I don't care about and then add the ones I do care about back in as an Arcade Element

//This expression uses HTML tags (<b> and <br>) for formatting. 
//If you do not want them, take them out.
//That being said, if you use HTML for one thing, you're stuck with it for everything. 
//You can't use TextFormatting.NewLine with it, 
//    for example, so that's why I'm using <br>.

//Define output text array
var out = []
//Add the fields I always want
var name = $feature.Name
name = `<b>Name</b>: ${name}`
var ftype = $feature.FeatType
ftype = `<b>FeatType</b>: ${ftype}`
Push(out, name)
Push(out, ftype)


// Define the variables for the fields I sometimes want
var x = $feature.FieldX
x = `<b>FieldX</b>: ${x}`
var y = $feature.FieldY
y = `<b>FieldY</b>: ${y}`
var z = $feature.FieldZ
z = `<b>FieldZ</b>: ${z}`

//Add the variables to the output depending on FeatType
if ($feature.FeatType == "1"){
    Push(out, x)
    Push(out, y)
    Push(out, z)
} else if ($feature.FeatType == "2"){
    Push(out, x)
    Push(out, y)
}else {
    Push(out, z)
}
//Add a new line between each field
out = concatenate(out, "<br>")

//Return your output
return { 
  	type : 'text', 
text : out 
}

3 features with the same attributes except for FeatType

AlfredBaldenweck_3-1765207942685.png

AlfredBaldenweck_0-1765207780641.png

AlfredBaldenweck_1-1765207787744.png

AlfredBaldenweck_2-1765207795532.png

samshrma998
Occasional Contributor

Hi @AlfredBaldenweck , Thanks for suggestions!!

While the expression you provided meets our requirement but it loses the look and feel ArcGIS pro provides. 

We were able to write an expression which worked for us while retaining the original feel of pro map. Here is expression we used and results.


var s = Schema($feature);
var allFields = [];
for (var i = 0; i < Count(s.fields); i++) {
var f = s.fields[i];
Push(allFields, { fieldName: f.name });
}

return When(
// FeatType 1
$feature.FeatType == 1,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldX" },
{ fieldName: "FieldY" },
{ fieldName: "FieldZ" }
]
},

// FeatType 2
$feature.FeatType == 2,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldX" },
{ fieldName: "FieldY" }
]
},

// FeatType 3
$feature.FeatType == 3,
{
type: 'fields',
fieldInfos: [
{ fieldName: "Name" },
{ fieldName: "FieldZ" }
]
},

// Default (only once, and last)
{
type: 'fields',
fieldInfos: allFields
}
);

samshrma998_0-1765271852098.png

samshrma998_1-1765271933657.png

 

 

0 Kudos
AlfredBaldenweck
MVP Regular Contributor

Oh sweet, glad you got it worked out. 

To be honest, I didn't realize there was an Arcade fields element. That definitely fits it better.

0 Kudos
HollyTorpey_LSA
Frequent Contributor

This can be done with Arcade as shown in the very helpful example posted by @AlfredBaldenweck , but you might want to upvote these ideas as well: 

Conditional visibility for popup elements - Esri Community
Map Viewer: Enable Pop Up Elements with Conditions... - Esri Community

- Holly
AlfredBaldenweck
MVP Regular Contributor

Oh cool, I hadn't seen one of those.