I am making an online experience and need help with Pop-ups
I have a point layer that contains my company's environmental DNA sample results. There are over 1000 data points, containing information on over 20 species. The point attributes include 46 fields.
When a point is selected in the map, I would like the viewer to only see those fields in the pop-up window that have data for that particular point, instead of having to scroll through 46 fields to find the pertinent DNA results.
For example,
For this point, I would like the following pop-up window to omit all the empty rows (red slashes).
Can someone help me with this appropriate arcade expression?
I prefer the default pop-up look. No fancy headings or color are needed.
If you could provide an example that would be great!
Here are a couple of the fields in my data set.
NumPos_CohoWells
NumPos_BullTWells
Thank you!!
@WFCAdmin -
Try this -
var attributes = Dictionary($feature)["attributes"];
var fieldInfos = [];
var attributeValues = {};
var excludeFields = ["OBJECTID", "EditDate"];
for (var key in attributes) {
var value = attributes[key];
if (!IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
Push(fieldInfos, { fieldName: key });
attributeValues[key] = value;
}
}
return {
type: 'fields',
fieldInfos: fieldInfos,
attributes: attributeValues
};
This also allows a provision to remove certain fields like "ObjectID" and other tracking fields.
An example below -
Thank you so much!!!
Sorry, I am a total novice with Arcade.
For the fields line, I bracket each field with ' ' and separate each field with a comma? Do I close out the fields row with anything special?
Here is an example
The arcade code is fully dynamic. No need to mention what fields to output. The only time you might want to specify the fields is in
var excludeFields = ["OBJECTID", "EditDate"];
These fields will be removed regardless if they are null or not.
Awesome!
I am getting very close! Thank you gis_KIWI4!!
I am struggling with where to imbed the expression.
I notice that it will replicate the fields list filtered perfectly, omiting all the empty fields, but only if I add the expression after the fields list.
If I remove the fields list and only only include the expression then nothing will pop up.
To get this to work, I had to remove the field list, then add a new Arcade content and embed the code there.
Then it will draw the popup table correctly.
R_
Also, if it were possible to have the resulting popups use the display name instead of the field name, that would be amazing!
Here is the code to use display names -
var attributes = Dictionary($feature)["attributes"];
var fieldInfos = [];
var attributeValues = {};
var excludeFields = ["OBJECTID", "EditDate"]; //Use this to exclude any fields, null or not null
var layer_schema = Schema($feature);
var fieldAliases = {};
for (var i = 0; i < Count(layer_schema.fields); i++) {
var field = layer_schema.fields[i];
fieldAliases[field.name] = field.alias;
}
for (var key in attributes) {
var value = attributes[key];
if (!IsEmpty(value) && value != "" && IndexOf(excludeFields, key) == -1) {
var displayName = key; // Default to field name
// Use alias if available
if (HasKey(fieldAliases, key)) {
displayName = fieldAliases[key];
}
Push(fieldInfos, { fieldName: key, label: displayName });
attributeValues[key] = value;
}
}
return {
type: 'fields',
fieldInfos: fieldInfos,
attributes: attributeValues
};
Here you can see the Highlighted fields have had the Display Name (ignore the other fields).
The test layers has Display name and Field Name the same.
Thank you gis_KIWI4!
So here is the issue that I am having.
If I simply have my title and the arcade expression I get only the title in the pop-up.
If I have the title, the field list with all 46 fields checked on, and the arcade expression, I get the full list followed by the abbreviated list. The abbreviated list works perfectly this way always filtering out the empty fields, but it defeats the purpose because the pop-up is still clogged with a bunch of blank data to scroll through.
Any suggestions?
If on the other hand I add a fields list below the arcade expression I get
I am not sure why that is happening.
I only have the title and arcade expression and it works.
Do you have any attribute expressions that might be causing this iss