Return list of values in pop-up with arcade

5650
10
Jump to solution
06-30-2020 01:48 AM
LauraGuthschmidt
New Contributor III

I have a point layer of farms with several features, including a TRUE/FALSE field which tells me if the farm has submitted data that we require. We would like to be able to overlay this with a polygon layer of provinces to see per province how many farms have submitted the data, and then list their names in the polygon pop-up.

Please note that I am very new to arcade.

I have succeeded in the first expression of counting the farms, and am well on my way with the second expression, but I keep running into the following problem: According to multiple blogs/questions https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2018/12/10/overlapping-features-i..., Using FeatureSetBy functions in Arcade to drill-down to other layers and tables, my script looks as it should as far as I can see:

var farms = FeatureSetByName($map,"CoordinatesMasterZonal");
var gis = Intersects(Filter(farms,"GIS_Submitted LIKE 'TRUE'"),$feature);
var gistrue = "";
if (gis > 0) {
    for (var f in gis) {
        gistrue = f.Site_Name + ".  "+ TextFormatting.NewLine + "View their BEIA report here";
    }
} else {
    gistrue = "No farms in this province have submitted GIS data yet"
}  
return gistrue

However, this gives me an output like non of the farms have submitted the data for all provinces, even when I know that there are farms intersecting that have submitted the data.

The following does give me a better output:

var farms = FeatureSetByName($map,"CoordinatesMasterZonal");
var gis = Intersects(Filter(farms,"GIS_Submitted LIKE 'TRUE'"),$feature);
    for (var f in gis) {
        gis = f.Site_Name + ".  "+ TextFormatting.NewLine + "View their BEIA report here";
    }
return gis

But it doesn't loop through the "gis" list and only gives me one value for each province.

What am I missing here to achieve a full list per province?

Thanks!

1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Laura Guthschmidt ,

The main problem of the expression is that for each farm you replace the result in stead of adding it to the result. Look at the expression below where I have changed some variable names for me to understand it better:

var submittedfarms = Filter(FeatureSetByName($map, "CoordinatesMasterZonal"), "GIS_Submitted LIKE 'TRUE'");
var farms = Intersects(submittedfarms, $feature);
var result = "";
if (Count(farms) > 0) {
    for (var farm in farms) {
        result += TextFormatting.NewLine + farm.Site_Name + ".  " + TextFormatting.NewLine + "View their BEIA report here";
    }
} else {
    result = "No farms in this province have submitted GIS data yet"
}  
return result;‍‍‍‍‍‍‍‍‍‍‍

The main difference is on line 6 where I use "+="(to add the farm to the result) in stead of "=" (which replaces at each farm).

I do have a question the text "View their BEIA report here" you add for each farm. If your goal is to create a hyperlink for each farm, this is something you can't do in ArcGIS Online currently. (I would requiere returning HTML and that is not allowed in ArcGIS Online yet, it is possible in ArcGIS Pro).

View solution in original post

10 Replies
XanderBakker
Esri Esteemed Contributor

Hi Laura Guthschmidt ,

The main problem of the expression is that for each farm you replace the result in stead of adding it to the result. Look at the expression below where I have changed some variable names for me to understand it better:

var submittedfarms = Filter(FeatureSetByName($map, "CoordinatesMasterZonal"), "GIS_Submitted LIKE 'TRUE'");
var farms = Intersects(submittedfarms, $feature);
var result = "";
if (Count(farms) > 0) {
    for (var farm in farms) {
        result += TextFormatting.NewLine + farm.Site_Name + ".  " + TextFormatting.NewLine + "View their BEIA report here";
    }
} else {
    result = "No farms in this province have submitted GIS data yet"
}  
return result;‍‍‍‍‍‍‍‍‍‍‍

The main difference is on line 6 where I use "+="(to add the farm to the result) in stead of "=" (which replaces at each farm).

I do have a question the text "View their BEIA report here" you add for each farm. If your goal is to create a hyperlink for each farm, this is something you can't do in ArcGIS Online currently. (I would requiere returning HTML and that is not allowed in ArcGIS Online yet, it is possible in ArcGIS Pro).

LauraGuthschmidt
New Contributor III

Thanks Xander Bakker! Works like a charm.

About the hyperlink; that was indeed what I was going for, and I was already struggling with the hmtl, thanks for addressing that as well.

Would it be possible to create the pop-up with hyperlinks through ArcGIS Pro and then publish them to ArcGIS Online?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Laura Guthschmidt ,

I'm glad it works. You were very close, it was just the missing "+".

Unfortunately, ArcGIS Online does not have the same support for HTML in the pop-up as ArcGIS Pro and when you configure this in Pro and publish the map, I don't think this will work. Last night ArcGIS Online was updated, so maybe somethings changed. Let me validate and I will confirm if there is enhanced support to return html using Arcade in the pop-up.

XanderBakker
Esri Esteemed Contributor

Hi ASC_GIScoordinator ,

I just did a small test to return a html link (a href) from an Arcade expression in the pop-up and it did not work. I am pretty sure that when you configure that in ArcGIS Pro and publish it, it will not work. 

RobertLiveanu
New Contributor II

Hi Xander Bakker - I came across this question and your answer because I wanted to perform a similar action on my own Web Map. I'm only just beginning to familiarize myself with Arcade expressions, and I was wondering if you can help me though? I wanted to modify the code so that, when returning the list of values, all the duplicates are removed; I only want unique values.

My data consists of two layers, a polygon layer (on which I'm doing this expression), and a related point layer that represents trees that are located in each polygon.

I want to return the list of species names (field name Essence, in layer Arbres). As my code is currently written, if two points have the same species name, it will appear in the return list twice. I just want it to return once, removing the duplicate. Is there a way to do this? Thanks!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Robert Liveanu ,

For your specific case I would recommend you to use "GroupBy". This will also allow you to show the count of the trees or other statistics if available (average height, diameter, etc). There is a blog post by Paul Barker that explains the use of GroupBy: What’s New in Arcade 1.8 

I recommend you to read it and if you have any questions, just post them here (or start another thread, which would probably be better, to keep the threads clean)

RobertLiveanu
New Contributor II

Xander Bakker‌ This is pretty much exactly what I needed, my bad for not being able to find the blog post myself and thank you for the link!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Robert Liveanu ,

Don't worry, I'm happy to help. If you run into any problems, you can reach out to me. 

0 Kudos
DanDeegan
New Contributor III

Thank you! 

I was so close but didn't think it would be that simple. 

0 Kudos