Arcade, FeatureSets, and Popups

4913
22
Jump to solution
09-16-2020 01:34 PM
AndrewSD
Occasional Contributor

Hello,

I have two layers, Organization and Venue in a web map. 

I want to display Venue info in a popup on the Organization layer. I know I can use FeatureSetByName in Arcade, but I don’t have a lot of experience with Arcade.

 

There are also related records so if you click on an Organization point it could have several venues so I would like to display all that relate to the Organization name (how they are related).

In my head I imagine the popup having all the organization info (name, address, other features) that I have created in the customize popup interface. Then I would have an Arcade Expression that gave me the venue name, address, etc. This expression would show any related venue that an Organization has worked at. 

If anyone can give a sample code that would be great. If you need more info I can provide it just not sure what one might need. 

Thank you!

22 Replies
AndrewSD
Occasional Contributor

Hi Xander,

I search your user name and it still is not showing your account for me to add and I have to look outside my organization. Here is a link to the group https://arcg.is/1Pnrzv 

Sorry about that!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi ANDREW BUTTERFIELD ,

Using the link I can see the public group, but it does not appear to have any content and the only member is you. If it is not a problem to have your data shared publicly you can share it in this group, if not, make sure you have the option to look outside your organization switched on, since otherwise you will not be able to find me ("xbakker.spx").

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi ButterfieldLECP ,

Find below the expression that was used to get a list of organizations per venue and sum the number of participants. The "CorrectValue" function was written to translate the text field with the number of participants to a numeric value and accounts for a couple of known situations. This however, is no guarantee that in the future other exceptions will be handled correctly.  

Function CorrectValue(participants) {
    Console(participants);
    if (IsEmpty(participants)) {
        Console("case IsEmpty");
        return 0;
    }
    if (IsNan(participants)) {
        Console("case IsNan");
        return 0;
    }
    participants = Upper(participants);
    Console(participants);
    if (Left(participants, 3) == "N/A") {
        Console("case N/A");
        return 0;
    }
    if (Left(participants, 3) == "MIN") {
        Console("case Min...");
        return 250;
    }
    participants = Replace(participants, "+", "");
    Console(participants);
    participants = Replace(participants, ",", "");
    Console(participants);
    if (Find(" TO ", participants) > -1) {
        Console("case to");
        var arr = Split(participants, " ");
        return (Number(arr[0]) + Number(arr[2]))/2;
    }
    if (Find("ANNUALLY", participants) > -1) {
        Console("case annually");
        var arr = Split(participants, " ");
        return Number(arr[0]);
    }
    if (Find("-", participants) > -1) {
        Console("case -");
        var arr = Split(participants, "-");
        return (Number(arr[0]) + Number(arr[1]))/2;
    }
    return Number(participants);
}

// use venue name to link to organization information
var venname = $feature["org_venue"];

// access the organization featureset
var fsorgs = FeatureSetByName($map,"Organization Info", ["org_name", "org_type", "org_address", "org_number_participants"], False);

// create a SQL query to get the related organizations
var sql = "org_venue = @venname";

// filter organizations on venue name
var orgs = Filter(fsorgs, sql);

// count organizations
var cnt = Count(orgs);

// loop through organizations and create result
var result = "";
var tot_part = 0;
if (cnt > 0) {
    // there are organizations found, loop through orgs
    result = cnt + " organization(s) found:"
    for (var org in orgs) {
        // add org information to the result
        var participants = CorrectValue(org["org_number_participants"]);
        tot_part += participants;
        result += TextFormatting.NewLine + TextFormatting.NewLine + org["org_name"];
        result += TextFormatting.NewLine + org["org_type"];
        result += TextFormatting.NewLine + org["org_address"];
        result += TextFormatting.NewLine + "participants: " + participants;
    }
    result += TextFormatting.NewLine + TextFormatting.NewLine + "Total participants: " + tot_part;
} else {
    // no organizations found
    result = "no organizations found...";
}

return result;
0 Kudos